I'm trying to figure out how to "Demote" a selection set of occurrances within an Inventor assembly file to another assembly. The code I have demotes the first selection, but then fails to move past the first "oPane.Reorder(oTargetNode, False, oSourceNode)" for the next selection. I put the selection set into a List(of ComponentOccurrence) and have defined the sub-assembly Occurrence as "oSubAssyOcc" What am I missing? Is there a specific way to reorder a selection set?
' Get the model browser Dim oPane As BrowserPane = inventorDoc.BrowserPanes.Item("Model") For Each co As ComponentOccurrence In listOfComponentOccurrences ' Get the browser node that corresponds to the new sub-assembly occurrence Dim oSubAssyNode As BrowserNode = oPane.GetBrowserNodeFromObject(oSubAssyOcc) 'Get the last visible child node under the sub-assembly occurrence Dim oTargetNode As BrowserNode Dim i As Long For i = oSubAssyNode.BrowserNodes.Count To 1 Step -1 If oSubAssyNode.BrowserNodes.Item(i).Visible Then oTargetNode = oSubAssyNode.BrowserNodes.Item(i) Exit For End If Next 'Get the browser node that corresponds to the occurrence to be demoted Dim oSourceNode As BrowserNode = oPane.GetBrowserNodeFromObject(co) 'Demote the occurrence Call oPane.Reorder(oTargetNode, False, oSourceNode) Next
Solved! Go to Solution.
Hi Gary,
You would need to provide the full code sample, so it makes more sense and it can be tested in the same conditions than you do.
Keep in mind that transacting operations clear the selection set, might this be the issue in your case? Hard to tell obviously based on that code fragment...
Regards,
Philippe.
Philippe,
I did some more playing around and the code above actually works as intended if none of the occurrences have any constraints. I deleted all the constrains from the test occurrences and it worked. I do want to keep the constraints however as it would be a pain to reassemble the parts inside the new sub-assy. Is there something missing in the API that allows constraints to move with an occurrence during a browser pane reoder? Or can I turn something off and then back on again after the reoder?
Thanks for your help.
I don't think this is actually doable: constraints have to be created between entities in a specific assembly context. If you demote an occurrence from one assembly level to a sub-assembly, you most likely have to recreate the constraints. Did you experiment from the UI? If it's not doable from the UI, it will be the same behavior from the API.
Regards,
Philippe.
No, the API does not behave the same way as the UI. That leads me to believe I am missing something. I can drag and drop fully constrained occurrences (more than one occurrence at a time) into a sub-assy with the UI. I cannot do that with MORE THAN ONE occurrence in the API with my code. The API works with the first Occurrence but then fails with the rest UNLESS they do not have any constraints. Then it works. This to me seems like a limitation of the API or I am missing something simple.
FYI, I'm using Inventor Pro 2013, but will be upgrading to 2015 Pro shortly. I will try this in 2015 and see if it works.
I believe I have solved this with a different approach. Here is the code that works.. Using the CommandManager and assigning the new assembly filename and path in a postPrivateEvent.... I fount the example here http://modthemachine.typepad.com/my_weblog/2009/03/running-commands-using-the-api.html
Dim oCommandMgr As CommandManager = _invApp.CommandManager oCommandMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, "C:\Temp\NewAssembly.iam") Dim oControlDef As ControlDefinition = oCommandMgr.ControlDefinitions.Item("AssemblyDemoteCmd") Call oControlDef.Execute()