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.
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)
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.
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
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?
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