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
How to select the planes by name
How to select the planes by name
Hi,
in the line
PlaneName = "Plane" & "i" (results in Planei)
change it to
PlaneName = "Plane" & i (results in Plane1, Plane2,...)
Also in the line
boolstatus = Part.Extension.SelectByID2(PlaneName, "Plane", 0, 0, 0, True, 0, Nothing, 0)
Plane should be PLANE
from the docs:
Type
Type of object (uppercase) as defined in swSelectType_e or an empty string
Eddy
Go to full postin the line
PlaneName = "Plane" & "i" (results in Planei)
change it to
PlaneName = "Plane" & i (results in Plane1, Plane2,...)
Also in the line
boolstatus = Part.Extension.SelectByID2(PlaneName, "Plane", 0, 0, 0, True, 0, Nothing, 0)
Plane should be PLANE
from the docs:
Type
Type of object (uppercase) as defined in swSelectType_e or an empty string
Eddy
- Eddy Alleman
- Posts: 50
- Joined: Thu Apr 01, 2021 10:32 am
- Location: Belgium
- x 80
- x 89
- Contact:
Re: How to select the planes by name
Hi,
in the line
PlaneName = "Plane" & "i" (results in Planei)
change it to
PlaneName = "Plane" & i (results in Plane1, Plane2,...)
Also in the line
boolstatus = Part.Extension.SelectByID2(PlaneName, "Plane", 0, 0, 0, True, 0, Nothing, 0)
Plane should be PLANE
from the docs:
Type
Type of object (uppercase) as defined in swSelectType_e or an empty string
Eddy
in the line
PlaneName = "Plane" & "i" (results in Planei)
change it to
PlaneName = "Plane" & i (results in Plane1, Plane2,...)
Also in the line
boolstatus = Part.Extension.SelectByID2(PlaneName, "Plane", 0, 0, 0, True, 0, Nothing, 0)
Plane should be PLANE
from the docs:
Type
Type of object (uppercase) as defined in swSelectType_e or an empty string
Eddy
Re: How to select the planes by name
Hi Eddy, thank you for your answer!Eddy Alleman wrote: ↑Mon Jul 12, 2021 9:38 am Hi,
in the line
PlaneName = "Plane" & "i" (results in Planei)
change it to
PlaneName = "Plane" & i (results in Plane1, Plane2,...)
Also in the line
boolstatus = Part.Extension.SelectByID2(PlaneName, "Plane", 0, 0, 0, True, 0, Nothing, 0)
Plane should be PLANE
from the docs:
Type
Type of object (uppercase) as defined in swSelectType_e or an empty string
Eddy
- Eddy Alleman
- Posts: 50
- Joined: Thu Apr 01, 2021 10:32 am
- Location: Belgium
- x 80
- x 89
- Contact: