Macro hide basemap, BOM table (not bubble) and revision table

Hello
For a drawing export only with views, I'm looking for a macro that:
1 - hides the basemap (uncheck ' Show basemap ' in sheet property)
2-hides the table ‹ Nomenclature1 ›
3-Hide Table ‹ Revision Table1 ›
then a .ai registration
and finally redisplay the hide elements.

Thank you all in advance for your help.
Thierry

Hello

Several questions:

  • A single sheet?
  • One bill of materials and one revision table per page?

Hiding elements is not very complicated in macro but you need to know the number of elements to hide and whether a processing on several sheets or not

1 Like

Hello
yes, a single sheet ‹ Sheet1 ›
One bill of materials ‹ Schedule1 ›
and a single revision table ‹ Revision Table1 ›

Thank you
image

Hello

Code below to test:

Dim swSheet         As SldWorks.Sheet
Dim swApp           As SldWorks.SldWorks
Dim swModel         As SldWorks.ModelDoc2
Dim swModelDocExt   As ModelDocExtension
Dim swDraw          As SldWorks.DrawingDoc
Dim swView          As SldWorks.View
Dim swAnn           As SldWorks.Annotation
Dim boolstatus      As Boolean
Dim sPathName       As String
Dim lErrors         As Long
Dim lWarnings       As Long

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
    MsgBox ("Pas de document ouvert")
    Exit Sub
    Else
        Set swModelDocExt = swModel.Extension
        If swModel.GetType <> 3 Then
            MsgBox ("Il ne s'agît pas d'une mise en plan")
        Else
            Set swDraw = swModel
            Set swSheet = swDraw.GetCurrentSheet
            swSheet.SheetFormatVisible = False ' Masque le fond de plan
            Set swView = swDraw.GetFirstView
            Do While Not Nothing Is swView
                Set swAnn = swView.GetFirstAnnotation3
                Do While Not Nothing Is swAnn
                    If swAnn.GetType = swTableAnnotation Then 'Verifie si c'est un objet de type table (BOM ou révision)
                        swAnn.Visible = swAnnotationHidden ' Cache les tables
                    End If
                Set swAnn = swAnn.GetNext3
                Loop
                Set swView = swView.GetNextView
            Loop
            sPathName = swModel.GetPathName 'Recupere le nom complet du document actif
            sPathName = Left(sPathName, Len(sPathName) - 6) 'Suppression de l'extension
            sPathName = sPathName + "ai" 'Formatage du nom d'enregistrement
            boolstatus = swModelDocExt.SaveAs3(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, Nothing, lErrors, lWarnings)
        End If
        swSheet.SheetFormatVisible = True 'Affiche le fond de plan
        Set swView = swDraw.GetFirstView
            Do While Not Nothing Is swView
                Set swAnn = swView.GetFirstAnnotation3
                Do While Not Nothing Is swAnn
                    If swAnn.GetType = swTableAnnotation Then 'Verifie si c'est un objet de type table (BOM ou révision)
                        swAnn.Visible = swAnnotationVisible ' Affiche les tables
                    End If
                Set swAnn = swAnn.GetNext3
                Loop
                Set swView = swView.GetNextView
            Loop
End If
End Sub

Didn't handle whether the ai file exists or not (possible to add)

1 Like

Thank you, that's perfect!!

1 Like

Hello

I skipped a subject.

If several sheets, I want to save only the 1st sheet in Ai, currently the macro saves all the sheets
Thank you for your help.
Thierry

Hello
I have to look but from memory only the PDF export allows it natively in the API.
You will certainly have to " tinker" to remove the sheets not to be exported and then close the file without saving.

Hello
In fact, by carrying out several tests, there is no way of exporting only the sheet 1 in .ai.
Temporarily, I delete sheet2, launch the macro and when generated file touches anulate (ctrl + Z) .
Is it playable with the macro.

Thank you
Thierry

Hello
Yes doable I look at it when I have a little time

