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!

x, y, z table in api

Status
Not open for further replies.

Bwaggoner

Mechanical
Apr 9, 2007
23
We are trying to create a table just like the hole table in solidworks. Our problem is we are cutting a path, like for a gasket track. We need to be able to capture the coordinates of the sketch points. I've got some code that I'm working with but it captures arc center points as well, which we don't need. I would like to create something that would allow the user to select the sketch points that they need and possibly wait for more sketch points to add to the finished table.
Unless someone can come up with another way to do this. This is the best way that we've come up with.

Code:
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
 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 = Round(sp.x * 1000 / 25.4, DEC)
         sheet.Cells(2 + i, 3).Value = Round(sp.Y * 1000 / 25.4, DEC)
         sheet.Cells(2 + i, 4).Value = Round(sp.Z * 1000 / 25.4, DEC)
         exApp.Columns.AutoFit
        End If
       Next i
      End If
     End If
    End If
   End If
  End If
 End If
End Sub
 
Replies continue below

Recommended for you

That will give you the arc centerpoints as well. Which they are not wanting.

What I would like is to have the user select each point and then let the macro capture the coords. of each. Also we have more than 1 sketch so if it could allow user to get into another sketch that would be great.

I just don't know how to allow the user to select an item on the screen then process something.

Thanks.
 
You could traverse all the arcs, get the centerpoint coordinates, compare & eliminate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor