Open the VBA Editor from Inventor/Tools.
Inside the Vba editor, select Tools-> References from the menu.
Check the Microsoft Excel Object Library
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition
Set oDef = oDoc.ComponentDefinition
Dim oWorkpoints As WorkPoints
Dim oWP As WorkPoint
Dim oP As Point
'get all workpoints in this part
Set oWorkpoints = oDef.WorkPoints
'create a new excel workbook
Dim oBook As Excel.Workbook
Set oBook = Excel.Workbooks.Add()
Dim oSheet As Excel.WorkSheet
Set oSheet = oBook.ActiveSheet
Dim nRow As Integer
nRow = 1
'write the coordinates into separate columns, one workpoint each row
For Each oWP In oWorkpoints
Set oP = oWP.Point
oSheet.Cells(nRow, 1) = oP.X
oSheet.Cells(nRow, 2) = oP.Y
oSheet.Cells(nRow, 3) = oP.Z
nRow = nRow + 1
Hope this helps,
Inventor Principal Software Engineer
Id like to know more about this if possible? Could you give more detailed instructions please? Ive opened the VBA editor, checked excel object library but when i enter the text in a new module and try to run it, it comes up with an error.
I need some info on the error you are seeing in order to be able to help. What line of the code? What's the error message?
It says "Compile error: User-defined type not defined"
If i click "ok" it then highlights the line of code "oBook As Excel.Workbook"
Does that help?
Im creating the module under "Document Project"
Sorry, that was the wrong one actually! Id forgotten to check excel object library.
With that checked it now reads "run-time error '13': Type mismatch" If i click debug, it highlights the line "Set oDoc = ThisApplication.ActiveDocument"
The example I wrote is for a single part document - it is a generic example that takes workpoints within this part and exports their locations.
Dim oDoc As PartDocument
as opposed to
Dim oDoc As AssemblyDocument
In order to extend the sample to assemblies, you'd have to iterate over the assembly component Definition structure(Assemblies can contain sub assemblies,....) .
You'd need to know about Component Occurrences and transformations in order to get all the points to show up at the assembled locations.
Unfortunately I can't spare the time to write it - I need to wrap up things before leaving on a 3 week business trip. Maybe somebody else can pick it up or you get some training. It is quite a good example to learn how programming Inventor with VBA works.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register