Excel

Discussion in 'SolidWorks' started by Jan, Mar 1, 2005.

  1. Jan

    Jan Guest

    Hi all,

    I was wondering if it is possible in solid works to create a part by using
    an excel sheet with coordinates of some 250 points for a certain geometry in
    one plane, and then using a similar file for a complex geometry in a second
    plane, and so on, and then via 'loft' to create the complete part.

    If there are then changes in coordinates that I just have to update these
    Excel file(s) and my part follows the new coordinates.

    Thanks in advance
     
    Jan, Mar 1, 2005
    #1
  2. Jan

    janderson Guest

    I did something like that using points to define a surface. Basically,
    the points were laid out in a grid fashion with varying z-coordinates
    at evenly spaced x and y coordinates. I wrote a macro to read the
    points from a text file, draw a curve across each line of points, and
    then loft a surface over the curve. It worked pretty well - I had ~
    15000 points. The file I had contained one point on each line with the
    x y and z separated by tabs. Here's the macro I had, which you could
    adjust to your needs, or even adapt it to Excel:


    -----------------------------
    Option Explicit

    Dim swApp As Object
    Dim Part As Object
    Dim boolstatus As Boolean
    Dim longstatus As Long, longwarnings As Long
    Dim FeatureData As Object
    Dim Feature As Object
    Dim Component As Object
    Dim fs As Object
    Dim file As Object

    Type Point
    x As Double
    y As Double
    z As Double
    End Type

    Dim oldY As Double
    Dim pt As Point
    Dim SelectionPoints As New Collection
    Dim line As String
    Dim first As Boolean
    Dim i As Long

    Sub main()

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

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set file = fs.OpenTextFile("C:\data.xyz")
    line = file.ReadLine()

    swApp.ActiveDoc.ActiveView.FrameState = 1
    oldY = 0
    first = True

    Do While file.AtEndOfStream <> True And line <> ""
    Dim p1 As Long
    Dim p2 As Long
    p1 = InStr(line, Chr(9))
    pt.x = CDbl(Mid(line, 1, p1 - 1)) / 25000
    p2 = InStr(p1 + 1, line, Chr(9))
    pt.y = CDbl(Mid(line, p1 + 1, p2 - p1 - 1)) / 25000
    pt.z = CDbl(Mid(line, p2 + 1)) / 250

    If first Or pt.y <> oldY Then
    oldY = pt.y
    If Not first Then Part.InsertCurveFileEnd
    Part.InsertCurveFileBegin
    SelectionPoints.Add pt.x
    SelectionPoints.Add pt.y
    SelectionPoints.Add pt.z
    first = False
    End If

    Part.InsertCurveFilePoint pt.x, pt.y, pt.z
    line = file.ReadLine()

    Loop

    Part.InsertCurveFileEnd
    file.Close

    Part.ClearSelection2 True
    For i = 1 To SelectionPoints.Count / 3
    Dim name As String
    name = "Curve" + Trim(Str(i))
    boolstatus = Part.Extension.SelectByID(name, "REFERENCECURVES",
    SelectionPoints(i * 3 - 2), _
    SelectionPoints(i * 3 - 1), SelectionPoints(i * 3), True, 1,
    Nothing)
    Next i

    Part.InsertLoftRefSurface2 False, False, False, 1, 0, 0
    End Sub
     
    janderson, Mar 1, 2005
    #2
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.