Exporting x,y,z corrdinates

Dear Experts,

I have a series of points located in a bolt pattern in an assembly.When I click on each point and measure I get the x,y,z coordinates.I would like to be able to export these coordinates to a tableformat for subsequent in another program. Is this possible?

At the moment I am writing down all data which is a nuisance.

Any information appreciated.

Regards
Ed
Design EngineerSolidworksGeneral
Answers 22
MA
MA 2009-01-22 Best Answer
Look into using a Hole Table in a drawing. I don't use them,but I believe they will give you XY coordinates which you canexport to a spreadsheet. Getting the Z coordinate may be notpossible.
SF
SF 2009-01-22
I'd say it would be possible with a macro..

How to do it, I can't help with..
JB
JB 2009-01-22
What kind of points? Are they points in a sketch? Where isthe sketch located? In the bolt itself, in a hole wizard pattern onthe component the bolts are fixing? In a sketch in the assembly?You want X, Y, and Z with respect to the main assembly's coordinatesystem?
SF
SF 2009-01-22
The 'points' I am referring to are in the assembly. By Boltpattern I mean I select the hole cylindrical surface and insert a'point'. From this I select measure to obtain the x,y,zcoordinates.
Yes, the coordinates are with reference to the assembly coordinatesystem.

I could not find a way to export the coordinates of each point to afile that I can manipulate. I need to use these in another program.

Any hints

Ed
JB
JB 2009-01-22
Sorry, I'm still not sure exactly what you're doing. Thereare a lot of ways to "insert a point" in SolidWorks. Are the'points' you are inserting part of a sketch, or are they referencegeometry points (as inserted by Insert->ReferenceGeometry->Point...? If they are part of a sketch, is it a 2-dsketch or a 3-d sketch?
SF
SF 2009-01-22
Sorry for the lack of clarity. Yes, the points are fromreference geometry(Insert->Reference Geometry->Point.

Hope that makes it clear.
Ed
JB
JB 2009-01-22
In that case, this oughtta do it for you. It will output thecoordinates of every reference point in the active document to anExcel file. If you need more decimal places, add zeroes into the"FMAT" constant at the top. The "SF" constant is a scale factor.The 1000 value is to convert meters (the underlying unit that SWactually works in) to millimeters. If you're looking for inches,use 1000/25.4.

Option Explicit

Const FMAT As String = "0.00"
Const SF As Double = 1000

Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim Feature As SldWorks.Feature
Dim myRefPoint As SldWorks.RefPoint
Dim myMathPt As SldWorks.MathPoint
Dim ptData As Variant
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Const FirstRow As Long = 4
Const FirstCol As Long = 2
Dim CurRow As Long
Dim IDCol As Long
Dim Xcol As Long
Dim Ycol As Long
Dim Zcol As Long
Dim PtID As Variant
Dim i As Long

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets("Sheet1")

CurRow = FirstRow
IDCol = FirstCol
Xcol = FirstCol + 1
Ycol = FirstCol + 2
Zcol = FirstCol + 3
xlSheet.Cells(CurRow, IDCol).Value = "'Point ID"
xlSheet.Cells(CurRow, Xcol).Value = "'X Coord"
xlSheet.Cells(CurRow, Ycol).Value = "'Y Coord"
xlSheet.Cells(CurRow, Zcol).Value = "'Z Coord"
CurRow = CurRow + 1

Set Feature = Part.FirstFeature
While Not Feature Is Nothing
If Feature.GetTypeName2 = "RefPoint" Then
Set myRefPoint = Feature.GetSpecificFeature2
Set myMathPt = myRefPoint.GetRefPoint
ptData = myMathPt.ArrayData
xlSheet.Cells(CurRow, IDCol).Value = Feature.Name
xlSheet.Cells(CurRow, Xcol).Value = Format(ptData(0) * SF, FMAT)
xlSheet.Cells(CurRow, Ycol).Value = Format(ptData(1) * SF, FMAT)
xlSheet.Cells(CurRow, Zcol).Value = Format(ptData(2) * SF, FMAT)
CurRow = CurRow + 1
End If
Set Feature = Feature.GetNextFeature
Wend

End Sub
SF
SF 2009-01-23
Dear Josh,

Thank you. That is exactly what I needed. I realise now how usingmacros may be powerful tool if one knows how to exploit them!

Is there a good source I could avail of for one to learn macros inSolidworks?

Cheers
Ed
JB
JB 2009-01-23
If you are already experienced with VB or VBA then LukeMalpass has a book, and the API help is pretty decent once youfigure out how the object structure works. If you can get hold ofthe API help for 2008 it's much easier to read than 2009's. If youdon't have previous programming experience, I would advise gettingstarted writing macros in Excel. There are lots of VBA for Exceltutorials available on the web.
SB
SB 2009-10-14

Josh,

Is it hard to tweak this macro code to look for points in a 3d sketch rather than ref points?  If you can do this that would be very helpful for me.  I would appreciate it very much.  I have tried to get this macro to run, just to see how it works, but have been unsuccessful.  How do I use this code? When I run it in SW it does nothing....there is no error.  I'm a newbie, so what's the most common newbie mistake?

What would really be ideal for me and my company would be to be able to not only export the points, but to export the points in a user defined order.  In my wildest fantasies I we would be able to select a point, hit a button and have it copy the xyz's to a spreadsheet or text file.  Wow, that would be awesome. I don't know what it would take to do that?  Even if we can't pick the order, an export macro will help tremendously.

Thanks for any help or insight that you can give.

Cody

NG
NG 2009-10-14

Cody,

Attached is a macro that I've been using for a while that exports 3Dsketch point to an excel file. Just select the 3Dsketch in your feature tree, run the macro and then format your table anyway you would like. The only thing I have run into with this macro is if any of the points have coincident relationships to other points, you will get double coordinates in your table. Hope that works for you!

SF
SF 2009-10-19

Thanks Nick,

It works great.  I have tried to modify the code to give me 8 decimal places.  If I change anything VB crashes when I try and run it.  Weird.  I can't figure it out.  Do you have any ideas?

If Not sp Is Nothing And Not sheet Is Nothing And Not exApp Is Nothing Then
         sheet.Cells(3 + i, 1).Value = "Pt. " & i + 1
         sheet.Cells(3 + i, 2).Value = Round(sp.X * 1000 / 1, 8)
         sheet.Cells(3 + i, 3).Value = Round(sp.Y * 1000 / 1, 8)
         sheet.Cells(3 + i, 4).Value = Round(sp.Z * 1000 / 1, 8)
         exApp.Columns.AutoFit

        If Not sp Is Nothing And Not sheet Is Nothing And Not exApp Is Nothing Then
         sheet.Cells(3 + i, 1).Value = "Pt. " & i + 1
         sheet.Cells(3 + i, 2).Value = sp.X
         sheet.Cells(3 + i, 3).Value = Round(sp.Y * 1000 / 1, 3)
         sheet.Cells(3 + i, 4).Value = Round(sp.Z * 1000 / 1, 3)
         exApp.Columns.AutoFit

Thanks,

Cody

SW 2009 sp2.1 x64 xp

VB 6.5

NG
NG 2009-10-20
I'm not sure what's happening on your end. I tried changing the 3 to 8 like you did and it worked fine for me. I attached my new macro I saved for 8 decimal places. See if that one works any different for you.
MG
MG 2009-10-20

Hi Josh

Is there any chance you could just post the macro and not the code.

I have tried to copy and paste the code but could not get it to work. Don't know if i did this right.

Thanks

Mark (Solid|Works 2009)

SF
SF 2009-10-20

Thanks Nick,

Although I couldn't get this macro to work on my 64 bit pc, I was able to get it to work on a 32 bit machine.  Weird.

Thanks a lot!

Cody

SF
SF 2009-12-08

Hi Josh, I also tried it but the macro stops at the first 'dim' line with a 'user defined type not defined' error.

My doubt is that "sldworks.sldworks" is not really a 'type'

Do you know of the problem?

Giotto

SF
SF 2010-06-10

This marco works great but is there a way to only export the center point of arc in a sketch?

Thanks,

Chris

PB
PB 2011-03-18

Hi All,

In SolidWorks We have an option for exporting Points which in turn create curves and points as output. Go to Add-ins and switch ON Scan to 3D option. Then click Curve Wizard Feature and under creation method use discrete and under Mesh/Cloud/File select Browse and under files of type choose Text files (.txt, .csv) and choose appropriate file and apply. You can able to see a curve with points generated. Then create a line thru the points and hide the curve. Hope this amy help you. Find the attached image for your reference.

Regards,

Prakash.

SF
SF 2011-11-19

Hi Prakash,

I tried what you mentioned to export points and I exactly followed your instruction in 3D Scan, but it does not save any point in .txt file. If you have tried it, may you give me more details. I created a blank .txt file and browse it when choosing text files since it requires selecting a file as well.

Thanks,

Yasaman

SF
SF 2012-02-20

Can this loop through 3d sketches a export the XYZ data points and the output the sketch name in the excel file.

comment imagecomment image
SF
SF 2012-02-20

done it

Option Explicit

Dim Feature As SldWorks.Feature
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim profileFeature As Sketch
Dim sketchpoints As Variant
Dim sketchPoint As SldWorks.sketchPoint
Dim i As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Const FirstRow As Long = 4
Const namerow As Long = 3
Dim FirstCol As Long
Dim CurRow As Long
Dim IDCol As Long
Dim Xcol As Long
Dim Ycol As Long
Dim Zcol As Long
Dim v As Long


'To run this macro open the model and run macro
'You have been warned this with travese through allsketches

Sub main()

'open and format the excel sheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets("Sheet1")

CurRow = FirstRow
FirstCol = 2
IDCol = FirstCol
Xcol = FirstCol + 1
Ycol = FirstCol + 2
Zcol = FirstCol + 3
xlSheet.Cells(2, IDCol).Value = "All values are in mm"
xlSheet.Cells(CurRow, IDCol).Value = "'Point ID"
xlSheet.Cells(CurRow, Xcol).Value = "'X Coord"
xlSheet.Cells(CurRow, Ycol).Value = "'Y Coord"
xlSheet.Cells(CurRow, Zcol).Value = "'Z Coord"
CurRow = CurRow + 1


Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature


Do While Not swFeat Is Nothing
 
  Set swSubFeat = swFeat.GetFirstSubFeature
 
  ' Process feature
  DoFeature swFeat
 
  Do While Not swSubFeat Is Nothing


    ' Process feature
    DoFeature swSubFeat
   
    Set swSubFeat = swSubFeat.GetNextSubFeature


  Loop
  Set swFeat = swFeat.GetNextFeature
 
Loop


End Sub

Private Sub DoFeature(feat As Feature)
   
    If feat.GetTypeName2 = "3DProfileFeature" Then
        ' Do the business on the feature
        Set profileFeature = feat.GetSpecificFeature2()
       
     
    
     If CurRow > 5 Then
     CurRow = FirstRow
FirstCol = FirstCol + 5
IDCol = FirstCol
Xcol = FirstCol + 1
Ycol = FirstCol + 2
Zcol = FirstCol + 3
xlSheet.Cells(2, IDCol).Value = "All values are in mm"
xlSheet.Cells(CurRow, IDCol).Value = "'Point ID"
xlSheet.Cells(CurRow, Xcol).Value = "'X Coord"
xlSheet.Cells(CurRow, Ycol).Value = "'Y Coord"
xlSheet.Cells(CurRow, Zcol).Value = "'Z Coord"
  ' Get the name
xlSheet.Cells(namerow, IDCol).Value = "Sketch Name: " & feat.Name
CurRow = CurRow + 1
v = 0
Else
   ' Get the namae
xlSheet.Cells((namerow), IDCol).Value = "Sketch Name: " & feat.Name
End If

       
        ' Get the sketch segments
        sketchpoints = profileFeature.GetSketchPoints2
       

        ' Loop all segments
        For i = 0 To UBound(sketchpoints)
           
        Set sketchPoint = sketchpoints(i)
       'Export points in mm to Excel
            xlSheet.Cells(CurRow, IDCol).Value = ".Pt" & v + 1
            xlSheet.Cells(CurRow, Xcol).Value = Format(sketchPoint.X * 1000)
            xlSheet.Cells(CurRow, Ycol).Value = Format(sketchPoint.Y * 1000)
            xlSheet.Cells(CurRow, Zcol).Value = Format(sketchPoint.Z * 1000)
            CurRow = CurRow + 1
v = v + 1
        Next
       
    End If


End Sub

Needs the code cleaning up a bit and some dialog boxes putting in. only works for 3d sketched not sure how to do it for 2d sketches as well which be xz or zy or xy?

can you help?

HK
HK 2012-12-13

Dear Sammy Redshaw

tnx for your code , but above code just export spline points, which are created from, Is there any way to split the spline with the predefined segment length and then  export the points