Sheet Format - Macro Question

Here is a macro question

I downloaded a macro that will change the sheet format in a given folder.  it works amazingly.  The only problem I am having with it is it will result in a default scale of 1:1 and it will not change the sheet format on other sheets of a document, only the current one. 

I have posted the code below. 

<p><span style="font-family: calibri, verdana, arial, sans-serif;">' Change_Sheet_Format.swp ---------------------------------08/10/09</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">' Original Code taken from Zoom and Rebuild macro</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">' Author: Luke Malpass, Paul Kellner 2004 (super rebuild), Pete Farnham</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">' Website: <a href="http://www.angelsix.com" data-community-id="1">http://www.angelsix.com</a></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">' Prerequisites: Set the directories having drawings you wish to run the</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">' change sheet format, set the new sheet format location and sheet format name</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">'</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">' Macro will find all the drawing files in the specified folder/location and</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">' replace the existing sheet format with the new one. Might delete everything contained</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">' within the format.</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">' ------------------------------------------------------------------------------</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">' Written by: Deepak Gupta (<a href="http://gupta9665.wordpress.com/" data-community-id="1">http://gupta9665.wordpress.com/</a>)</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">' ------------------------------------------------------------------------------</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">Option Explicit</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">Dim swApp As SldWorks.SldWorks</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim swModel As ModelDoc2</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim swFilename As String</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim swDraw As SldWorks.DrawingDoc</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim swSheet As SldWorks.Sheet</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim bRet As Boolean</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim sPath As String</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim nErrors As Long</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim nWarnings As Long</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim Response As String</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Dim DocName As String</span><br><span style="font-family: calibri, verdana, arial, sans-serif; color: #3366ff;">' Change sheet format location here<br></span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Public Const sTemplatePath As String = "<span style="color: #00ff00;">C:\\Jobs 2010\\Template\\</span>"</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;"><br> Sub main()<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">Set swApp = Application.SldWorks<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;"><span style="color: #3366ff;">' Change folder location containing the drawings to be updated here</span><br></span><br><span style="font-family: calibri, verdana, arial, sans-serif;">SheetFormat "<span style="color: #00ff00;">C:\\Jobs 2010\\Job # 11068\\06  REAR  Bowl Feeder\\</span>", ".SLDDRW", True<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">End Sub<br><br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">Sub SheetFormat(folder As String, ext As String, silent As Boolean)<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">Dim swDocTypeLong As Long<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">ext = UCase\\\$(ext)</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">swDocTypeLong = Switch(ext = ".SLDDRW", swDocDRAWING, True, -1)<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">'If not a SW file, return</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">If swDocTypeLong = -1 Then</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Exit Sub</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">End If<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">ChDir (folder)<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">Response = Dir(folder)</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Do Until Response = ""<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">swFilename = folder & Response<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">If Right(UCase\\\$(Response), 7) = ext Then</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  </span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  Set swModel = swApp.OpenDoc6(swFilename, swDocTypeLong, swOpenDocOptions_Silent, "", nErrors, nWarnings)</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  </span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  If swDocTypeLong = swDocDRAWING Then</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">   </span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Set swDraw = swModel</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">    Set swSheet = swDraw.GetCurrentSheet</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">     </span><br><span style="font-family: calibri, verdana, arial, sans-serif;"><span style="color: #3366ff;">' Change Sheet format name here which you to put on the drawing sheet.</span><br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">sPath = sTemplatePath & "<span style="color: #00ff00;">RPP DRAWING.SLDDRT</span>"<br></span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">bRet = swDraw.SetupSheet4(swSheet.GetName, swDwgPaperAsize, swDwgTemplateCustom, <span style="color: #ff0000;">1, 1,</span> False, sPath, 0.2794, 0.2159, "Default")</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">     </span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  End If</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  </span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  swModel.ViewZoomtofit2</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  </span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  swModel.ForceRebuild3 False</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  </span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  swModel.Save2 silent</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  </span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  swApp.CloseDoc swModel.GetTitle</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">  </span><br><span style="font-family: calibri, verdana, arial, sans-serif;">End If</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">Response = Dir</span><br><span style="font-family: calibri, verdana, arial, sans-serif;">Loop</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">MsgBox "Drawing(s) Sheet Fomat Updated!!"</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;">End Sub</span></p><p><span style="font-family: calibri, verdana, arial, sans-serif;"> </span></p>

