Inventor General

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

How to export 3D points to excel?

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

Please help.

Thanks in advance.

Employee
Hochenauer
Posts: 52
Registered: ‎02-14-2005
Message 2 of 16 (2,175 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
Inventor Software Development
Autodesk, Inc.

Active Member
dansharpy
Posts: 9
Registered: ‎03-15-2011
Message 3 of 16 (2,094 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,054 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: 52
Registered: ‎02-14-2005
Message 5 of 16 (2,052 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
Inventor Software Development
Autodesk, Inc.

Active Member
dansharpy
Posts: 9
Registered: ‎03-15-2011
Message 6 of 16 (2,049 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,047 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: 52
Registered: ‎02-14-2005
Message 8 of 16 (2,043 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
Inventor Software Development
Autodesk, Inc.

Active Member
dansharpy
Posts: 9
Registered: ‎03-15-2011
Message 9 of 16 (2,040 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: 52
Registered: ‎02-14-2005
Message 10 of 16 (2,019 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
Inventor Software Development
Autodesk, Inc.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube