iLogic: Export Custom iProperties Of All iPart Instances

By Dutt Thakar

I recently found a question on the Autodesk forums, where a user wanted to export the custom iProperties of all iPart instances to an excel document. I have found two ways to do this this. The first, is to scan the iPart Author table, get the data from it and then copy this to an Excel file. This method is faster because Inventor just needs to capture the data from the Excel table.

Here is the iLogic code for it:

ExcelFile = "C:\Vault\Designs\GoExcel.xlsx"
ExcelSheet = "Sheet2"

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oFactory As iPartFactory = oDef.iPartFactory
Dim i As Long
    For i = 1 To oFactory.TableRows.Count
        ' Get the current row.
        Dim oRow As iPartTableRow
		oRow = oFactory.TableRows.Item(i)
		GoExcel.CellValue(ExcelFile, ExcelSheet, "A" & i) = oRow.MemberName
        ' Iterate through each column in the row.
        Dim j As Long
        For j = 1 To oFactory.TableColumns.Count'oPartList.PartsListColumns.Count
			If oFactory.TableColumns.Item(j).DisplayHeading = "Stock Number"
            ' Get the current cell.
            Dim oCell As iPartTableCell
           	oCell = oRow.Item(j)
			
            GoExcel.CellValue(ExcelFile, ExcelSheet, "B" & i) = oCell.Value
            End If
			
			If oFactory.TableColumns.Item(j).DisplayHeading = "DXF_No"
            ' Get the current cell.
            Dim oCell1 As iPartTableCell
           	oCell1 = oRow.Item(j)
            GoExcel.CellValue(ExcelFile, ExcelSheet, "C" & i) = oCell1.Value
            End If		
        Next	
    Next
GoExcel.Save
GoExcel.Close
GoExcel.ClearCache

The second way of achieving this, is by activating each instance of an iPart and capturing the data from its iProperties, this is easy to understand in terms of code, but it is slower, as Inventor has to go through each instance and activate it.

Here is the iLogic code for it:

ExcelFile = "C:\Vault\Designs\GoExcel.xlsx"
ExcelSheet = "Sheet2"

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

Dim oFactory As iPartFactory = oDef.iPartFactory
Dim i As Integer = 1

	For Each oRow As iPartTableRow In oFactory.TableRows
		oFactory.DefaultRow = oRow
		GoExcel.CellValue(ExcelFile, ExcelSheet, "A" & i) = oRow.MemberName
		GoExcel.CellValue(ExcelFile, ExcelSheet, "B" & i) = iProperties.Value("Project", "Stock Number")
		GoExcel.CellValue(ExcelFile, ExcelSheet, "C" & i) = iProperties.Value("Custom", "DXF_No")
		i = i + 1
	Next
GoExcel.Save
GoExcel.Close
GoExcel.ClearCache

Below is the link of the forum post with a solution

https://forums.autodesk.com/t5/inventor-customization/how-to-export-ipropertis-to-a-excel-sheet-from-all-instances-of/m-p/9955858#M119319

Notes:

This version of the code was briefly tested in Inventor 2021.

As always, please test all iLogic code extensively on non-production files. Do not use any code in a production environment until YOU have thoroughly tested it and have verified that it works as expected. Always back up any data before running any experimental code. You are ultimately responsible for any iLogic code that you run, so make sure you test it thoroughly!

About the Author:

Dutt Thakar has been using Inventor and Vault since 2014 . He works for a company that creates food and dairy processing plants and equipment. Dutt’s career has been spent mostly working as a Mechanical Design Engineer. In his current role, Dutt creates automated models and drawings using Inventor and iLogic (apart from doing regular projects). He also uses VBA and VB.Net to create automations using the Inventor API.

LinkedIn | Blog

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: