Face or edge selection

Hi all

I'm looking for how to select a specific face of a part in an assembly with the "Part.Extension.SelectByID2" function for an API

 

Hello

Can you please specify your request?

You want to select a face of a part in an assembly from its feature name:

Or from its entity name:

Kind regards

3 Likes

Hello

Finally, I have an extrusion (a volume) and I want to select a specific side of this extrusion

C

Hello

If it's something like:

MySelection = "Face<1>@Boss.-Extru.1@maPiece-1@monAssemblage"
bRet = swDocExt.SelectByID2(MySelection, "FACE", 0, 0, 0, False, 1, Nothing, swSelectOptionDefault)

that you want to do this is, to my knowledge, not possible, it seems to me that this possibility is not implemented in the "SelectByID2" function.

On the other hand, if you have the possibility to put a specific name in the properties of the face (right click on the face then properties of the face) then you can then select it by the APIs using the "GetEntityName" function that you can find HERE.

Kind regards

Hello

I have located with right click the face to select but it has no selection, I attach my sample code

value = Part.Extension.GetEntityName("toto@Pièce1.prt")

 

Kind regards

 


Part1.SLDPRT

Hello

Here's an example of code to select your face called "foo" on your attachment.

Option Explicit

Sub main()
    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim swSelData               As SldWorks.SelectData
    Dim swBody                  As SldWorks.Body2
    Dim swFaceFeat              As SldWorks.Feature
    Dim vBody                   As Variant
    Dim vBodyArr                As Variant
    Dim swFace                  As SldWorks.Face2
    Dim swEnt                   As SldWorks.Entity
    Dim bRet                    As Boolean
    Dim EntityName              As String

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    If swModel.GetType = swDocPART Then
        swModel.ClearSelection2 True
        vBodyArr = swModel.GetBodies2(swSolidBody, False)
        For Each vBody In vBodyArr
            Set swBody = vBody
            Set swFace = swBody.GetFirstFace
            Do While Not swFace Is Nothing
                Set swEnt = swFace
                EntityName = swModel.GetEntityName(swEnt)
                If EntityName = "toto" Then
                    bRet = swEnt.Select4(True, swSelData): Debug.Assert bRet
                End If
                Set swFace = swFace.GetNextFace
            Loop
        Next
    End If
End Sub

Kind regards

2 Likes