Apply a document template to an old part or assembly

Hello

Is it possible to apply a document template to an older part or assembly?

Basically, I'd like to be able to update the document properties (option => Document properties => Wrapping standard, ...) and add all the custom properties to the template without deleting the old custom properties.

Thank you for your feedback

Hello
Natively this is not possible (you can at best add properties with the task scheduler).
By macro or maybe in the Visiativ tools (MyCadTool) I don't see any other solution.

2 Likes

Via Integration you should be able to do this.
For the standard:
image
For Properties:
image
Attached is the help of Integration, it is a paid Visiativ utility, but it is possible to test it for a month of memory.
Otherwise via macro it's feasible since the utility based on the solidworks API does it, but you'll have to look for the ready-made equivalent or write it, if nothing equivalent.

Edit: an example of a macro to change the Hgabillage:
https://help.solidworks.com/2022/english/api/sldworksapi/Change_Drafting_Standard_to_Custom_Example_VB.htm

3 Likes

Hello;
There is no simple solution on this subject...
However, and if it does not concern a large number of files, it is possible to use my solution discussed in the topic:


Hello;

For an Assembly, it is always possible to drag it into a document template *. SLDASM (new Assembly document), then decompose it (right-click) to return to its original FeatureTree.
image

… and save the new assembly.

For the parts it's slightly more complicated (but not that much).
Insert your component into a new document part (document template) as if you were making a derivative part, Check the " Break the link with the original part" option:


And (optionally) delete the directory created in the featureTree.
image
Then save.

Kind regards.

1 Like

It's ingenious as a technique, on the other hand for the parts seems to me that it's not as simple as you described, I imagine that any link to assembly or function in the context, child derivative part or drawing will be lost

1 Like

@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.

3 Likes