Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Get Spline Coordinates? 1

Status
Not open for further replies.

Jaynen

Automotive
Feb 17, 2004
21
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.
 
Replies continue below

Recommended for you

Any ideas? Possible to import it in a different program that could do this? Possible to make a macro?
 
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.
 
Ya tried that. Can only do 100 points at a time.
 
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 [link]http://help.solidworks.com/2012/English/api/sldworksapi/insert_reference_points_example_vb.htm[/url]

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
'-----------------------------------------------------
 
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor