Select component's face in assembly

I’m trying to show the flat pattern’s fixed face for any selected sheetmetal part in the assembly.

I already tried the method swEntity.Select3 the return value is True but nothing is selected.

1 Like

You need to post some code with an example assembly.

Got it!

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swComp As SldWorks.Component2
Dim swEnt As SldWorks.Entity

Sub Main()

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

Dim Sheetmetal_Flatpattern_Name As String

If swModel.GetType = swDocPART Then
        
    Sheetmetal_Flatpattern_Name = Get_Flatpattern_Name(swModel)
Else
    
    Set swComp = swModel.SelectionManager.GetSelectedObjectsComponent2(1)
    
    Sheetmetal_Flatpattern_Name = Get_Flatpattern_Name(swComp.GetModelDoc2)
       
    Set swEnt = swComp.GetCorrespondingEntity(swEnt)
End If

swEnt.Select False
End Sub

Private Function Get_Flatpattern_Name(ByVal Ref_Model As SldWorks.ModelDoc2) As String

Dim Ref_Feat As SldWorks.Feature
Dim Ref_SheetMetal As SldWorks.SheetMetalFeatureData
Dim Ref_FlatPattern As SldWorks.FlatPatternFeatureData
Dim Ref_Face As SldWorks.Face2

Set Ref_Feat = Ref_Model.FirstFeature

Do While Not Ref_Feat Is Nothing

    If Ref_Feat.GetTypeName2 = "FlatPattern" Then
        Get_Flatpattern_Name = Ref_Feat.name
        Exit Do
      End If

    Set Ref_Feat = Ref_Feat.GetNextFeature
Loop

Set Ref_FlatPattern = Ref_Feat.GetDefinition

Ref_FlatPattern.AccessSelections Ref_Model, Nothing

Set Ref_Face = Ref_FlatPattern.FixedFace2

Ref_FlatPattern.ReleaseSelectionAccess

Set swEnt = Ref_Face
Set swEnt = swEnt.GetSafeEntity
End Function

This was the missing line in the code:
Set swEnt = swComp.GetCorrespondingEntity(swEnt)

1 Like