Hallo, wenn es hilft, unten finden Sie einen Codeausschnitt, mit dem Sie eine Grundkarte unabhängig vom ursprünglichen Format des Plans neu laden können (beschränkt auf A4, A3, A2, A1). Es genügt ein Klick, der einmal mit einer Schaltfläche verknüpft ist.
Option Explicit
Public Enum swDocumentTypes_e
swDocNONE = 0 ' Used to be TYPE_NONE
swDocPART = 1 ' Used to be TYPE_PART
swDocASSEMBLY = 2 ' Used to be TYPE_ASSEMBLY
swDocDRAWING = 3 ' Used to be TYPE_DRAWING
End Enum
Dim swSheet As SldWorks.Sheet
Dim swApp As Object
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swModelDocExt As ModelDocExtension
Dim sTemplate As String
Dim stemplatepath As String
Dim Count As Integer
Dim vSheetNameArr As Variant
Dim vSheetName As Variant
Dim vSheetProps As Variant
Dim bRet As Boolean
'Constantes
Const cDirTemplate = "..." 'Mettre le chemin d'accès aux fonds de plans sous ce format: C:\xxx\xxx\
Const cTemplateA4 = "A4.slddrt" 'A renommer si vos templates s'appelent autrement
Const cTemplateA3 = "A3.slddrt"
Const cTemplateA2 = "A2.slddrt"
Const cTemplateA1 = "A1.slddrt"
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox ("Pas de document ouvert")
Else
If swModel.GetType <> 3 Then
MsgBox ("Il ne s'agît pas d'une mise en plan")
Else
Set swDraw = swModel
Set swModelDocExt = swModel.Extension
vSheetNameArr = swDraw.GetSheetNames
For Each vSheetName In vSheetNameArr
bRet = swDraw.ActivateSheet(vSheetName): Debug.Assert bRet
Set swSheet = swDraw.GetCurrentSheet
vSheetProps = swSheet.GetProperties
If vSheetProps(0) = "7" Then 'A4
stemplatepath = cDirTemplate & cTemplateA3
bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
stemplatepath = cDirTemplate & cTemplateA4
bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
swModel.ForceRebuild3 (False)
ElseIf vSheetProps(0) = "8" Then 'A3
stemplatepath = cDirTemplate & cTemplateA4
bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
stemplatepath = cDirTemplate & cTemplateA3
bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
swModel.ForceRebuild3 (False) 'A2
ElseIf vSheetProps(0) = "9" Then
stemplatepath = cDirTemplate & cTemplateA4
bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
stemplatepath = cDirTemplate & cTemplateA2
bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
swModel.ForceRebuild3 (False)
ElseIf vSheetProps(0) = "10" Then 'A1
stemplatepath = cDirTemplate & cTemplateA4
bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
stemplatepath = cDirTemplate & cTemplateA1
bRet = swDraw.SetupSheet4(swSheet.GetName, vSheetProps(0), 12, vSheetProps(2), vSheetProps(3), True, stemplatepath, 0#, 0#, "")
swModel.ForceRebuild3 (False)
ElseIf vSheetProps(0) <> "7" Then 'Pour les formats un peu exotiques non gérés
If vSheetProps(0) <> "8" Then
If vSheetProps(0) <> "9" Then
If vSheetProps(0) <> "10" Then
MsgBox "Le fond de plan ne correspond à aucune trame connue" & vbCrLf & "Aucun changement appliqué"
Exit Sub
End If: End If: End If
End If
Next
End If
End If
swModel.Save2 (True) 'Sauvegarde des changements
End Sub