Export iProperties to Excel

Export iProperties to Excel

Anonymous
Not applicable
3,625 Views
8 Replies
Message 1 of 9

Export iProperties to Excel

Anonymous
Not applicable

Is it possible to export specific iProperties to excel?

I have a full assembly and would like to go part to part and export the specific I properties to on excel file.

3,626 Views
8 Replies
Replies (8)
Message 2 of 9

MechMachineMan
Advisor
Advisor

Something like this would work.

 

Sub Main()
	Dim oNextOpenArrRow As Integer = 0

	Dim oiPropArr(,) As Object
	ReDim Preserve oiPropArr(0 To 1, 0)
	
	For Each oSubDoc In ThisApplication.ActiveDocument.AllReferencedDocuments
		oiPropArr(0, oNextOpenArrRow) = oSubDoc.FullFileName
		oiPropArr(1, oNextOpenArrRow) = oSubDoc.PropertySets("Design Tracking Properties")("Part Number").Value
		oNextOpenArrRow = oNextOpenArrRow + 1
		ReDim Preserve oiPropArr(0 To 1, 0 To oNextOpenArrRow)
	Next
		
	ReDim Preserve oiPropArr(0 To 1, 0 To UBound(oiPropArr,2) - 1)
	Call ExportArrToExcel(oiPropArr)
End Sub

Sub ExportArrToExcel(oArr As Object)
	Dim xlApp As Object
	Dim xlwb As Object
	Dim xlws As Object
    xlApp = CreateObject("Excel.Application")
    xlwb = xlApp.Workbooks.Add()
    xlws = xlwb.Worksheets(1)
    	
    xlApp.Visible = True    
			   
	'For Each arr row...
	For iRow = LBound(oArr,2) To UBound(oArr,2)
		'For each entry
		For iColumn = LBound(oArr,1) To UBound(oArr,1)
			xlws.Cells(iRow+1, iColumn+1) = oArr(iColumn,iRow)
		Next
	Next

    xlws = Nothing
    xlwb = Nothing
    xlApp = Nothing
End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 9

Anonymous
Not applicable

This works great!! The only thing I am having trouble with is that I have never worked with property sets.

I am wanting to grab certain iProperties like Comments, Stock Number, Cut Length (G_L), Item QTY, etc. Is that possible with property sets or should I go a different dirction?

0 Likes
Message 4 of 9

MechMachineMan
Advisor
Advisor

For PARAMETERS, like "G_L", you need to ensure they are marked for export so they get pushed to a custom iProperty.

 

For PROPERTIES, use google and learn how on your own.

 

ex blog you will find from the google machine: 

 

http://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 9

Anonymous
Not applicable

Been mucking around with this trying to get it to run.   I can't define the size of the array in my first "dim" as it complains that it's already been defined when I ReDim, however an empty bracket set should define a flexible array.   There was a comma in MMM's original code, my compiler doesn't like that.

In the sub ExportArrtoExcel, , I don't see why I'm not using the oiPropArr as the argument rather than oArr, which isn't defined.   I get an argument type mismatch in the last line of the main sub (renamed ExportProperties,) which leads me to believe my code hasn't generated an array for export.  Missing the comma!

So far in my journey into customization I've been fed everything I've needed, and I've read a lot of howtos, but I think I'm going back to basics and visiting the library to get more background on coding.

 

 



Sub ExportProperties() Dim oNextOpenArrRow As Integer oNextOpenArrRow = 0 Dim oiPropArr() As Object ReDim Preserve oiPropArr(0 To 2, 0 To 2) For Each oSubDoc In ThisApplication.ActiveDocument.AllReferencedDocuments oiPropArr(0, oNextOpenArrRow) = oSubDoc.FullFileName oiPropArr(1, oNextOpenArrRow) = oSubDoc.PropertySets("Design Tracking Properties")("Part Number").Value oNextOpenArrRow = oNextOpenArrRow + 1 ReDim Preserve oiPropArr(0 To 2, 0 To oNextOpenArrRow) Next ReDim Preserve oiPropArr(0 To 2, 0 To UBound(oiPropArr, 2) - 1) Call ExportArrToExcel(oiPropArr) End Sub Private Sub ShowArray()
'ignore... 'For each "Part Number" in oiPropArr End Sub Sub ExportArrToExcel(oArr As Object) Dim xlApp As Object Dim xlwb As Object Dim xlws As Object xlApp = CreateObject("Excel.Application") xlwb = xlApp.Workbooks.Add() xlws = xlwb.Worksheets(1) xlApp.Visible = True 'For Each arr row... For iRow = LBound(oArr, 2) To UBound(oArr, 2) 'For each entry For iColumn = LBound(oArr, 1) To UBound(oArr, 1) xlws.Cells(iRow + 1, iColumn + 1) = oArr(iColumn, iRow) Next Next xlws = Nothing xlwb = Nothing xlApp = Nothing End Sub

  

0 Likes
Message 6 of 9

MechMachineMan
Advisor
Advisor

Are you trying to use this in VBA?

 

As the code was originally written, it was intended to be plopped into the iLogic environment. Converting to vba will definitely have some things to change as the 2 languages handle arrays a little different (IIRC).


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 9

Anonymous
Not applicable

Huh!  Really no way to easily tell - I haven't worked with arrays in VBA, either, otherwise I may have noticed.  Now that I look again all of the excel object stuff looks wrong.

 

I have this drive to keep things consistent and use VBA for everything, esp. since I want to integrate older stuff into this routine.  I'll figure out how to make these arrays in VBA.  It's not a huge chunk to learn.  Thanks for the help!

0 Likes
Message 8 of 9

MechMachineMan
Advisor
Advisor

Pretty hard to tell with that chunk of code, but 1 of the hints that reminded me was the

 

xlws = Nothing

line as in vba it should be 

 

set xlws = Nothing

 

There is also the use of declaring objects as Object instead of Variant which is a hint.

 

As well as the lack of using "Call" everywhere as vba is picky about the bracket syntax when using parameters to methods. (<--- definitely add this one to the reading material)


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 9 of 9

b_sharanraj
Advocate
Advocate

In Master Assembly BOM add whatever Custom Properties & iProperties of Parts / Sub Assemblies you want to export into Excel.

 

Add a New rule in Master Assembly with the below code

 

ThisBOM.Export("Parts Only", "fileName", kMicrosoftExcelFormat)

 

Excel file will be generated with all the Customer Properties & iProperties in the Same Path of Master Assembly in "fileName".xls 🙂

Regards

B.Sharan Raj

0 Likes