Get first Bend-Line sketch name (vba)

Hello,

I want to get the name of the 1st sketch (here Bend-lines2) in a drawing in the 1st view in the flat-pattern state of my 1st piece. (already in first sheet, 1rst view and 1rst sheet-metal flat-pattern)

I try to hide/show this sketch but the name is different depending on the piece.

The code when i know the name:

Dim swApp As Object
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.ActivateView("Drawing View1")
boolstatus = Part.Extension.SelectByID2("Bend-Lines2@Part1@DV1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Part.BlankSketch
MsgBox "Bend-Lines sketch hide"
boolstatus = Part.Extension.SelectByID2("Bend-Lines2@Part1@DV1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Part.UnblankSketch
MsgBox "Bend-Lines sketch show"
End Sub‍‍‍‍‍‍‍‍‍‍‍‍‍
 
SolidworksApi/macros
Answers 1
SD
SD 2021-04-08 Best Answer

The solution of my problems:

Option Explicit<br>Sub main()<br>    Dim swApp As SldWorks.SldWorks<br>    Dim swModel As SldWorks.ModelDoc2<br>    Dim swDraw As SldWorks.DrawingDoc<br>    Dim swPartModel As SldWorks.ModelDoc2<br>    Dim swFeat As SldWorks.Feature<br>    Dim swSubFeat As SldWorks.Feature<br>    Dim swView As SldWorks.View<br>    Dim swSelMgr As SldWorks.SelectionMgr<br>    Dim boolstatus As Boolean<br>    Set swApp = Application.SldWorks<br>    Set swModel = swApp.ActiveDoc<br>    Set swDraw = swModel<br>    Set swSelMgr = swModel.SelectionManager<br>    Set swView = swDraw.ActiveDrawingView<br>    If swView Is Nothing Then<br>        MsgBox "Sélectionner une vue"<br>        Exit Sub<br>    End If<br><br>    Set swPartModel = swView.ReferencedDocument<br>    Set swFeat = swPartModel.FirstFeature<br>    While Not swFeat Is Nothing<br>        'Debug.Print swFeat.Name & " " & swFeat.GetTypeName2'<br>        If swFeat.GetTypeName2 = "FlatPattern" Then<br>            Set swSubFeat = swFeat.GetFirstSubFeature<br>            While Not swSubFeat Is Nothing<br>                If swSubFeat.GetTypeName2 = "ProfileFeature" Then<br>                    Debug.Print swSubFeat.Name & "@" & swPartModel.GetTitle & "@" & swView.GetName2<br>                    boolstatus = swModel.Extension.SelectByID2(swSubFeat.Name & "@" & swPartModel.GetTitle & "@" & swView.GetName2, "SKETCH", 0, 0, 0, False, 0, Nothing, 0)<br>                    swModel.UnblankSketch<br><br>                    swModel.ClearSelection2 True<br>                    Exit Sub<br>                End If<br>                Set swSubFeat = swSubFeat.GetNextSubFeature<br>            Wend<br>        End If<br>        Set swFeat = swFeat.GetNextFeature<br>    Wend<br>End Sub<span class="line-numbers-rows"><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span></span>