Hello

Here is the modified code:

Dim swSheet             As SldWorks.Sheet
Dim swApp               As SldWorks.SldWorks
Dim swModel             As SldWorks.ModelDoc2
Dim swModelDocExt       As ModelDocExtension
Dim swDraw              As SldWorks.DrawingDoc
Dim swView              As SldWorks.View
Dim swAnn               As SldWorks.Annotation
Dim boolstatus          As Boolean
Dim sPathName           As String
Dim lErrors             As Long
Dim lWarnings           As Long
Dim vSheetNameArr       As Variant
Dim vSheetName          As Variant
Dim lUndo               As Long


Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
    MsgBox ("Pas de document ouvert")
    Exit Sub
    Else
        Set swModelDocExt = swModel.Extension
        If swModel.GetType <> 3 Then
            MsgBox ("Il ne s'agît pas d'une mise en plan")
        Else
            Set swDraw = swModel
            Set swSheet = swDraw.GetCurrentSheet
            swSheet.SheetFormatVisible = False ' Masque le fond de plan
            Set swView = swDraw.GetFirstView
            Do While Not Nothing Is swView
                Set swAnn = swView.GetFirstAnnotation3
                Do While Not Nothing Is swAnn
                    If swAnn.GetType = swTableAnnotation Then 'Verifie si c'est un objet de type table (BOM ou révision)
                        swAnn.Visible = swAnnotationHidden ' Cache les tables
                    End If
                Set swAnn = swAnn.GetNext3
                Loop
                Set swView = swView.GetNextView
            Loop
            lUndo = swDraw.GetSheetCount - 1
            vSheetNameArr = swDraw.GetSheetNames  'Récupère tous les noms de feuilles
            For Each vSheetName In vSheetNameArr  'Boucle sur les noms de feuilles
                If vSheetName <> "Feuille1" Then 'Sélection des feuilles autres que la feuille 1
                    swModel.SelectByName 0, vSheetName 'Sélection de la feuille à supprimer
                    boolstatus = swModel.DeleteSelection(False) 'Suppression de la feuille
                End If
            Next
            sPathName = swModel.GetPathName 'Recupere le nom complet du document actif
            sPathName = Left(sPathName, Len(sPathName) - 6) 'Suppression de l'extension
            sPathName = sPathName + "ai" 'Formatage du nom d'enregistrement
            boolstatus = swModelDocExt.SaveAs3(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, Nothing, lErrors, lWarnings)
        End If
        swModel.EditUndo2 (lUndo) 'Annule les suppressions de feuilles
        swSheet.SheetFormatVisible = True 'Affiche le fond de plan
        Set swView = swDraw.GetFirstView
            Do While Not Nothing Is swView
                Set swAnn = swView.GetFirstAnnotation3
                Do While Not Nothing Is swAnn
                    If swAnn.GetType = swTableAnnotation Then 'Verifie si c'est un objet de type table (BOM ou révision)
                        swAnn.Visible = swAnnotationVisible ' Affiche les tables
                    End If
                Set swAnn = swAnn.GetNext3
                Loop
                Set swView = swView.GetNextView
            Loop
End If
End Sub

1 Like

Hello
Perfect, it works wonderfully!!
My abilities in VBA are limited, even very limited.
So one last question if possible on the attached code, I can't find the solution to check ' ‹ ‹ display under a single article the configurations with the same name › › in Grouping the configurations of parts of the created name.
Do you have a solution?

In advance a big thank you again

nomenclatue.docx (17.5 KB)

Hello

Must add: swBOMFeat.DisplayAsOneItem = True

Hello

Thank you for your quick answer, but it doesn't work, it remains ticked to '  'display separately the configurations of the same coin ' › › while I want to '  'display under a single article the configurations with the same name''.
what's the code??
Thank you

Sorry, I got the wrong parameter: swBOMFeat.PartConfigurationGrouping = swDisplay_AllConfigurationOfSamePart_AsOneItem