Sw_编辑零部件属性
当我们以还原的方式打开装配体时,其零部件也是有加载到程序内存里来的。按理是可以不用打开零部件再编辑零件的属性的。
通过object[] vComponents = swAssy.GetComponents(false);获得零部件集合,
再遍历集合里的零部件,用 swCustPropMgr = swCompModel.Extension.CustomPropertyManager[“”];去对属性进行编辑。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public static void Prop() { AssemblyDoc swAssy = (AssemblyDoc)swApp.ActiveDoc; CustomPropertyManager swCustPropMgr; swAssy.ResolveAllLightWeightComponents(true); object[] vComponents = swAssy.GetComponents(false); foreach (object SingleComponent in vComponents) { Component2 swComponent = (Component2)SingleComponent; ModelDoc2 swCompModel = swComponent.GetModelDoc2(); if (swCompModel == null) { continue; } if (swCompModel.GetType() == (int)swDocumentTypes_e.swDocPART) { swCustPropMgr = swCompModel.Extension.CustomPropertyManager[""]; swCustPropMgr.Add3("Length", (int)swCustomInfoType_e.swCustomInfoYesOrNo, "X", (int)swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd); } else if (swCompModel.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY) { swCustPropMgr = swCompModel.Extension.CustomPropertyManager[""]; swCustPropMgr.Add3("Length", (int)swCustomInfoType_e.swCustomInfoText, "X", (int)swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd); } } }
|