2003 macro, select all segments

Jul 07, 2005 2 Replies

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


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 '----------------------------------------------------

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...

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required