Highlighted in green is the parameters that one would change  folder of template, folder to update drawings, and template name.  Whats in red is what I beleive makes the new scale 1:1

I was hoping to find out if

1: there is a way to have the scale the same as the original drawing after updating template, and

2: (not necessary) have this macro update drawings with multiple sheets

This macro is the work of

Deepak Gupta (http://gupta9665.wordpress.com/)

Any help would be much appreciated! 

Thank you

SolidworksDrawings And Detailing
Answers 10
DG
DG 2011-09-23 Best Answer

Welcome to SolidWorks forums Roman.

You can edit the macro to get the scale for the sheet and then add codes for using those values (instead of 1:1) while it changes the sheet format. Also you can add the codes for going thru multiple sheets.

You might also find this post helpful for your future reference

SF
SF 2011-09-28

do you have an idea of what code i would use?  i tried finding some sample code online without any luck.  Im not the most advanced when it comes to coding.  i beleive i came across a get sheet format code at one point but couldnt understand it.

any help would be appreciated.  thank you

SF
SF 2011-09-28

i was tinkering a bit and this is what I came up with

<p>' Change_Sheet_Format.swp ---------------------------------08/10/09</p><p>' Original Code taken from Zoom and Rebuild macro<br>' Author: Luke Malpass, Paul Kellner 2004 (super rebuild), Pete Farnham<br>' Website: <a href="http://www.angelsix.com" data-community-id="1">http://www.angelsix.com</a></p><p>' Prerequisites: Set the directories having drawings you wish to run the<br>' change sheet format, set the new sheet format location and sheet format name<br>'<br>' Macro will find all the drawing files in the specified folder/location and<br>' replace the existing sheet format with the new one. Might delete everything contained<br>' within the format.</p><p>' ------------------------------------------------------------------------------<br>' Written by: Deepak Gupta (<a href="http://gupta9665.wordpress.com/" data-community-id="1">http://gupta9665.wordpress.com/</a>)<br>' ------------------------------------------------------------------------------</p><p>Option Explicit</p><p>Dim swApp As SldWorks.SldWorks<br>Dim swModel As ModelDoc2<br>Dim swFilename As String<br>Dim swDraw As SldWorks.DrawingDoc<br>Dim swSheet As SldWorks.Sheet<br>Dim bRet As Boolean<br>Dim sPath As String<br>Dim nErrors As Long<br>Dim nWarnings As Long<br>Dim Response As String<br>Dim DocName As String<br>Dim X As Double<br>Dim Y As Double</p><p>' Change sheet format location here<br>Public Const sTemplatePath As String = "C:\Jobs 2010\Template\"</p><p>Sub main()</p><p>Set swApp = Application.SldWorks</p><p>' Change folder location containing the drawings to be updated here<br>SheetFormat "C:\Documents and Settings\Design2\Desktop\TEST\", ".SLDDRW", True</p><p>End Sub<br><br><br></p><p>Sub SheetFormat(folder As String, ext As String, silent As Boolean)</p><p>Dim swDocTypeLong As Long<br><strong>Dim vSheetProps As Variant</strong></p><p>ext = UCase$(ext)<br>swDocTypeLong = Switch(ext = ".SLDDRW", swDocDRAWING, True, -1)</p><p>'If not a SW file, return<br>If swDocTypeLong = -1 Then<br>Exit Sub<br>End If</p><p>ChDir (folder)</p><p>Response = Dir(folder)<br>Do Until Response = ""</p><p>swFilename = folder & Response</p><p>If Right(UCase$(Response), 7) = ext Then<br>  <br>  Set swModel = swApp.OpenDoc6(swFilename, swDocTypeLong, swOpenDocOptions_Silent, "", nErrors, nWarnings)<br>  <br>  If swDocTypeLong = swDocDRAWING Then<br>  <br>   <br>Set swDraw = swModel</p><p>    Set swSheet = swDraw.GetCurrentSheet<br>    <br><strong>vSheetProps = swSheet.GetProperties</strong></p><p>' Change Sheet format name here which you to put on the drawing sheet.</p><p><br>sPath = sTemplatePath & "RPP DRAWING.SLDDRT"</p><p>bRet = swDraw.SetupSheet4(swSheet.GetName, swDwgPaperAsize, swDwgTemplateCustom, <strong>vSheetProps(2), vSheetProps(3), </strong>False, sPath, 0.2794, 0.2159, "Default")</p><p>     <br>  End If<br>  <br>  swModel.ViewZoomtofit2<br>  <br>  swModel.ForceRebuild3 False<br>  <br>  swModel.Save2 silent<br>  <br>  swApp.CloseDoc swModel.GetTitle<br>  <br>End If</p><p>Response = Dir<br>Loop</p><p>MsgBox "Drawing(s) Sheet Fomat Updated!!"</p><p>End Sub</p>

It now runs but now the sheet format does not change and scale doesnt change (which is what I want) but am not sure if it actually works.  but it doesnt change to 1, 1,

in bold is what was added to the code

vSheetProps = swSheet.GetProperties

Scale 1 is brought up by vSheetProps(2)

Scale2 is brought up by vSheetProps(3)

any help would be appreciated

DG
DG 2011-09-28

You need to define the properties before calling them in the code.

Add these line and check

<p class="apiCode" style="font-family: 'Courier New', monospace; font-size: 10pt;">' Current sheet properties</p><p class="apiCode" style="font-family: 'Courier New', monospace; font-size: 10pt;">    Debug.Print "  Scale1                    = " & vSheetProps(2)</p><p class="apiCode" style="font-family: 'Courier New', monospace; font-size: 10pt;">    Debug.Print "  scale2                    = " & vSheetProps(3)</p>

below the line

<p class="apiCode" style="font-family: 'Courier New', monospace; font-size: 10pt;">vSheetProperties = swSheet.<span style="font-weight: bold;">GetProperties</span></p>
SF
SF 2011-09-29

GOT IT!

<p>' Change_Sheet_Format.swp ---------------------------------08/10/09</p><p>' Original Code taken from Zoom and Rebuild macro<br>' Author: Luke Malpass, Paul Kellner 2004 (super rebuild), Pete Farnham<br>' Website: <a href="http://www.angelsix.com" data-community-id="1">http://www.angelsix.com</a></p><p>' Prerequisites: Set the directories having drawings you wish to run the<br>' change sheet format, set the new sheet format location and sheet format name<br>'<br>' Macro will find all the drawing files in the specified folder/location and<br>' replace the existing sheet format with the new one. Might delete everything contained<br>' within the format.</p><p>' ------------------------------------------------------------------------------<br>' Written by: Deepak Gupta (<a href="http://gupta9665.wordpress.com/" data-community-id="1">http://gupta9665.wordpress.com/</a>)<br>' ------------------------------------------------------------------------------</p><p>Option Explicit</p><p>Dim swApp As SldWorks.SldWorks<br>Dim swModel As ModelDoc2<br>Dim swFilename As String<br>Dim swDraw As SldWorks.DrawingDoc<br>Dim swSheet As SldWorks.Sheet<br>Dim bRet As Boolean<br>Dim sPath As String<br>Dim nErrors As Long<br>Dim nWarnings As Long<br>Dim Response As String<br>Dim DocName As String</p><p><br>' Change sheet format location here<br>Public Const sTemplatePath As String = "C:\Jobs 2010\Template\"</p><p>Sub main()</p><p>Set swApp = Application.SldWorks</p><p>' Change folder location containing the drawings to be updated here<br>SheetFormat "C:\Documents and Settings\Design2\Desktop\TEST\", ".SLDDRW", True</p><p>End Sub</p><p>Sub SheetFormat(folder As String, ext As String, silent As Boolean)</p><p>Dim swDocTypeLong As Long<br><strong>Dim vSheetProps As Variant</strong></p><p><br>ext = UCase$(ext)<br>swDocTypeLong = Switch(ext = ".SLDDRW", swDocDRAWING, True, -1)</p><p>'If not a SW file, return<br>If swDocTypeLong = -1 Then<br>Exit Sub<br>End If</p><p>ChDir (folder)</p><p>Response = Dir(folder)<br>Do Until Response = ""</p><p>swFilename = folder & Response</p><p>If Right(UCase$(Response), 7) = ext Then<br>  <br>  Set swModel = swApp.OpenDoc6(swFilename, swDocTypeLong, swOpenDocOptions_Silent, "", nErrors, nWarnings)<br>  <br>  If swDocTypeLong = swDocDRAWING Then<br>  </p><p>    <br>Set swDraw = swModel<br>    Set swSheet = swDraw.GetCurrentSheet</p><p><strong>vSheetProps = swSheet.GetProperties</strong></p><p><br><br>' Change Sheet format name here which you to put on the drawing sheet.</p><p>sPath = sTemplatePath & "RP PRODUCTS.SLDDRT"</p><p>bRet = swDraw.SetupSheet4(swSheet.GetName, swDwgPaperAsize, swDwgTemplateCustom, <strong>vSheetProps(2), vSheetProps(3),</strong> False, sPath, 0.2794, 0.2159, "Default")</p><p>     <br>  End If<br>  <br>  swModel.ViewZoomtofit2<br>  <br>  swModel.ForceRebuild3 False<br>  <br>  swModel.Save2 silent<br>  <br>  swApp.CloseDoc swModel.GetTitle<br>  <br>End If</p><p>Response = Dir<br>Loop</p><p>MsgBox "Drawing(s) Sheet Fomat Updated!!"</p><p>End Sub</p><p></p><p class="apiCode"></p>

WORKS GREAT,

Added too much the first time, or messed something up.  What you just added was to display the scale, or print to screen or something. 

What I did before seems to be right by defining

<p><strong>Dim vSheetProps As Variant</strong></p>

and adding

<p><strong>vSheetProps = swSheet.GetProperties</strong></p><p> </p><p>bRet = swDraw.SetupSheet4(swSheet.GetName, swDwgPaperAsize, swDwgTemplateCustom, <strong>vSheetProps(2), vSheetProps(3),</strong> False, sPath, 0.2794, 0.2159, "Default")</p>

I think I messed something up before, but works now .  Now to get it to scan multiple sheets, but that can wait

CHEERS

DG
DG 2011-09-29

You can add codes to traverse thru all the sheets

SF
SF 2011-10-18

Any advice on how to do this on files in an EPDM vault?

DG
DG 2011-10-18

In case you looking to update multi sheet format drawing, check the macro here:

https://forum.solidworks.com/message/138211#138211

https://forum.solidworks.com/message/253495#253495

DG
DG 2011-10-18

The only way I know is to access the folder directly else check them out and update.

There are few tools available but not sure if they work with EPDM.

SK
SK 2024-09-16

@DG Hello Sir,
Thank you for this macro.
What shall I need to edit if I need to change only slddrt file instead of size and view scale?
I mean I need to run macro on a specific folder with browse function and need to change slddrt file.
I went through this post as well.
Thank you.