EXPORTING XYZ

Discussion in 'SolidWorks' started by Ben, Jul 16, 2006.

  1. Ben

    Ben Guest

    Ok I have found this macro on the group

    I cannot get it to work? What gives? How should it be exectuted? I run
    it in a part that only has a point cloud in a 3d skectch and nouthing
    happens... I could save myself hours and hours with this. does anyone
    have a macro that can take a point cloud in SW and export it to commman
    delimited or something of that nature?

    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

    Ben
     
    Ben, Jul 16, 2006
    #1
  2. Ben

    CS Guest

    Ben why don't we look at the code you are using. First off you have to
    reference the excel type libraries for this macro to work. Then if you
    step through your code you could point out exactly which line is
    erroring.

    Regards,
     
    CS, Jul 17, 2006
    #2
  3. Ben

    Ben Guest

    CS

    Hate to say this but I am a hack at best when coding, so I pretty much
    can say I have no idea how to ref the excel librarys little alone
    properly step through the code...

    Guess it sucks to be me and I will have to manually get the 300 points,
    gong to be a late late boring night...Gahhhh!!!!! Maybe this will be
    punishment enough to convince me to take some VBA courses and get my
    arse in gear.....

    Ben
     
    Ben, Jul 18, 2006
    #3
  4. Ben

    CS Guest

    I'm sorry it is probably too late, but to Reference you (In the VB
    Editor) Tools>References
    Brows down to Microsoft Excel X.X and put a check mark next to it.
    Your current references should be listed at the top of the list. Then
    to step through code you can use F8 each press of F8 will increment the
    code through 1 line.
     
    CS, Jul 21, 2006
    #4
  5. Ben

    Ben Guest

    Well the job is done... I have bought some self study VBA and CS you
    are right that was the problem and the code works now. So even though
    it is late I have learned some stuff here and truly appreciate it

    Ben
     
    Ben, Jul 22, 2006
    #5
  6. Ben

    CS Guest

    Glad to help Happy CODING
     
    CS, Jul 24, 2006
    #6
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.