55 Replies Latest reply on Oct 30, 2018 3:44 PM by Ricky Graber

    Reload Sheet Format

    Jeffrey Tongco

      Hi Guys,

       

      I need a help regarding drawing sheet format.

      The situation is when I update my sheet format I want to update my drawings.

      So what I do is reload my drawings.

      The step are

      1. Right-click the sheet

      2. Select Properties.

      3. Click Reload

      3. Click OK.

       

      So it takes four (4) clicks to reload the drawing.

      It's fine if it is only one but what I have sometimes 7 drawings to update.

       

      I think macro will do the trick just one click of a button.

       

      Hope you have that kind of macro

       

      Thanks guys.

       

      Cheers,

        • Re: Reload Sheet Format
          Deepak Gupta

          Jeff,

           

          I don't think API has codes for the reload button yet. So the workaround is to set the sheet format to none and then switching back to same sheet format. I've not tested this method and not sure if this would delete notes, etc. from the sheet format.

           

          Please vote for SPRs #:330668

            • Re: Reload Sheet Format
              Jeffrey Tongco

              Deepak,

               

              Yeah I have that kind of process. I copied some codes.

              So I have 2 macro button.

              First macro setting the sheet format to none

              Second macro reloading my updated sheet format.

               

               

              Cheers,

                • Re: Reload Sheet Format
                  Deepak Gupta

                  Why don't you combine both of them OR share the codes/macro here and someone will help you out.

                    • Re: Reload Sheet Format
                      Jeffrey Tongco

                      this is the first code

                       

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

                      ' * PLEASE change the path/filename for the sheet templates (see below)

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

                      ' *

                      ' * Macro changes the sheetformat (= the "paper" of your drawing) for

                      ' * all sheets of the active drawing. You have to adjust the path and

                      ' * the file names to the new sheet formats. After successfully changing

                      ' * the sheetformat the drawing is saved with its current name.

                      ' * ATTENTION: you CAN'T change the drawing template, this is not

                      ' * possible. So with this macro you can't update document properties.

                      ' * All sheet formats will be "userdefinied" after updating with this

                      ' * macro. If you want to have the "standard" A-A0 formats and not

                      ' * userdefinied you have to change the macro accordingly or use its

                      ' * "compagnion" which reloads a standard sheettemplate

                      ' *

                      ' * This macro is intended to be used with PAC4SWX for batch reloading

                      ' * of sheetformats, in case you changed you sheetformat with a new

                      ' * company logo, new title block layout or similar. But it will also

                      ' * word if fired from the GUI (taskplaner not tested, but should work;

                      ' * but I would like to see you using PAC4SWX instead of taskplaner ;-))

                      ' *

                      ' * PAC4SWX - http://swtools.cad.de/prog_pac.htm

                      ' *

                      ' *

                      ' * 17.12.2003 Stefan Berlitz

                      ' * SolidWorks Solution Partner

                      ' *    http://swtools.cad.de

                      ' * Inoffizielle deutsche SolidWorks Hilfeseite

                      ' *    http://solidworks.cad.de

                      ' *

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

                      Sub ReloadSheetFormat()

                         

                          Dim sheetformatpath(12) As String

                          Dim sheetformatdir As String

                             

                          ' ************ EDIT path and file name HERE ************************

                         

                          ' After editing the sheetformats delete the next line or comment it

                          'If MsgBox(msgtext(6), vbOKOnly, "Please Edit Macro") = vbOK Then End

                         

                          ' Path to directory with sheetformats

                          sheetformatdir = "C:\ProgramData\SolidWorks\SolidWorks 2013\lang\english\sheetformat\New Template\"

                          ' path to the various sheet formats from A to A0, you may also use

                          ' full pathnames, but if they are all in teh same subdir it's easier this way

                          sheetformatpath(0) = sheetformatdir & "temp_A.slddrt"

                          sheetformatpath(1) = sheetformatdir & "temp_av.slddrt"

                          sheetformatpath(2) = sheetformatdir & "temp_B.slddrt"

                          sheetformatpath(3) = sheetformatdir & "temp_c.slddrt"

                          sheetformatpath(4) = sheetformatdir & "temp_d.slddrt"

                          sheetformatpath(5) = sheetformatdir & "temp_e.slddrt"

                          sheetformatpath(6) = sheetformatdir & "temp_a4.slddrt"

                          sheetformatpath(7) = sheetformatdir & "temp_a4v.slddrt"

                          sheetformatpath(8) = sheetformatdir & "temp_a3.slddrt"

                          sheetformatpath(9) = sheetformatdir & "temp_a2.slddrt"

                          sheetformatpath(10) = sheetformatdir & "temp_a1.slddrt"

                          sheetformatpath(11) = sheetformatdir & "temp_a0.slddrt"

                           ' already user defined

                          sheetformatpath(12) = sheetformatdir & "WS-A3.slddrt"

                          ' ************************* EDIT END *******************************

                       

                       

                          Dim swApp As Object

                          Dim DrawingDoc As Object

                          Dim Sheet As Object

                         

                          Dim Titel As String

                          Dim Datei As String

                          Dim temp As String

                          Dim pfad As String

                          Dim msgtxt As String

                         

                          Dim Name As String

                          Dim paperSize As Long

                          Dim templateIn As Long

                          Dim scale1 As Double

                          Dim scale2 As Double

                          Dim firstAngle As Boolean

                          Dim templateName As String

                          Dim Width As Double

                          Dim Height As Double

                          Dim propertyViewName As String

                          Dim i As Long

                          Dim MySheetCount As Long

                          Dim SheetNames As Variant

                          Dim SheetProperties As Variant

                         

                          Const swDocDRAWING = 3

                          Const swDwgTemplateCustom = 12

                          Const swDwgTemplateNone = 13

                         

                          ' attach to SolidWorks

                          Set swApp = CreateObject("SldWorks.Application")

                         

                          Set DrawingDoc = swApp.ActiveDoc

                          If DrawingDoc Is Nothing Then

                              ' check if document is open

                              MsgBox "No Drawing Open"

                              Exit Sub

                          End If

                         

                          If (DrawingDoc.GetType <> swDocDRAWING) Then

                              ' check if document is a drawing

                              MsgBox "No Drawing Open"

                              Exit Sub

                          End If

                       

                          ' get sheet count and traverse all sheets to reload sheetfromat

                          '

                          MySheetCount = DrawingDoc.GetSheetCount

                          SheetNames = DrawingDoc.GetSheetNames

                          ' reset error messages

                          msgtxt = ""

                         

                          For i = 0 To MySheetCount - 1

                              ' activate next sheet

                              If DrawingDoc.ActivateSheet(SheetNames(i)) Then

                                  ' attach to sheet object

                                  Set Sheet = DrawingDoc.GetCurrentSheet

                                  SheetProperties = Sheet.GetProperties

                                 

                                  ' first we have to set the sheet to use "no sheetformat", for SolidWorks

                                  ' wont reload a sheetformat if it is the same name as before

                                  Name = Sheet.GetName

                                  paperSize = SheetProperties(0)

                                  ' set NO SHEETFORMAT

                                  templateIn = swDwgTemplateNone

                                  scale1 = SheetProperties(2)

                                  scale2 = SheetProperties(3)

                                  firstAngle = CBool(SheetProperties(4))

                                  ' no sheetformat = no path

                                  templateName = ""

                                  ' but we need the sheet size

                                  Width = SheetProperties(5)

                                  Height = SheetProperties(6)

                                  propertyViewName = Sheet.CustomPropertyView

                                 

                                  retval = DrawingDoc.SetupSheet5( _

                                              Name, _

                                              paperSize, _

                                              templateIn, _

                                              scale1, _

                                              scale2, _

                                              firstAngle, _

                                              templateName, _

                                              Width, _

                                              Height, _

                                              propertyViewName, _

                                              True)

                                  If retval = False Then

                                      msgtxt = "Error" & vbCrLf

                                  Else

                                 

                                      ' and now we set the new sheetformat; it is necessary to set

                                      ' USER DEFINIED sheetformat for SolidWorks will look for the

                                      ' standard templates temp_??.slddrt in your spefified folder

                                      ' if using the standard sheet sizes.

                                      templateIn = swDwgTemplateCustom

                                     

                                      ' get correct sheetformat for this size depending on the

                                      ' papersize, this will allow aleady userdefined sheetformats

                                      ' to properly be reloaded

                                      paperSize = GetSheetSizeFromPaperSize(Width, Height)

                                      templateName = sheetformatpath(paperSize)

                                     

                                      retval = DrawingDoc.SetupSheet5( _

                                                  Name, _

                                                  paperSize, _

                                                  templateIn, _

                                                  scale1, _

                                                  scale2, _

                                                  firstAngle, _

                                                  templateName, _

                                                  Width, _

                                                  Height, _

                                                  propertyViewName, _

                                                  True)

                                      If retval = False Then

                                          ' ERROR : can't load new sheetformat

                                          msgtxt = "Can't Load" & templateName & vbCrLf

                                      Else

                                         

                                          ' everything worked fine, no message here for automation

                                         

                                          ' save the document without backup

                                          'If DrawingDoc.Save2(True) > 0 Then

                                              ' error saving file

                                              ' Fehler beim Speichern

                                           '   msgtxt = msgtxt & msgtext(5) & vbCrLf

                                          'End If

                                     

                                      End If

                                 

                                  End If

                              Else

                                  msgtxt = "Something" & Name & vbCrLf

                              End If

                          Next i

                         

                          'SetDraftingStandard

                          'SetCurrentLayer

                          'If Len(msgtxt) Then

                          '    MsgBox msgtxt

                          'End If

                          DrawingDoc.ViewZoomtofit2

                          DrawingDoc.ForceRebuild3 False

                      End Sub

                      Function GetSheetSizeFromPaperSize(SheetWidth, SheetHeight)

                          ' Function returns the SheetSize constant based on the width and heigth

                          ' useful for userdefined sheetformats

                        

                          Const swDwgPaperAsize = 0

                          Const swDwgPaperAsizeVertical = 1

                          Const swDwgPaperBsize = 2

                          Const swDwgPaperCsize = 3

                          Const swDwgPaperDsize = 4

                          Const swDwgPaperEsize = 5

                          Const swDwgPaperA4size = 6

                          Const swDwgPaperA4sizeVertical = 7

                          Const swDwgPaperA3size = 8

                          Const swDwgPaperA2size = 9

                          Const swDwgPaperA1size = 10

                          Const swDwgPaperA0size = 11

                          Const swDwgPapersUserDefined = 12

                         

                          If (Round(SheetWidth, 4) = 0.2794) And (Round(SheetHeight, 4) = 0.2159) Then

                              GetSheetSizeFromPaperSize = swDwgPaperAsize

                          ElseIf (Round(SheetWidth, 4) = 0.2159) And (Round(SheetHeight, 4) = 0.2794) Then

                              GetSheetSizeFromPaperSize = swDwgPaperAsizeVertical

                          ElseIf (Round(SheetWidth, 4) = 0.4318) And (Round(SheetHeight, 4) = 0.2794) Then

                              GetSheetSizeFromPaperSize = swDwgPaperBsize

                          ElseIf (Round(SheetWidth, 4) = 0.5588) And (Round(SheetHeight, 4) = 0.4318) Then

                              GetSheetSizeFromPaperSize = swDwgPaperCsize

                          ElseIf (Round(SheetWidth, 4) = 0.8636) And (Round(SheetHeight, 4) = 0.5588) Then

                              GetSheetSizeFromPaperSize = swDwgPaperDsize

                          ElseIf (Round(SheetWidth, 4) = 1.1176) And (Round(SheetHeight, 4) = 0.8636) Then

                              GetSheetSizeFromPaperSize = swDwgPaperEsize

                          ElseIf (Round(SheetWidth, 4) = 0.297) And (Round(SheetHeight, 4) = 0.21) Then

                              GetSheetSizeFromPaperSize = swDwgPaperA4size

                          ElseIf (Round(SheetWidth, 4) = 0.21) And (Round(SheetHeight, 4) = 0.297) Then

                              GetSheetSizeFromPaperSize = swDwgPaperA4sizeVertical

                          ElseIf (Round(SheetWidth, 4) = 0.42) And (Round(SheetHeight, 4) = 0.297) Then

                              GetSheetSizeFromPaperSize = swDwgPaperA3size

                          ElseIf (Round(SheetWidth, 4) = 0.594) And (Round(SheetHeight, 4) = 0.42) Then

                              GetSheetSizeFromPaperSize = swDwgPaperA2size

                          ElseIf (Round(SheetWidth, 4) = 0.841) And (Round(SheetHeight, 4) = 0.594) Then

                              GetSheetSizeFromPaperSize = swDwgPaperA1size

                          ElseIf (Round(SheetWidth, 4) = 1.189) And (Round(SheetHeight, 4) = 0.841) Then

                              GetSheetSizeFromPaperSize = swDwgPaperA0size

                          Else

                              GetSheetSizeFromPaperSize = swDwgPapersUserDefined

                          End If

                      End Function

                • Re: Reload Sheet Format
                  Patrick O'Hern

                  You probably just need to set the sheet properties using the existing values.  This should reload the new template (I haven't tested this theory though.)

                   

                  Check out this example from the help file: http://help.solidworks.com/2013/English/api/sldworksapi/Get_and_Set_Sheet_Properties_Example_VB.htm

                   

                  Take out these lines:

                  ' Switch projection property 

                      bFirstAng = vSheetProps(4)

                      vSheetProps(4) = Not bFirstAng

                   

                   

                  That should get the existing sheet properties, and then reapply them but with an updated template.

                  • Re: Reload Sheet Format
                    Peter Larsen

                    Thanks, Deepak! I know you are a busy man!

                    But I must say that there is something happening when using the macro. It does change the Region from Sheet to Margins.

                    When I update manually with same sheet format it does not change to Margins. Maybe it somehow resets that setting...?

                    However, it doesn´t matter - I can still use the macro as it currently is.

                     

                    Thanks again!

                    /Peter