Page 1 of 1

How to select the planes by name

Posted: Mon Jul 12, 2021 9:17 am
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

Re: How to select the planes by name

Posted: Mon Jul 12, 2021 9:38 am
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

Re: How to select the planes by name

Posted: Mon Jul 12, 2021 9:53 am
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

Re: How to select the planes by name

Posted: Wed Jul 14, 2021 12:09 pm
by Eddy Alleman
You're welcome