selecting all component occurrences in a folder using API

selecting all component occurrences in a folder using API

Anonymous
Not applicable
1,464 Views
3 Replies
Message 1 of 4

selecting all component occurrences in a folder using API

Anonymous
Not applicable

hey,

i am doing some calculation based on component occurrences that user selects in a plugin, that is written in c#. while in a common assembly document, there is no problem iterating through the slected set, but when user selects a folder from browser, my problem occurs, i would like to get all component occurrences in the selected folder, do you have any idea?

0 Likes
Accepted solutions (2)
1,465 Views
3 Replies
Replies (3)
Message 2 of 4

AlexFielder
Advisor
Advisor

If you can share the code you have so far, that is a big help for everyone here.

0 Likes
Message 3 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@Anonymous,

 

Hoping that below vb.net code is helpful.

 

oFolder = oPane.TopNode.BrowserFolders.Item("Name of folder or selected node")
oFolderNodes = oFolder.BrowserNode.BrowserNodes
Dim oComp as ComponentOccurrence
For Each oNode As BrowserNode In oFolderNodes
	oComp = oNode.NativeObject
	 
Next

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 4 of 4

Anonymous
Not applicable
Accepted solution

thank you, dear Chandra, 

i also did this a little bit different, as in c# it looks like this:

 

void PackSelectedComponents(BrowserNode Node, Globals.Package thispack)
{
foreach( object nodeobj in Node.BrowserNodes)
{
ObjectTypeEnum objectType = GetObjectType(nodeobj);
if (objectType == ObjectTypeEnum.kBrowserFolderObject)
                {
                    BrowserFolder Folder = default(BrowserFolder);
                    object  obj = nodeobj;
                    Folder = (BrowserFolder)obj;
                    BrowserNode subNode = Folder.BrowserNode;
                    PackSelectedComponents(subNode, thispack);
                }
else if (objectType == ObjectTypeEnum.kComponentOccurrenceObject
                    || objectType == ObjectTypeEnum.kComponentOccurrenceProxyObject)
                {
                    ComponentOccurrence compOcc = default(ComponentOccurrence);
                    compOcc = (ComponentOccurrence)nodeobj;
                    DoAttribute.WritePackagingData(compOcc, thispack);
                    if (compOcc.DefinitionDocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
                        PackSelectedComponents((ComponentOccurrences)compOcc.SubOccurrences, thispack);
                }
}



}
0 Likes