Community
Hello,
In the following code, the 'For' loop crashes. It throws a type mismatch error. I change the drawing LOD and view representations to the different options, all to no avail. Can someone point me in the right direction?
' Set a reference to the currently active drawing document. Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
' Get the active sheet.
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
' Get the selected view.
Dim oDrawView As Inventor.DrawingView
oDrawView = oDrawDoc.ActiveSheet.DrawingViews.Item(1)
' Get the assembly shown in the view.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = oDrawView.ReferencedDocumentDescriptor.ReferencedDocument
' Get the component defenition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition
' Get all of the leaf occurrences of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmCompDef.Occurrences.AllLeafOccurrences
Dim oOccProxy As ComponentOccurrenceProxy
For Each oOccProxy In oLeafOccs
' Work goes here.
Next
The occurrences return by the AllLeafOccurrences property might not all be proxies. If you have any parts placed in the top assembly those will be standard occurrences, not proxies. Just change the variable type from ComponentOccurrenceProxy to ComponentOccurrence. Since ComponentOccurrenceProxy is derived from ComponentOccurrence it will correctly handle both standard occurrences and proxies.