Reorder Occurrences in Assembly

Reorder Occurrences in Assembly

Anonymous
Not applicable
1,738 Views
4 Replies
Message 1 of 5

Reorder Occurrences in Assembly

Anonymous
Not applicable

I have to reorder the occurrences in the assembly. I have tried using the browserpane reorder method, it only changes the order in the model tree. But when I try to get the component occurrences from assembly document using "ComponentDefinition.Occurrences" api, I get the old order only. Can someone suggest me something which I can do? Because If I am not getting the occurrences in the order I set in browserpane, then it will block my functionality.

 

Example: We have structure like this:

Assembly
   ->Part1

   ->Part2

   ->Part3

 

Now I want to move Part3 above Part2.

 

So, using the reorder functionality of browserpane, i am able to achieve the new order in model browser pane.

Assembly

   ->Part1

   ->Part3

   ->Part2

But when I try to get Occurrences from Component definition of assembly, I get structure like this only:

Assembly

   ->Part1

   ->Part2

   ->Part3

0 Likes
Accepted solutions (1)
1,739 Views
4 Replies
Replies (4)
Message 2 of 5

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

The internal order of the occurrences is related to the moment in which the components were inserted in the assembly. To change this internal order I suppose you should eliminate and reinsert components, something that I would not advise.
Maybe you should change the approach to how to access the occurrences. The first thing that occurs to me is to access through the browser. Then I show you a code
Accessing the occurrences from the order in the browser, is a simplified code for your example, if you had for example a circular or linear pattern, this object would be skipped, so there is the instruction "on error resume next".

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oPane As BrowserPane
oPane = oDoc.BrowserPanes.ActivePane

Dim oNode As BrowserNode
oNode = oPane.TopNode

Dim j As Integer = 0

For i As Integer = 1 To oNode.BrowserNodes.Count
	If InStr(oNode.BrowserNodes.Item(i).FullPath, "End of Features") <> 0 Then j =i +1
Next

Dim oCC As ComponentOccurrence
Dim doc As Document

For i As Integer = j To oNode.BrowserNodes.Count
		On Error Resume Next
	oCC = oNode.BrowserNodes.Item(i).NativeObject
	doc = oCC.Definition.Document
	MessageBox.Show(doc.DisplayName)
Next

 I hope this can be useful for you to analyze a new approach. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 5

Anonymous
Not applicable

This approach will help but I will have to change the approach to get occurrences everywhere. And that will be troublesome for me.

 

When we manually drag the browsernode in the tree and save the document and the again reopen it, the order in "ComponentDefinition.Occurrences" also gets changed. So, there must be some internal operation that can change the order in occurrences too. Do you know about it?

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

How will I access Patterns if I follow the approach you suggested?

0 Likes
Message 5 of 5

or.mokhtar
Contributor
Contributor

hello my friend, 

I wonder if you found a solution for your problem. if you did can  you please tell me how you solved it as I also encountered your same problem and yet to find a solution 

0 Likes