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