public void RemoveGroup(ref Inventor.AssemblyDocument m_AssemblyDocument, String GroupName, String GroupNumber) { if (m_AssemblyDocument.SelectSet.Count == 0) { MessageBox.Show("Need to select a Part or Sub Assembly"); return; } Inventor.Assets colour = m_AssemblyDocument.Assets; foreach (var item in m_AssemblyDocument.SelectSet) { //Inventor.ComponentOccurrence occurrence = (Inventor.ComponentOccurrence)item; object objUnKnown = item; System.Type invokeType = objUnKnown.GetType(); object tmp = invokeType.InvokeMember("Type", BindingFlags.GetProperty, null, objUnKnown, null); Inventor.ObjectTypeEnum objTypeEum = (Inventor.ObjectTypeEnum)tmp; System.Diagnostics.Debug.WriteLine(objTypeEum.ToString()); if (objTypeEum == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)item; //(Inventor.ComponentOccurrence)objUnKnown; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; System.Diagnostics.Debug.Print(componentOccurrence.Name + "Remove"); //Delete the attributes to the ComponentOccurrence if (m_AttributeSets.NameIsUsed[GroupName]) { m_AttributeSets[GroupName].Delete(); componentOccurrence.AppearanceSourceType = Inventor.AppearanceSourceTypeEnum.kPartAppearance; } } else if (objTypeEum == Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject) { Inventor.RectangularOccurrencePattern RectangularOccurrencePattern = (Inventor.RectangularOccurrencePattern)item; foreach (var Ritem in RectangularOccurrencePattern.OccurrencePatternElements) { Inventor.OccurrencePatternElement occurrencePatternElement = (Inventor.OccurrencePatternElement)Ritem; foreach (var Occitem in occurrencePatternElement.Occurrences) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)Occitem; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; if (m_AttributeSets.NameIsUsed[GroupName]) { m_AttributeSets[GroupName].Delete(); componentOccurrence.AppearanceSourceType = Inventor.AppearanceSourceTypeEnum.kPartAppearance; System.Diagnostics.Debug.Print(componentOccurrence.Name + "Remove Att and color"); } } } } } }
private static void AddEachAttributes(ref Inventor.AssemblyDocument m_AssemblyDocument, bool SelectAllArrays, String GroupName, String GroupNumber) { if (m_AssemblyDocument.SelectSet.Count == 0) { MessageBox.Show("Need to select a Part or Sub Assembly"); return; } Inventor.Assets colour = m_AssemblyDocument.Assets; try { foreach (var item in m_AssemblyDocument.SelectSet) { object objUnKnown = item; System.Type invokeType = objUnKnown.GetType(); object tmp = invokeType.InvokeMember("Type", BindingFlags.GetProperty, null, objUnKnown, null); Inventor.ObjectTypeEnum objTypeEum = (Inventor.ObjectTypeEnum)tmp; System.Diagnostics.Debug.WriteLine(objTypeEum.ToString()); if (objTypeEum == Inventor.ObjectTypeEnum.kComponentOccurrenceObject) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)item;//(Inventor.ComponentOccurrence)objUnKnown; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; System.Diagnostics.Debug.Print(componentOccurrence.Name); // Add the attributes to the ComponentOccurrence Name = "GroupObject"; if (!m_AttributeSets.NameIsUsed[GroupName]) { Inventor.AttributeSet m_AttributeSet = m_AttributeSets.Add(GroupName); Inventor.Attribute m_Attribute = m_AttributeSet.Add(GroupName + "A", Inventor.ValueTypeEnum.kStringType, "G"); Inventor.Asset asset = m_AssemblyDocument.Assets["Red"]; //this to sort out componentOccurrence.Appearance = asset; } } else if (objTypeEum == Inventor.ObjectTypeEnum.kRectangularOccurrencePatternObject && SelectAllArrays) { Inventor.RectangularOccurrencePattern RectangularOccurrencePattern = (Inventor.RectangularOccurrencePattern)item; foreach (var Ritem in RectangularOccurrencePattern.OccurrencePatternElements) { Inventor.OccurrencePatternElement occurrencePatternElement = (Inventor.OccurrencePatternElement)Ritem; foreach (var Occitem in occurrencePatternElement.Occurrences) { Inventor.ComponentOccurrence componentOccurrence = (Inventor.ComponentOccurrence)Occitem; Inventor.AttributeSets m_AttributeSets = componentOccurrence.AttributeSets; if (!m_AttributeSets.NameIsUsed[GroupName]) { Inventor.AttributeSet m_AttributeSet = m_AttributeSets.Add(GroupName); Inventor.Attribute m_Attribute = m_AttributeSet.Add(GroupName + "A", Inventor.ValueTypeEnum.kStringType, "G"); Inventor.Asset asset = m_AssemblyDocument.Assets["Red"]; //this to sort out componentOccurrence.Appearance = asset; } } } } } } catch (Exception ex) { MessageBox.Show("Is the selected item a Component?"); MessageBox.Show(ex.ToString()); return; } }