How to select the planes by name
Posted: Mon Jul 12, 2021 9:17 am
Hello there,
I apologize if this question is easy.
I want to build a macro in SW 20 to select planes e.g. "Plane 1","Plane 2","Plane 3" and so on... to sketch a circle in each plane. I used the following code to do that, but it turned out that only the first plane in the feature tree will be selected and creatingCircle was applied many times on a same plane.
Anyone knows how can I modify my code to select planes? Thanks a lot in advance.
Code:
Sub selectPlanes()
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim i As Integer
Dim swSketchSegment As Object
Dim swSketchMgr As SldWorks.SketchManager
Dim PlaneName As String
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swSketchMgr = Part.SketchManager
For i = 1 To 3 Step 1
' Use the loop to select the planes where the sketchs to be drawed
PlaneName = "Plane" & "i"
boolstatus = Part.Extension.SelectByID2(PlaneName, "Plane", 0, 0, 0, True, 0, Nothing, 0)
Part.InsertSketch2 True
Set swSketchSegment = swSketchMgr.CreateCircle(0#, 0#, 0#, 0.01 * i, 0.01 * i, 0#)
Part.ClearSelection2 True
Part.InsertSketch2 True
Next i
End Sub
I apologize if this question is easy.
I want to build a macro in SW 20 to select planes e.g. "Plane 1","Plane 2","Plane 3" and so on... to sketch a circle in each plane. I used the following code to do that, but it turned out that only the first plane in the feature tree will be selected and creatingCircle was applied many times on a same plane.
Anyone knows how can I modify my code to select planes? Thanks a lot in advance.
Code:
Sub selectPlanes()
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim i As Integer
Dim swSketchSegment As Object
Dim swSketchMgr As SldWorks.SketchManager
Dim PlaneName As String
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swSketchMgr = Part.SketchManager
For i = 1 To 3 Step 1
' Use the loop to select the planes where the sketchs to be drawed
PlaneName = "Plane" & "i"
boolstatus = Part.Extension.SelectByID2(PlaneName, "Plane", 0, 0, 0, True, 0, Nothing, 0)
Part.InsertSketch2 True
Set swSketchSegment = swSketchMgr.CreateCircle(0#, 0#, 0#, 0.01 * i, 0.01 * i, 0#)
Part.ClearSelection2 True
Part.InsertSketch2 True
Next i
End Sub