Occurrences from Document
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey
Hoping someone can help me out here, i cant seem to get this right.... Im using DocumentsEnumerator to get all assembly references. These consist of parts & sub assemblies. There are some instances where we get an assembly with 1 single part inside so in those instances, I need to promote that part out of the found assembly into the top level assembly and then delete the found assembly. ALL of the sub assemblies are only 1 level down so this should be straight forward but im not getting it right tonight... The DocumentsEnumerator has an assembly DocumentType condition as shown below
Dim CurrDoc As AssemblyDocument = _invApp.ActiveDocument
Dim oRefDocs As DocumentsEnumerator = CurrDoc.AllReferencedDocuments
' Iterate through the list of documents.
For Each oRefDoc As Inventor.Document In oRefDocs
Select Case oRefDoc.DocumentType
Case DocumentTypeEnum.kAssemblyDocumentObject
'Call Promote HERE
Dim CurrAssy As AssemblyDocument = oRefDoc 'see below
Promote(CurrAssy)
End Select
Next
The big problem i am finding is oRefDoc. I am trying to assign it as something but i cannot seem to access Document, ComponentDefinition or ComponentOccurrence. I was hoping for oRefDoc.Document.ComponentDefinition
Im using this code from api to promote
Public Sub Promote(ByVal FoundAssembly As AssemblyDocument)
'need to use FoundAssy in the sub
' Get the active assembly document
Dim oDoc As AssemblyDocument = _invApp.ActiveDocument
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
' Get the top level occurrence of an assembly
Dim oSubAssyOcc As ComponentOccurrence = oDef.Occurrences.Item(1)
' Get the 2nd level occurrence under the assembly occurrence
Dim oSubOcc As ComponentOccurrenceProxy = oDef.Occurrences.Item(1).SubOccurrences.Item(1)
Set oSubOcc = oSubAssyOcc.SubOccurrences.Item(1)
Dim oPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
' Get the browser nodes corresponding to the two occurrences
Dim oTargetNode As BrowserNode
Set oTargetNode = oPane.GetBrowserNodeFromObject(oSubAssyOcc)
Dim oSourceNode As BrowserNode
Set oSourceNode = oPane.GetBrowserNodeFromObject(oSubOcc)
' Reorder the nodes to promote the sub-occurrence to the top level
Call oPane.Reorder(oTargetNode, True, oSourceNode)
oSubAssyOcc.Delete
End Sub
i know that oSubASssyOcc needs to be the the found Assembly oRefDoc in the Enumerator but as an occurrence. Seeing as its been found in the enumerator, not a top level loop, its not an occurrence per se because its been found as an object in the enumerator instead. So, i cant get this to work properly. It looks like the Browsernode is expecting an occurrence hence why this isnt working. What am i not seeing?
Thanks
Nacho
Automation & Design Engineer
Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.