Message 1 of 3
My First Plug-in - get group names from assembly file
Not applicable
01-24-2016
10:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All
I have followed the My First Plug-in Training http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=17332618
This plugin allows the user to group components in an assembly file and toggle the visibility on and off.
Currently it only allows for one group so I would like to expand on this by creating multiple groups.
I would like the group names to be variable which is fine but my problem is recalling the group names from the selected assembly document.
Heres the code that adds the item(s) to the group and underlined is where i have modified it.
string selectedGroup;
public void AddOrRemoveFromGroup(bool add) { AssemblyDocument asmDoc = default(AssemblyDocument); asmDoc = (AssemblyDocument)_invApp.ActiveDocument; if (asmDoc.SelectSet.Count == 0) { System.Windows.MessageBox.Show("Need to select a Part or Sub Assembly"); return; } SelectSet selSet = default(SelectSet); selSet = asmDoc.SelectSet; try { ComponentOccurrence compOcc = default(ComponentOccurrence); object obj = null; foreach (object obj_loopVariable in selSet) { obj = obj_loopVariable; compOcc = (ComponentOccurrence)obj; System.Diagnostics.Debug.Print(compOcc.Name); AttributeSets attbSets = compOcc.AttributeSets; if (add) { // Add the attributes to the ComponentOccurrence if (!attbSets.NameIsUsed["myPartGroup"]) { AttributeSet attbSet = attbSets.Add("myPartGroup"); Inventor.Attribute attb = attbSet.Add(selectedGroup, ValueTypeEnum.kStringType, "Group1"); } } else { // Delete the attributes to the ComponentOccurrence if (attbSets.NameIsUsed["myPartGroup"]) { attbSets["myPartGroup"].Delete(); } } } } catch (Exception ex) { System.Windows.MessageBox.Show("Is the selected item a Component?"); System.Windows.MessageBox.Show(ex.ToString()); return; } }
What i would like is to loop through the active assembly document and get the group names already existing.
Any help would be greatfully received.
Thanks
Chris.