How to select the planes by name

Programming and macros
cd123333
Posts: 3
Joined: Tue Jun 22, 2021 2:38 pm
Answers: 0
x 1
x 1

How to select the planes by name

Unread post by cd123333 »

Hello there,

I apologize if this question is easy. UU

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
Attachments
Image3.png
by Eddy Alleman » 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
Go to full post
User avatar
Eddy Alleman
Posts: 50
Joined: Thu Apr 01, 2021 10:32 am
Answers: 8
Location: Belgium
x 80
x 89
Contact:

Re: How to select the planes by name

Unread post by Eddy Alleman »

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
cd123333
Posts: 3
Joined: Tue Jun 22, 2021 2:38 pm
Answers: 0
x 1
x 1

Re: How to select the planes by name

Unread post by cd123333 »

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
Hi Eddy, thank you for your answer! UU
User avatar
Eddy Alleman
Posts: 50
Joined: Thu Apr 01, 2021 10:32 am
Answers: 8
Location: Belgium
x 80
x 89
Contact:

Re: How to select the planes by name

Unread post by Eddy Alleman »

You're welcome
Post Reply