×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to Get Spline Coordinates?

How to Get Spline Coordinates?

How to Get Spline Coordinates?

(OP)
I have multiple complex splines that I have joined together using a fit spline. I need to get the xyz coordinates of that fit spline in 0.5 meter increments to a text file. The fit spline is 2000 meters long. I tried using reference points which I converted into a 3d sketch and exported using a macro but I can only place 100 reference points at a time which is very time consuming. Anyone have any ideas? Thanks.

RE: How to Get Spline Coordinates?

(OP)
Any ideas? Possible to import it in a different program that could do this? Possible to make a macro?

RE: How to Get Spline Coordinates?

(OP)
Thanks for the response. Unfortunately thats not quite what I was looking for. The problem I have is putting the points in. My spline is 2000 meters long and for me to put a point every 0.5 meters is going to take a long time. I have no problem running the macro and exporting the points. Just need to get the points on the spline in 0.5 meter increments for 2000 meters.

RE: How to Get Spline Coordinates?

A quick Google search turned up this.
Link

I have not done this for several years.

Chris, CSWA
SolidWorks 14
ctopher's home
SolidWorks Legion

RE: How to Get Spline Coordinates?

(OP)
Ya tried that. Can only do 100 points at a time.

RE: How to Get Spline Coordinates?

Create a new macro and paste in the following code. Update nPoints and increment to suite. Create a reference point some distance along your curve. Select that reference point and run the macro. It should move the point along the line and create a text file in the same folder and with the same name as the model with an extra .txt on the end (Part1.SLDPRT.txt for example), with the XYZ coordinates. With the part I tested, the increment and locations were in meters.

There is no error handling, and it should be possible to extend the macro to create the point and delete it afterward. See http://help.solidworks.com/2012/English/api/sldworksapi/insert_reference_points_example_vb.htm

Eric

CODE

'------------------------------------------------
'
' Preconditions:
'           (1) Part, or assembly is open.
'           (2) Reference point defined by distance feature is selected.
'
' Postconditions:
'           swModel.GetPathName.txt is created with xyz locations of point.
'           Reference point likely moved.
'-----------------------------------------------

Option Explicit

Sub main()
    Dim swApp                       As SldWorks.SldWorks
    Dim swModel                     As SldWorks.ModelDoc2
    Dim swSelMgr                    As SldWorks.SelectionMgr
    Dim swFeat                      As SldWorks.Feature
    Dim swRefPt                     As SldWorks.RefPoint
    Dim swRefPtData                 As SldWorks.RefPointFeatureData
    Dim swMathPt                    As SldWorks.MathPoint
    Dim i                           As Integer
    Dim fileSystem                  As Variant
    Dim textFile                    As Variant
    Dim nPoints                     As Integer
    Dim stepSize                    As Double
    
    nPoints = 10
    stepSize = 0.0254
    
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swFeat = swSelMgr.GetSelectedObject5(1)
    Set swRefPt = swFeat.GetSpecificFeature2
    Set swRefPtData = swFeat.GetDefinition
    Set swMathPt = swRefPt.GetRefPoint
    
    Set fileSystem = CreateObject("Scripting.FileSystemObject")
    Set textFile = fileSystem.CreateTextFile(swModel.GetPathName & ".txt", True)
    
    For i = 0 To nPoints - 1
        swRefPtData.Distance = stepSize * i
        swRefPt.ModifyDefinition swRefPtData, swModel, Nothing
        Set swMathPt = swRefPt.GetRefPoint
        
        textFile.writeline Format(swMathPt.ArrayData(0)) & "," & _
            Format(swMathPt.ArrayData(1)) & "," & _
            Format(swMathPt.ArrayData(2))
    Next
    textFile.Close
End Sub
'----------------------------------------------------- 

RE: How to Get Spline Coordinates?

(OP)
IT WORKED! And it worked perfectly! Thank you so much you have no idea how much time you have saved me. If you need anything please let me know. Thanks again!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources