private void button5_Click(object sender, EventArgs e) { if (_invApp.Documents.Count == 0) { MessageBox.Show("Need to open an Assembly document"); return; } if (_invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject) { MessageBox.Show("Need to have an Assembly document active"); return; } AssemblyDocument asmDoc = (AssemblyDocument)_invApp.ActiveDocument; // Get the attribute manager for the document AttributeManager attbMan = asmDoc.AttributeManager; // Find the objects with the attributes ObjectCollection objCol = default(ObjectCollection); objCol = attbMan.FindObjects("myPartGroup", "PartGroup1", "Group1"); AttributeSets attbSets = default(AttributeSets); // Delete the attribute from the ComponentOccurrence foreach (object obj in objCol) { ComponentOccurrence compOcc = (ComponentOccurrence)obj; attbSets = compOcc.AttributeSets; attbSets["myPartGroup"].Delete(); // Make the ComponentOccurrence visible compOcc.Visible = true; } }
/// <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*"); }
public void HideOrShowGroup(bool hide) { if (_invApp.Documents.Count == 0) { MessageBox.Show("Need to open an Assembly document"); return; } if (_invApp.ActiveDocument.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject) { MessageBox.Show("Need to have an Assembly document active"); return; } AssemblyDocument asmDoc = default(AssemblyDocument); asmDoc = (AssemblyDocument)_invApp.ActiveDocument; try { AttributeManager attbMan = asmDoc.AttributeManager; ObjectCollection objsCol = default(ObjectCollection); objsCol = attbMan.FindObjects("myPartGroup", "PartGroup1", "Group1"); ComponentOccurrence compOcc = default(ComponentOccurrence); foreach (object obj in objsCol) { compOcc = (ComponentOccurrence)obj; compOcc.Visible = hide; //False } } catch (Exception ex) { MessageBox.Show("Problem hiding component"); } }