2003 macro, select all segments

Discussion in 'SolidWorks' started by toolman, Jul 7, 2005.

  1. toolman

    toolman Guest

    In the recorded macro you see below, I have selected 2-sketch segments. I
    want to change that so that ALL sketch segments are selected. Can anyone
    help me with this? Thanks.

    Sub main()

    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc
    boolstatus = Part.Extension.SelectByID("Line1", "SKETCHSEGMENT", 0, 0, 0,
    True, 0, Nothing)
    boolstatus = Part.Extension.SelectByID("Line2", "SKETCHSEGMENT", 0, 0, 0,
    True, 0, Nothing)
    Part.ClearSelection
    boolstatus = Part.Extension.SelectByID("Line1", "SKETCHSEGMENT", 0, 0, 0,
    False, 1, Nothing)
    boolstatus = Part.Extension.SelectByID("Line2", "SKETCHSEGMENT", 0, 0, 0,
    True, 1, Nothing)
    Part.FeatureManager.MakeStyledCurves 0.0000127, 1
    Part.ClearSelection
    Part.ClearSelection
    Part.InsertSketch2 True
    End Sub
     
    toolman, Jul 7, 2005
    #1
  2. toolman

    Tin Man Guest

    I have this example in my native SW2004 Help file, maybe it will help.
    You have to preselect the sketch before running the macro.

    Ken

    Find Total Length of Sketch Segments in Sketch Example (VB)
    This example shows how to find the total length of all sketch segments
    in a sketch.

    '----------------------------------------------------
    Option Explicit

    Public Enum swSketchSegments_e
    swSketchLine = 0
    swSketchArc = 1
    swSketchEllipse = 2
    swSketchSpline = 3
    swSketchTEXT = 4
    swSketchParabola = 5
    End Enum

    Sub main()

    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swSelMgr As SldWorks.SelectionMgr
    Dim swFeat As SldWorks.feature
    Dim swSketch As SldWorks.sketch
    Dim i As Long
    Dim bRet As Boolean

    Dim vSketchSeg As Variant
    Dim swSketchSeg As SldWorks.SketchSegment
    Dim nLength As Double


    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    Set swSelMgr = swModel.SelectionManager
    Set swFeat = swSelMgr.GetSelectedObject5(1)
    Set swSketch = swFeat.GetSpecificFeature2

    vSketchSeg = swSketch.GetSketchSegments
    For i = 0 To UBound(vSketchSeg)
    Set swSketchSeg = vSketchSeg(i)

    ' Ignore construction lines
    If swSketchSeg.ConstructionGeometry = False Then
    ' ignore text
    If swSketchTEXT <> swSketchSeg.GetType Then
    nLength = nLength + swSketchSeg.GetLength
    End If
    End If
    Next i

    Debug.Print "File = " & swModel.GetPathName
    Debug.Print " Sketch = " & swFeat.Name
    Debug.Print " Total length = " & nLength * 1000# & " mm"
    End Sub
    '----------------------------------------------------
     
    Tin Man, Jul 8, 2005
    #2
  3. toolman

    toolman Guest

    I have the same example in 2003. I don't know VB. All I am able to do is
    "record" which is what I posted.

    For me to get it to work, somebody that spends their day struggling with
    this stuff is going to have to give me the exact "select all" syntax that I
    can substitute for where it reads, "boolstatus =
    Part.Extension.SelectByID("Line1", SKETCHSEGMENT", 0, 0, 0, False, 1,
    Nothing) boolstatus = Part.Extension.SelectByID("Line2", "SKETCHSEGMENT", 0,
    0, 0, True, 1, nothing)".

    I appreciate your interest, though...
     
    toolman, Jul 8, 2005
    #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.