→ @Lynkoa15
Indeed, this implies "breaking" all external references and re-associating the drawings and assemblies.
For the more "MACRO-teux" this macro also does a good part of the JOB: To customize according to your location of the Norms and templates files...
-For advanced users only...
Dim Part As Object
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModExt As SldWorks.ModelDocExtension
Dim NormeActive As String
Dim DefaultSlotMate As String
Sub Norme()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModExt = swModel.Extension
NormeActive = swModExt.GetUserPreferenceString(SwConst.swDetailingDimensionStandardName, SwConst.swDetailingNoOptionSpecified) 'Ecrit la Norme existante du fichier ouvert dans la variable
Debug.Print NormeActive
ModelDoc = swModel.GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swDefaultTemplateAssembly)
Debug.Print ModelDoc
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
filetype = swModel.GetType 'Donne le type de document ouvert avec :0=swDocNONE;1=swDocPART;2=swDocASSEMBLY;3=swDocDRAWING
If filetype = 1 Then
boolstatus = Part.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\Emplacement de votre modele PRT.sldstd") '<- Emplacement exacte du fichier sldstd pour vos pièces
End If
If filetype = 2 Then 'Si le fichier ouvert est un Assemblage
boolstatus = Part.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\Emplacement de votre modele ASM.sldstd") '<- Emplacement exacte du fichier sldstd pour vos Assemblages
defaultTemplate = "W:\Modeles_solidworks\Assemblage .asmdot"
End If
If filetype = 3 Then 'Si le fichier ouvert est une Mise en plan
Call Formats
End If
End Sub
-> Dans un nouveau Module
Dim vSheetProps As Variant
Dim nErrors As Long
Dim nTemplatePath As String
Dim swPaperWidth As String
Dim swPaperHeight As String
' Repertoire contenant les modeles des fonds de plans
Const sTemplatePath As String = "W:\Modeles_solidworks\Fonds_de_plans_2023"
' Formats des differents fond de plans disponibles dans le Repertoire ci-dessous
Const A0HTemplateName As String = "A0H.slddrt"
Const A1HTemplateName As String = "A1H.slddrt"
Const A1VTemplateName As String = "A1V.slddrt"
Const A2HTemplateName As String = "A2H.slddrt"
Const A2VTemplateName As String = "A2V .slddrt"
Const A3HTemplateName As String = "A3H.slddrt"
Const A3VTemplateName As String = "A3V.slddrt"
Const A4HTemplateName As String = "A4H.slddrt"
Const A4VTemplateName As String = "A4V.slddrt"
Sub Formats()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim vSheetProps As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet
'swModel.ActivateSheet vSheetName
Set swSheet = swModel.GetCurrentSheet
vSheetProps = swSheet.GetProperties
swPaperWidth = vSheetProps(5)
swPaperHeight = vSheetProps(6)
Select Case swPaperWidth & swPaperHeight ' Comparaison de la Longueur et de la Largeur du fond de plan present (Unité en Metres)
Case "1,189" & "0,841" ' Format A0H
nTemplatePath = sTemplatePath & "\" & A0HTemplateName
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\A0.sldstd")
Case "0,841" & "0,594" ' Format A1H
nTemplatePath = sTemplatePath & "\" & A1HTemplateName
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\A1.sldstd")
Case "0,594" & "0,841" ' Format A1V
nTemplatePath = sTemplatePath & "\" & A1VTemplateName
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\A1.sldstd")
Case "0,594" & "0,42" ' Format A2H
nTemplatePath = sTemplatePath & "\" & A2HTemplateName
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\A2.sldstd")
Case "0,42" & "0,594" ' Format A2V
nTemplatePath = sTemplatePath & "\" & A2VTemplateName
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\A2.sldstd")
Case "0,42" & "0,297" ' Format A3H
nTemplatePath = sTemplatePath & "\" & A3HTemplateName
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\A3.sldstd")
Case "0,297" & "0,42" ' Format A3V
nTemplatePath = sTemplatePath & "\" & A3VTemplateName
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\A3.sldstd")
Case "0,297" & "0,21" ' Format A4H
nTemplatePath = sTemplatePath & "\" & A4HTemplateName
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\A4.sldstd")
Case "0,21" & "0,297" ' Format A4V
nTemplatePath = sTemplatePath & "\" & A4VTemplateName
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\A4.sldstd")
Case Else
nTemplatePath = sTemplatePath & "\" & A2HTemplateName 'Format par défaut si le fond de plan present n'est pas dans la liste ci-dessus
boolstatus = swModel.Extension.LoadDraftingStandard("W:\Modeles_solidworks\Normes_de_mise_en_plans\ISO-REVTECH_A2.sldstd")
End Select
'On Supprime le fond de plan initial
swModel.SetupSheet5 swSheet.GetName, swDwgPapersUserDefined, swDwgTemplateNone, vSheetProps(2), vSheetProps(3), vSheetProps(4), "", vSheetProps(5), vSheetProps(6), "Default", True
'On Recharge le nouveau fond de plan
swModel.SetupSheet5 swSheet.GetName, swDwgPapersUserDefined, swDwgTemplateCustom, vSheetProps(2), vSheetProps(3), vSheetProps(4), nTemplatePath, vSheetProps(5), vSheetProps(6), "Default", True
swModel.ViewZoomtofit2
End Sub
Be careful to replace all the locations of the name and drawing files...
For the second part of this macro, I use format comparisons to determine
which "basemap" and MEP standard to use.
Kind regards.