/// <summary> /// Query Attribute /// this assumes a part document with some features is opened. /// and you have run AddAttribute on an edge /// </summary> /// <remarks></remarks> public void QueryAttribute() { // Set a reference to the attribute manager of the active document. AttributeManager oAttribMgr = _InvApplication.ActiveDocument.AttributeManager; // Get the objects with a particular attribute attached. ObjectCollection oObjs = oAttribMgr.FindObjects("BoltEdge", "BoltRadius", 0.5); // Get the objects that have an attribute set of a certain name. oObjs = oAttribMgr.FindObjects("BoltEdge"); // Get the attribute sets with a certain name. AttributeSetsEnumerator oAttribSets = oAttribMgr.FindAttributeSets("BoltEdge"); // Get the attribute sets with a certain name using a wild card. oAttribSets = oAttribMgr.FindAttributeSets("Bolt*"); }
/// <summary> /// assumes a document is opened ''' /// </summary> /// <remarks></remarks> public void Add_Persistent_Transient_Attribute() { Document oDoc = _InvApplication.ActiveDocument; MessageBox.Show("add one attribute set named PersistentAttSet which is persistent" + "\n" + "add one attribute set named TransientAttSet which is transient"); // add persistent attribute AttributeSet oPersistentAttSet = oDoc.AttributeSets.Add("PersistentAttSet"); oPersistentAttSet.Add("PersistentAtt", ValueTypeEnum.kDoubleType, 0.5); //add transient attribute AttributeSet oTransientAttSet = oDoc.AttributeSets.AddTransient("TransientAttSet"); oPersistentAttSet.Add("TransientAtt", ValueTypeEnum.kDoubleType, 1); MessageBox.Show("now try to find the attributes PersistentAttSet in the current document"); // Set a reference to the attribute manager of the active document. AttributeManager oAttribMgr = oDoc.AttributeManager; AttributeSetsEnumerator oAttSets = oAttribMgr.FindAttributeSets("PersistentAttSet"); if (oAttSets.Count > 0) { MessageBox.Show("find Persistent AttSet!"); } else { MessageBox.Show("cannot find Persistent AttSet!"); } MessageBox.Show("now try to find the attributes PersistentAttSet in the current document"); oAttSets = oAttribMgr.FindAttributeSets("TransientAttSet"); if (oAttSets.Count > 0) { MessageBox.Show("find Transient AttSet!"); } else { MessageBox.Show("cannot find Transient AttSet!"); } MessageBox.Show("Please save and close this document, open it again. Then click [OK] of this dialog"); oDoc = _InvApplication.ActiveDocument; oAttribMgr = oDoc.AttributeManager; oAttSets = oAttribMgr.FindAttributeSets("PersistentAttSet"); if (oAttSets.Count > 0) { MessageBox.Show("find Persistent AttSet!"); } else { MessageBox.Show("cannot find Persistent AttSet!"); } oAttSets = oAttribMgr.FindAttributeSets("TransientAttSet"); if (oAttSets.Count > 0) { MessageBox.Show("find Transient AttSet!"); } else { MessageBox.Show("cannot find Transient AttSet!"); } }