EXPORTING XYZ POINTS COORDINATES INTO EXCEL

Discussion in 'SolidWorks' started by Ariel, May 1, 2006.

  1. Ariel

    Ariel Guest

    I have this macro that for some reason is not working properly. It
    should open a excel file and extract xyz points coordibnates from sw
    parts. Could you please run it and tell me what is wrong?
    Thank you!!!!!
    Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim doc As SldWorks.ModelDoc2
    Dim part As SldWorks.PartDoc
    Dim sm As SldWorks.SelectionMgr
    Dim feat As SldWorks.Feature
    Dim sketch As SldWorks.sketch
    Dim v As Variant
    Dim i As Long
    Dim sseg As SldWorks.SketchSegment
    Dim sline As SldWorks.SketchLine
    Dim sp As SldWorks.SketchPoint
    Dim ep As SldWorks.SketchPoint
    Dim s As String
    Dim exApp As Excel.Application
    Dim sheet As Excel.Worksheet



    'Set exApp = New Excel.Application
    Set exApp = CreateObject("Excel.Application")
    If Not exApp Is Nothing Then
    exApp.Visible = True
    If Not exApp Is Nothing Then
    exApp.Workbooks.Add
    Set sheet = exApp.ActiveSheet
    If Not sheet Is Nothing Then
    sheet.Cells(1, 2).Value = "X"
    sheet.Cells(1, 3).Value = "Y"
    sheet.Cells(1, 4).Value = "Z"
    End If
    End If
    End If


    Set swApp = GetObject(, "sldworks.application")
    If Not swApp Is Nothing Then
    Set doc = swApp.ActiveDoc
    If Not doc Is Nothing Then
    If doc.GetType = swDocPART Then
    Set part = doc
    Set sm = doc.SelectionManager
    If Not part Is Nothing And Not sm Is Nothing Then
    If sm.GetSelectedObjectType2(1) = swSelSKETCHES Then
    Set feat = sm.GetSelectedObject4(1)
    Set sketch = feat.GetSpecificFeature
    If Not sketch Is Nothing Then
    v = sketch.GetSketchPoints
    For i = LBound(v) To UBound(v)
    Set sp = v(i)
    If Not sp Is Nothing And Not sheet Is Nothing And Not exApp Is
    Nothing Then
    'sheet.Cells(2 + i, 1).Value = "Normal Vector " & i + 1
    sheet.Cells(2 + i, 2).Value = (sp.X * 1000) / 25.4
    sheet.Cells(2 + i, 3).Value = (sp.Y * 1000) / 25.4
    sheet.Cells(2 + i, 4).Value = (sp.Z * 1000) / 25.4
    exApp.Columns.AutoFit
    End If
    Next i
    End If
    End If
    End If
    End If
    End If
    End If
    End Sub
     
    Ariel, May 1, 2006
    #1
  2. Ariel

    Mr. Who Guest

    Why don't you just write out solidworks data as a comma delimited text
    file and import it into excel? Seems like it would be a lot easier.
    Multiapp programming can be flaky.
     
    Mr. Who, May 1, 2006
    #2
  3. Ariel

    Ariel Guest

    How do you export txt files from SW? I can export IGES and open it in
    Rhino.... was not able to create txt in SW though, thank you for the
    advice!!

    Regarding the xyz-macro, it is working!
     
    Ariel, May 2, 2006
    #3
  4. Ariel

    Mr. Who Guest

    Good news that it is working. You can use the filesystemobject to
    create a text file and then write out to it with simple file.writeln
    calls. Do a search for filesystemobject and microsoft has some good
    examples. But I guess it is unnecessary now that you have your macro
    working. Feels good to make something work =D.
     
    Mr. Who, May 2, 2006
    #4
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.