- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
All,
I'm wondering if you can help me. I'm using the code below in an Assembly to export the Mass and COG Position data of all sub-assemblies to an XLSX spreadsheet.
I got the code using this post, which was very helpful as there is precious little info on the internet about this.
I'd like to also export data for parts (not just sub-assemblies). Does anyone know how I could update the code to include that?
I'm using Inventor Professional 2022, Build: 350, Release: 2022.3.
My code is as follows:
Class ThisRule
Public i As Long
Sub Main()
Dim oAssDoc As AssemblyDocument
oAssDoc = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition
oCompDef = oAssDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim strExcelPath As String
strExcelPath = "C:\path to excel file here" 'Please create one excel file before running the code, and define the location of excel here
oExcelApp = GoExcel.Application
GoExcel.CellValue(strExcelPath, "Sheet1", "A1")= "Sub-Assembly Name"
GoExcel.CellValue(strExcelPath, "Sheet1", "B1")= "X"
GoExcel.CellValue(strExcelPath, "Sheet1", "C1")= "Y"
GoExcel.CellValue(strExcelPath, "Sheet1", "D1")= "Z"
i=2
For Each oOcc In oCompDef.Occurrences
Call GetCOG(oOcc,strExcelPath)
Next
GoExcel.Save
GoExcel.Close
End Sub
Function GetCOG(oOcc As ComponentOccurrence, s as String)
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Dim oMassProps As MassProperties
Dim oAsmbDoc As AssemblyDocument
oAsmbDoc = oOcc.Definition.Document
oMassProps = oAsmbDoc.ComponentDefinition.MassProperties
GoExcel.CellValue(s, "Sheet1", "A" & CStr(i))= oOcc.Name
GoExcel.CellValue(s, "Sheet1", "B" & CStr(i))= oMassProps.CenterOfMass.X
GoExcel.CellValue(s, "Sheet1", "C" & CStr(i))= oMassProps.CenterOfMass.Y
GoExcel.CellValue(s, "Sheet1", "D" & CStr(i))= oMassProps.CenterOfMass.Z
i=i+1
End If
If oOcc.SubOccurrences.Count > 0 Then
For Each oOcc In oOcc.SubOccurrences
Call GetCOG(oOcc,s)
Next
End If
End Function
End Class
Many thanks,
Tom
Solved! Go to Solution.