How to select bottom plane in C# Solidworks API?

72 views Asked by At

Does any know how to select bottom plane in C# SolidWorks API?

I tried to set "Bottom" in doc.Extension.SelectByID2("Bottom", "PLANE", 0, 0, 0, false, 0, null, 0); but it doesn't work. ChatGPT also doesn't help me

1

There are 1 answers

0
bigcrazyal On

With something relatively simple such as selecting an item from the feature tree, the macro recorder is helpful enough.

VBA Macro Recorder Code:

Option Explicit

Dim swApp As Object

Dim Part As Object

Sub main()
    Set swApp = Application.SldWorks
    Set Part = swApp.ActiveDoc
    Part.Extension.SelectByID2 "Top Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0
End Sub

Since your example is in c#, this is the relevant code in c# after you've set your swApp to the current solidworks application:

var swModel = swApp.ActiveDoc as ModelDoc2;

bool bSel = swModel.Extension.SelectByID2("Top Plane", "PLANE", 0, 0, 0, false, 0, null, 0);

This is assuming you are using the built in macro tool and not a standalone application.

Edit: Note that using the SelectByID2 function requires that you use the exact name of the plane from the feature tree. If it's not named "Bottom" then it won't work.