AnsweredAssumed Answered

Reload Multiple Templates in Multi-sheet drawing

Question asked by Garret Hansen on Mar 17, 2015
Latest reply on Jan 7, 2016 by Jackie Yip

I am working on a larger project in small pieces and this is the first part.

 

I have a macro that Deepak Gupta had been very helpful on.  I have been searching and can't quite find the answer and my stab at it is not working.

 

I have drawings that have multiple sheets and they don't always have the same template.  So what I want to do is instead of fixing the template to reload as is done here:

 

' Change Sheet format name here which you to put on the drawing sheet.

Const sTemplateName As String = "BV-ASSEMBLY-RDI-TBLK-in.slddrt"

 

I would like to get and set the template for each sheet with this code:

 

Set sTemplateName = swSheet.GetTemplateName

 

Then the rest of the code would be the same.  However I get a compile error on the GetTemplateName.

 

Below is the code that Deepak created and I have made some edits to.

'Reload Drawing Sheet Format.swp ------------- 06/05/14

 

 

'Description: Macro to Reload Drawing Files Sheet Format for all sheets.

 

 

'Pre-Condition: An active drawing document having the older sheet format.

 

 

'Post-Condition: Macro will set the sheet format to NONE and then relaod the same format from the specified location.

' Might delete everything contained within the old/exisitng format.

 

 

'Please back up your data before use and USE AT OWN RISK

 

 

' This macro is provided as is.  No claims, support, refund, safety net, or

' warranties are expressed or implied.  By using this macro and/or its code in

' any way whatsoever, the user and any entities which the user represents,

' agree to hold the authors free of any and all liability.  Free distribution

' and use of this code in other free works is welcome.  If any portion of

' this code is used in other works, credit to the authors must be placed in

' that work within a user viewable location (e.g., macro header).  All other

' forms of distribution (i.e., not free, fee for delivery, etc.) are prohibited

' without the expressed written consent by the authors.  Use at your own risk!

' ------------------------------------------------------------------------------

' Written by: Deepak Gupta (http://gupta9665.com/)

' -------------------------------------------------------------------------------

'Option Explicit

 

 

Sub main()

 

 

Dim swApp           As SldWorks.SldWorks

Dim swModel         As SldWorks.ModelDoc2

Dim swDraw          As SldWorks.DrawingDoc

Dim swSheet         As SldWorks.Sheet

Dim vSheetProps     As Variant

Dim vSheetName      As Variant

 

 

Dim longstatus      As Long

Dim longwarnings    As Long

Dim nErrors         As Long

Dim nWarnings       As Long

Dim i               As Long

 

 

Dim sFileName       As String

Dim Path            As String

Dim sTemplateName   As Variant

 

 

 

 

 

 

' Change sheet format location here

Const sTemplatePath As String = "C:\RDIVault\ENGINEERING\SW TEMPLATES\"

 

 

' Change Sheet format name here which you to put on the drawing sheet.

'Const sTemplateName As String = "BV-ASSEMBLY-RDI-TBLK-in.slddrt"

 

 

'***************************************

 

 

On Error Resume Next

 

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

 

 

' Check to see if a drawing is loaded.

If swModel Is Nothing Then

        MsgBox "There is no active drawing document"

        Exit Sub

End If

   

If swModel.GetType <> swDocDRAWING Then

        MsgBox "Open a drawing first and then TRY again!"

        Exit Sub

End If

 

 

Set swDraw = swModel

   

    vSheetName = swDraw.GetSheetNames

 

 

    ' Traverse the drawing sheets and update the format

    For i = 0 To UBound(vSheetName)

 

 

        swDraw.ActivateSheet vSheetName(i)

        Set swSheet = swDraw.GetCurrentSheet

       

        Set sTemplateName = swSheet.GetTemplateName

       

        vSheetProps = swSheet.GetProperties

   

    'Set the sheet format to NONE

    swModel.SetupSheet5 swSheet.GetName, swDwgPapersUserDefined, swDwgTemplateNone, vSheetProps(2), vSheetProps(3), False, "", 0.4318, 0.2794, "Default", True

   

    'Reload the sheet format from the speicifed location

    swModel.SetupSheet5 swSheet.GetName, swDwgPapersUserDefined, swDwgTemplateCustom, vSheetProps(2), vSheetProps(3), False, sTemplatePath & sTemplateName, 0.4318, 0.2794, "Default", True

    swDraw.ViewZoomtofit2

   

Next i

 

 

    swDraw.ActivateSheet vSheetName(0)

    swDraw.ForceRebuild3 False

    swDraw.Save3 1, nErrors, nWarnings

       

Set swDraw = Nothing

 

 

End Sub

Any help would be greatly appreciated.

Outcomes