Importing points in part file.

Discussion in 'SolidWorks' started by Kav, Jan 24, 2007.

  1. Kav

    Kav Guest

    Hi All,

    I have a .sldcrv file and I want to import it as points in solidworks
    part file and not as spline curve. How can we do that? I am using
    Solidworks 2006 sp 5.0

    Thanks in advance.
    Kav
     
    Kav, Jan 24, 2007
    #1
  2. Kav

    TOP Guest

    This macro was posted back in 1999 by Joe Jones. I tried it at the time
    and it worked. The API has gone through some change though. I can be
    found with Google

    '
    ****************************************************************************
    **
    ' 3DPoints.swb 8/3/99
    '
    ' Edit a 3D sketch and run this macro to automate the creation of 3d
    points.
    ' Point data is in a TAB delimited file "3dpoints.txt"
    ' ex: 1.0 2.1 1
    ' 1.2 2.0 -1
    ' ...
    '
    ' Macro written by Joe Jones
    ' New Hampshire CAD www.nhcad.com
    '
    ' MECHANICAL DESIGN & CUSTOM PROGRAMMING
    '
    ****************************************************************************
    **

    Dim swApp As Object
    Dim modelDoc As Object
    Dim retval As Object
    Dim dataStr As String
    Dim I As Integer
    Dim Coords(1 To 3) As String
    Dim Cnt As Integer
    Dim Units As Integer
    Dim Conversion As Double

    Sub main()
    Set swApp = CreateObject ("SldWorks.Application")
    Set modelDoc = swApp.ActiveDoc

    ' calculate conversion factor for meters --> current units
    Units = modelDoc.LengthUnit
    Select Case Units
    Case 0 ' mm
    Conversion = 1/1000
    Case 1 ' cm
    Conversion = 1/100
    Case 2 ' m
    Conversion = 1
    Case 3 ' in
    Conversion = 1/39.37
    Case 4, 5 ' ft and ft-in
    Conversion = 1/3.28
    End Select

    ' read data file
    Open "3dpoints.txt" for Input as #1

    Do While Not EOF(1)
    Cnt = 1
    Line Input #1, dataStr
    For I = 1 To Len(dataStr)
    If Mid(dataStr,I,1) = Chr(9) Then
    Cnt = Cnt + 1
    Else
    Coords(Cnt) = Coords(Cnt) + Mid(dataStr,I,1)
    End If
    Next I

    set retval = ModelDoc.CreatePoint2 (Val(Coords(1))*Conversion,
    Val(Coords(2))*Conversion, Val(Coords(3))*Conversion)
    Loop
    End Sub

    |===========================================
    | Joe Jones
    |
    | New Hampshire CAD http://www.nhcad.com
    | Lebanon, NH 03766
    |
    | Mechanical Design and Custom Programming
    | SolidWorks Research Partner
    | Online SolidWorks API Tutorial
    |===========================================
     
    TOP, Jan 25, 2007
    #2
  3. Kav

    Kav Guest

    thanks for your help. I will try the marco...
     
    Kav, Jan 25, 2007
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.