作者: littleboy 2025-03-04 16:19:07

SW_编辑属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static void CopyCustProps()
{
object vPropNames = null;
object vPropTypes = null;
object vPropValues = null;

swCustPropMgr.GetAll(ref vPropNames, ref vPropTypes, ref vPropValues);//获得零件的属性


string[] vCompCustPropNames = (string[])vPropNames;
int[] vCompCustPropTypes = (int[])vPropTypes;
string[] vCompCustPropValues = (string[])vPropValues;

for (int i = 0; i < vCompCustPropNames.Length; i++)
{
swCustPropMgr.Delete2(vCompCustPropNames[i]);
}
for (int i = 0; i < vCompCustPropNames.Length; i++)
{
swCustPropMgr.Add2(vCompCustPropNames[i], vCompCustPropTypes[i], vCompCustPropValues[i]);
}
}

获得属性对象

swCustPropMgr

1
2
ModelDoc2 swModel= swApp.ActiveDoc;
CustomPropertyManager swCustPropMgr = swModel.Extension.CustomPropertyManager[""];

获得属性

1
2
3
4
5
6
7
8
9
object vPropNames = null;
object vPropTypes = null;
object vPropValues = null;

swCustPropMgr.GetAll(ref vPropNames, ref vPropTypes, ref vPropValues);//获得零件的属性

string[] vCompCustPropNames = (string[])vPropNames;
int[] vCompCustPropTypes = (int[])vPropTypes;
string[] vCompCustPropValues = (string[])vPropValues;

删除属性

1
swCustPropMgr.Delete2(vCompCustPropNames[i]);

添加属性

1
swCustPropMgr.Add2(vCompCustPropNames[i], vCompCustPropTypes[i], vCompCustPropValues[i]);