By Wayne Brill
This VB.NET example shows how to recursively access parameters from an assembly document containing multiple levels of parts and sub-assemblies.
Private Sub AccessParametersFromAssembly() Dim oApp As Inventor.Application = System.Runtime.InteropServices.Marshal. GetActiveObject("Inventor.Application") Dim oDoc As Document oDoc = oApp.ActiveDocument If (oDoc.DocumentType = _ DocumentTypeEnum.kAssemblyDocumentObject) Then Debug.Print(oDoc.DisplayName) Dim oDef As AssemblyComponentDefinition oDef = oDoc.ComponentDefinition Call PrintParameters(oDef.Occurrences) Else MsgBox("Need an assembly document.") End If End Sub Private Sub PrintParameters _ (oOccs As ComponentOccurrences) Dim oOcc As ComponentOccurrence For Each oOcc In oOccs If (oOcc.DefinitionDocumentType = _ DocumentTypeEnum.kPartDocumentObject) Then Dim oPartDef As _ PartComponentDefinition oPartDef = oOcc.Definition Dim i As Integer For i = 1 To oPartDef.Parameters.Count Debug.Print(oOcc.Name & "," _ & oPartDef.Parameters.Item(i).Name _ & "=" & oPartDef.Parameters.Item(i).Value) Next i ElseIf (oOcc.DefinitionDocumentType = _ DocumentTypeEnum.kAssemblyDocumentObject) Then Debug.Print(UCase(oOcc.Name)) Call PrintParameters _ (oOcc.SubOccurrences) End If Next End Sub

Leave a Reply