Find part ID information in a drawing file

Hello

In a vba macro, I'm looking to hide the bend line sketch in the design tree. to do my selectID2 I have to put the name of the sketch and the name of the part with the name of the view.
I noticed that the number between <> changes with each view. How can I retrieve this information in order to select the entity in the design tree and use my blanksketch function.

If Not swSheet Is Nothing Then
                Debug.Print "Feuille activée: " & swSheet.GetName

                ' Obtenir la première vue de la feuille
                Set swView = swDraw.GetFirstView
                ' La première vue est toujours la vue du modèle, passer à la suivante
                Set swView = swView.GetNextView
                    Debug.Print "Nom de la vue sélectionnée :" & swView.Name
                    
                Do While Not swView Is Nothing
                    Debug.Print "Configuration de la vue: " & swView.ReferencedConfiguration
                    If swView.ReferencedConfiguration = configName Then
                        ' Obtenir le modèle de la vue
                        Set swPart = swView.ReferencedDocument
                        If Not swPart Is Nothing Then
                            Debug.Print "Modèle référencé: " & swPart.GetPathName

                            ' Parcourir les esquisses pour trouver et cacher les lignes de pliage
                            Set swFeat = swPart.FirstFeature
                            Do While Not swFeat Is Nothing
                                Debug.Print "swFeat :" & swFeat.GetTypeName
                            Set swSubFeat = swFeat.GetFirstSubFeature
                            'arborescence de sous niveau
                                Do While Not swSubFeat Is Nothing
                                        Debug.Print "swSubFeat :" & swSubFeat.GetTypeName
                                    If swSubFeat.GetTypeName = "ProfileFeature" Then
                                        swSketchName = swSubFeat.Name
                                        If swSketchName Like "Lignes de pliage*" Then
                                            boolstatus = swModel.ActivateView(swView.Name)
                                                Debug.Print "Nom de la vue sélectionnée :" & swView.Name
                                            récupérer le PartID du fichier référencé
                                            
                                            SelectItemPlan = swSubFeat.Name & "@" & NomFichierRacine & "-" & partID & "@" & swView.Name
                                            boolstatus = swModel.Extension.SelectByID2(SelectItemPlan, "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
                                            If boolstatus Then
                                                swModel.BlankSketch
                                                swModel.ClearSelection2 True
                                                Debug.Print "Esquisse " & swSubFeat.Name & " cachée pour la feuille " & sheetName & " avec la configuration " & configName
                                            Else
                                                MsgBox "Échec de la sélection pour " & swSubFeat.Name
                                            End If
                                        End If
                                    End If
                                    Set swSubFeat = swSubFeat.GetNextSubFeature()
                                Loop
                                Set swFeat = swFeat.GetNextFeature
                            Loop
                        Else
                            MsgBox "Modèle référencé non trouvé pour la vue avec la configuration " & configName
                        End If
                        Exit Do
                    End If
                    Set swView = swView.GetNextView
                Loop
            Else
                MsgBox "Feuille non trouvée: " & sheetName
            End If

Thank you in advance.
Kind regards.

Hello;

This is the occurrence identifier:
image

Kind regards.

2 Likes

Hello

Thank you that seems like it, but this code example works on an assembly. I'd like to retrieve this identifier that is in the referenced document of the drawing view. First, I select my " Drawing View2 " view for example and I would like it to tell me this occurrence identifier for part F0-99999-0 in this example.
Thank you in advance.
Kind regards.

Hello;

So with the variable " Name2 "
https://help.solidworks.com/2022/English/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IComponent2~Name2.html?verRedirect=1
(used in the Solidworks Example macro):
https://help.solidworks.com/2019/english/api/sldworksapi/Get_Components_in_Drawing_View_Example_VB.htm
See line:
Debug.Print " Component = " & swComp. Name2

Kind regards.

1 Like

Hello
I've tried but I can't seem to exploit it. I'm looking for this identifier for a part file referenced in the drawing and not an assembly. I have tried several modifications and it does not work.

Hello;
The variable remains the same: ( Name2)
https://help.solidworks.com/2019/english/api/sldworksapi/Get_Visible_Components_and_Entities_in_Drawing_View_Example_VB.htm

or more generally:
https://help.solidworks.com/SearchEx.aspx?query=Get%20Components%20in%20Drawing&version=2019&lang=english&prod=api

1 Like

Hello

Works well with the API example given by @Maclane Get Components in Drawing View Example (VBA) - 2023 - SOLIDWORKS API Help
The ID is contained at the end of the component name -n, so you have to decompose the result of the line Component = " & swComp.Name2 to output the ID

2 Likes