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
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
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
i was tinkering a bit and this is what I came up with
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
You need to define the properties before calling them in the code.
Add these line and check
below the line
GOT IT!
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
and adding
I think I messed something up before, but works now . Now to get it to scan multiple sheets, but that can wait
CHEERS
You can add codes to traverse thru all the sheets
Any advice on how to do this on files in an EPDM vault?
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
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.
@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.