How to export iPropertis to a excel sheet from all instances of a iPart.

How to export iPropertis to a excel sheet from all instances of a iPart.

JonnyPot
Advocate Advocate
979 Views
1 Reply
Message 1 of 2

How to export iPropertis to a excel sheet from all instances of a iPart.

JonnyPot
Advocate
Advocate

Hello every one
I need to export thes iProperties of all iPart instances to a excel sheet:

-code part
-width
-height
-description
-thickness
-height flat model
-width flat model
-perimeter

0 Likes
Accepted solutions (1)
980 Views
1 Reply
Reply (1)
Message 2 of 2

dutt.thakar
Collaborator
Collaborator
Accepted solution

@JonnyPot 

 

I assume that you have all the properties already filled into the Factory iPart Table, and you want to export the values from there to a separate excel sheet. In that case, I have written two codes for you. In the below code, "CLENGTH" and "CQTY" are two custom iProperties and I want to export them in a separate excel file. First, you need to create an excel file and save it somewhere. Make sure you run both the codes in the iPart Factory

 

Try running the below code first: This code iterate through each row, activate it and then iterate to each column try to find the column with the iProperty name, if it has found one it goes to a respective cell in that column that corresponds to the active row and capture the value and export it to excel.

 

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 = "CLENGTH" ' Get the current cell. Dim oCell As iPartTableCell oCell = oRow.Item(j) 'MsgBox(oCell.Value) ' Check that the column isn't the quantity column. GoExcel.CellValue(ExcelFile, ExcelSheet, "B" & i) = oCell.Value End If If oFactory.TableColumns.Item(j).DisplayHeading = "CQTY" ' Get the current cell. Dim oCell1 As iPartTableCell oCell1 = oRow.Item(j) 'MsgBox(oCell1.Value) ' Check that the column isn't the quantity column. GoExcel.CellValue(ExcelFile, ExcelSheet, "C" & i) = oCell1.Value End If Next Next GoExcel.Save GoExcel.Close GoExcel.ClearCache

Another solution is it goes to each row activates its member and then Capture the iProperties from an active member, this will be slow compare to the first one and based on the data you have in ipart.

 

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("Custom", "CLENGTH")
		GoExcel.CellValue(ExcelFile, ExcelSheet, "C" & i) = iProperties.Value("Custom", "CQTY")
		i = i + 1
	Next

GoExcel.Save
GoExcel.Close
GoExcel.ClearCache

 

Try both the codes and see if they fulfill your requirement.

 

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn