Inventor General Discussion

Inventor General Discussion

Reply
New Member
a.sarmukaddam
Posts: 1
Registered: ‎02-20-2011
Message 1 of 16 (2,499 Views)

How to export 3D points to excel?

2499 Views, 15 Replies
02-20-2011 06:35 PM

Please help.

Thanks in advance.

Employee
Hochenauer
Posts: 58
Registered: ‎02-14-2005
Message 2 of 16 (2,462 Views)

Re: How to export 3D points to excel?

02-21-2011 09:31 AM in reply to: a.sarmukaddam

Open the VBA Editor from Inventor/Tools.

 

Inside the Vba editor, select Tools-> References from the menu.

Check the Microsoft Excel Object Library

 

 

 

Sub ExportWorkpoints()
   
    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
    Next
       
    oBook.SaveAs ("c:\test.xls")
   
End Sub

 

 

 

 

 

 

Hope this helps,

Gerald

 



Gerald Hochenauer(gerald.hochenauer@autodesk.com)
Inventor Principal Software Engineer

Manufacturing Group
Autodesk, Inc.

 



Gerald Hochenauer
Senior Principal Engineer, Inventor
Autodesk, Inc.

Active Member
dansharpy
Posts: 9
Registered: ‎03-15-2011
Message 3 of 16 (2,381 Views)

Re: How to export 3D points to excel?

03-15-2011 03:18 AM in reply to: a.sarmukaddam

Hi,

 

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. 

 

Thanks, Dan

Active Member
dansharpy
Posts: 9
Registered: ‎03-15-2011
Message 4 of 16 (2,341 Views)

Re: How to export 3D points to excel?

03-17-2011 08:50 AM in reply to: dansharpy

Could anyone please give me some help with this as i'm completely stuck.

 

Thanks in advance.

Employee
Hochenauer
Posts: 58
Registered: ‎02-14-2005
Message 5 of 16 (2,339 Views)

Re: How to export 3D points to excel?

03-17-2011 08:54 AM in reply to: a.sarmukaddam

Dan,

 

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?

 

Gerald

 



Gerald Hochenauer
Senior Principal Engineer, Inventor
Autodesk, Inc.

Active Member
dansharpy
Posts: 9
Registered: ‎03-15-2011
Message 6 of 16 (2,336 Views)

Re: How to export 3D points to excel?

03-17-2011 08:59 AM in reply to: Hochenauer

Gerald,

 

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"

 

Thanks.

 

 

Active Member
dansharpy
Posts: 9
Registered: ‎03-15-2011
Message 7 of 16 (2,334 Views)

Re: How to export 3D points to excel?

03-17-2011 09:07 AM in reply to: dansharpy

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"

 

Any ideas?

 

Thanks, Dan

Employee
Hochenauer
Posts: 58
Registered: ‎02-14-2005
Message 8 of 16 (2,330 Views)

Re: How to export 3D points to excel?

03-17-2011 09:09 AM in reply to: dansharpy

Are you running this from within a part document?



Gerald Hochenauer
Senior Principal Engineer, Inventor
Autodesk, Inc.

Active Member
dansharpy
Posts: 9
Registered: ‎03-15-2011
Message 9 of 16 (2,327 Views)

Re: How to export 3D points to excel?

03-17-2011 09:13 AM in reply to: Hochenauer

It's an assembly, but only with <20 parts. Will it only work on a part document then?

Employee
Hochenauer
Posts: 58
Registered: ‎02-14-2005
Message 10 of 16 (2,306 Views)

Re: How to export 3D points to excel?

03-17-2011 09:44 AM in reply to: a.sarmukaddam

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.

 

 

Regards,

Gerald Hochenauer

 

 

 

 

 

 



Gerald Hochenauer
Senior Principal Engineer, Inventor
Autodesk, Inc.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.