-
Re: Macro to change sheet format on one drawing
Nilesh Patel Dec 10, 2016 11:13 AM (in response to Gillean Gilhang)Hi Gillean,
Try attached.
1. Replace "Your_Template_Name" with the name (just name) with your template.
2. Replace "Path_of_Sheet_Template" with the full path of your sheet template.
3. You may also have to change few parameters in the line 'swDraw.SetupSheet5'.
Regards,
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 12, 2016 11:57 AM (in response to Nilesh Patel)Hi Nilesh, thanks for the macro. But after editing and running it, I get the error 'Object library feature not supported'
I am not very good with macros, so I am not too sure how to solve this error.
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 12, 2016 12:28 PM (in response to Gillean Gilhang)What version of SW are you running?
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 12, 2016 12:30 PM (in response to Christian Chu)I'm using SW 2016.
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 12, 2016 12:35 PM (in response to Gillean Gilhang)
-
-
-
Re: Macro to change sheet format on one drawing
Nilesh Patel Dec 12, 2016 4:49 PM (in response to Gillean Gilhang)Hi Gillean,
Copy the codes of the macro that I supplied into notepad. Start a new macro in SolidWorks, delete everything from that new macro and paste the codes from notepad to the new macro. Save the macro and run it. It should fix the problem.
"Your_Template_Name" and "Path_of_Sheet_Template" must be inside double quotes (").
Hope this helps.
Regards,
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 12, 2016 4:53 PM (in response to Nilesh Patel)Good idea ! it's much simple way than searching for the obj. lib. missing !
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 12, 2016 6:01 PM (in response to Nilesh Patel)Hi Nilesh, I did everything as you instructed. Running the macro didn't return any error message however, it didn't change the sheet format on my drawing. I made sure that the file name and path in the macro are correct, and I tried it in two different drawings. Still nothing.
-
Re: Macro to change sheet format on one drawing
Nilesh Patel Dec 13, 2016 12:22 AM (in response to Gillean Gilhang)Hi Gillean,
I tried it on my end and it worked OK before I posted the macro. Could you attach your macro (including template path and template name)?
Put a break point in a macro and run the macro line by line and see what happens. You will be able to figure out why it is not changing the sheet template.
Regards,
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 13, 2016 10:58 AM (in response to Nilesh Patel)Hi Nilesh, please find attached edited macro.
First run doesn't change the sheet format. Second run of the macro returns this error:
-
Re: Macro to change sheet format on one drawing
John Stoltzfus Dec 13, 2016 11:05 AM (in response to Gillean Gilhang)Are you in the Assembly file? - will only work when you have the drawing open
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 13, 2016 11:48 AM (in response to John Stoltzfus)Drawing file. I'm detailing an assembly.
-
-
-
-
-
-
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 13, 2016 12:10 PM (in response to Nilesh Patel)Deepak Gupta remotely ran this macro on my computer and with a little tweaking, it finally worked! Thank you all. I will now try to learn as much as I can about API/macros. Have a great day everyone!
-
Re: Macro to change sheet format on one drawing
Nilesh Patel Dec 13, 2016 4:11 PM (in response to Gillean Gilhang)Glad to hear that. If the end result is good, all is good.
-
-
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 10, 2016 2:00 PM (in response to Gillean Gilhang)Gillean
You want to change sheet format on all sheets or just on current sheet?
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 12, 2016 11:58 AM (in response to Christian Chu)I would like to change format of all sheets in a drawing
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 12, 2016 4:55 PM (in response to Gillean Gilhang)Just do one step of a time
Make sure the macro to run first !
-
-
-
Re: Macro to change sheet format on one drawing
John Stoltzfus Dec 12, 2016 7:21 AM (in response to Gillean Gilhang)I use this one every day and it works awesome, written by Deepak Gupta and edited by Garrett Hansen
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 12, 2016 12:02 PM (in response to John Stoltzfus)Hi John, thanks for the macro. But I'm not sure if I'm supposed to edit this first before running it? If so, I don't see any lines where I can specify the sheet format and/or file path. Please let me know how to proceed with this.
-
Re: Macro to change sheet format on one drawing
John Stoltzfus Dec 12, 2016 12:11 PM (in response to Gillean Gilhang)You should be able to just run it, it goes to the sheet and finds the path and reloads from there, no need to tell it where to go, it if doesn't run there may be properties that need changing..
When you edit the macro - go Tools, References and change what you need and run it, if it don't work then you'll need to contact Deepak Gupta as he might have an older version...
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 12, 2016 12:14 PM (in response to Gillean Gilhang)-
Re: Macro to change sheet format on one drawing
John Stoltzfus Dec 12, 2016 12:17 PM (in response to Christian Chu)-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 12, 2016 12:22 PM (in response to John Stoltzfus)The problem is I'm not sure if GIllean has a set of templates as you do
So just want to make sure it's pointed to correct template
-
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 12, 2016 12:19 PM (in response to Christian Chu)-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 12, 2016 12:29 PM (in response to Christian Chu)Hmm, I'm not sure it will work the way I want it to if I don't specify the sheet format and file path.
To clarify, we implemented a new sheet format / title block. So all of my drawings have an old format that I want to be able to change to the new one with a macro. If I don't specify the new format, I'm not sure how would it know which one I want to use? :/
-
Re: Macro to change sheet format on one drawing
John Stoltzfus Dec 12, 2016 12:38 PM (in response to Gillean Gilhang)-
Re: Macro to change sheet format on one drawing
Deepak Gupta Dec 12, 2016 12:50 PM (in response to John Stoltzfus)John, the macro is to reload same format with same name. In case there is a different name then you need to specify the new name along with path.
Christian, you can reload the same sheet format bu setting first to NONE (no sheet format) and then adding again. That is what that macro does.
Gillean If the sheet format name is same has same path then macro would work fine else you need ot set the path suggested in my post above.
-
Re: Macro to change sheet format on one drawing
John Stoltzfus Dec 12, 2016 1:03 PM (in response to Deepak Gupta)That's right - see my last post
-
-
Re: Macro to change sheet format on one drawing
Deepak Gupta Dec 12, 2016 1:14 PM (in response to John Stoltzfus)John Stoltzfus wrote:
Oh oh - That is a new issue totally, never save as a new format, unless you are prepared to change every sheet out one by one, right click the sheet, properties and select the new sheet.
Why not save as new sheet format name. You can easily change that by macro OR with 2017 in one click I guess (I've not checked/tried that yet)
-
Re: Macro to change sheet format on one drawing
John Stoltzfus Dec 12, 2016 1:34 PM (in response to Deepak Gupta)Actually it's not really an issue today, unless you don't have access to #Task or any macros.....
-
-
-
Re: Macro to change sheet format on one drawing
Deepak Gupta Dec 12, 2016 12:39 PM (in response to Gillean Gilhang)-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 12, 2016 12:44 PM (in response to Deepak Gupta)Also it's good idea to add revision to your template
Since even though you make change on template, but the name of your template is same as the one included in the drawing, then it won't be replaced
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 12, 2016 5:51 PM (in response to Deepak Gupta)Hi Deepak, thanks for your help. I did the necessary changes but it returned another error- "Can't find project or library."
I'm not sure if there's an error in the macro or if it's something in my computer system. I'm really not good with these things haha
-
Re: Macro to change sheet format on one drawing
Deepak Gupta Dec 12, 2016 11:06 PM (in response to Gillean Gilhang)I just tested it again and no errors message. And it worked as expected.
Can you share your screen over TeamViewer?
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 13, 2016 11:16 AM (in response to Deepak Gupta)Sure. I had just downloaded TeamViewer. Should I send you my ID #?
-
Re: Macro to change sheet format on one drawing
Deepak Gupta Dec 13, 2016 11:39 AM (in response to Gillean Gilhang)Sent you a PM.
-
-
-
-
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 12, 2016 12:51 PM (in response to Gillean Gilhang)-
Re: Macro to change sheet format on one drawing
Nilesh Patel Dec 12, 2016 4:53 PM (in response to Christian Chu)Hi Christian,
The line that you have marked and the one below changes the sheet template path (obtained by swSheet.GetTemplateName) to just sheet template name.
I have added the condition 'If sTemplateName <> "Your_Template_Name" Then' to make sure that if someone accidentally runs the macro in drawing document which already has new sheet format then nothing will happen.
Regards,
-
-
-
-
-
-
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 13, 2016 1:22 AM (in response to Gillean Gilhang)Gillean,
I think you're totally confused and go around a loop with few different macros provided here and we just jumped in the middle and guided you to different directions. I think you'd better stay with one simple macro and get it work first
Here is how it works:
1) Open a drawing, select sheet and right click and select properties ...
here is what you'll see
2) the sheet format in this dialog box is the one being used in the drawing. It might be the same or older the sheet format template. Assume it's older than the sheet format template, you can replace the sheet format being used by selecting a new sheet format template using the browser and reload the new template into your drawing.
Above steps are how to replace the sheet format manually. A macro is just combing all steps above into one
Here is the simple code from API help:
Do this: copy the sheet format path in your drawing and replace "C:\ProgramData\SolidWorks\SOLIDWORKS 2016\lang\english\sheetformat\b-landscape.slddrt" with your path and run this code:
'--------------------------------------------------------
' Preconditions:
' 1. Verify that the specified sheet format template exists.
' 2. Open install_dir\samples\tutorial\api\2012-sm.slddrw.
'
' Postconditions:
' 1. Changes the sheet format's paper size and template.
' 2. Examine the drawing.
'
' NOTE: Because the drawing is used elsewhere, do not save
' changes.
'--------------------------------------------------------
Option Explicit
Sub main()
Const sTemplatePath As String = "C:\ProgramData\SolidWorks\SOLIDWORKS 2016\lang\english\sheetformat\b-landscape.slddrt"
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet
Dim bRet As BooleanSet swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheetbRet = swDraw.SetupSheet4(swSheet.GetName, swDwgPaperBsize, swDwgTemplateBsize, 1#, 1#, False, "", 0#, 0#, "")
swModel.ForceRebuild3 (False)
End Sub
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 13, 2016 11:42 AM (in response to Christian Chu)You're right, I'm kind of getting confused now but I'm grateful for all the help.
But yes, I know how to manually change the sheet format. I recorded a macro to automate the process but what I want to have is a macro that will do the process on all sheets in a drawing.
I copied and ran your code with the changes, don't know why but it just messed up my drawings. (all views scale changed to 1:1, overlaid my title block with a different title block)
I do not want to change paper size, I essentially just want to change the title block of all sheets in a drawing.
-
Re: Macro to change sheet format on one drawing
Deepak Gupta Dec 13, 2016 11:44 AM (in response to Gillean Gilhang)Did you got mt PM?
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 13, 2016 11:55 AM (in response to Gillean Gilhang)Gillean,
I think you should start using API help from your SW software
search for setupsheet4 and here is the list of all parrameters used in this setupsheet4 function - go thru and change the parrameters in your macro then youd have a better understanding than using someone macro and guessing with trial and error and wish for the luck
Parameters
- Name
- Name for the sheet
- PaperSize
- Size of paper if using swDwgTemplateNone as defined in swDwgPaperSizes_e
- TemplateIn
- Template as defined in swDwgTemplates_e
- Scale1
- Scale numerator
- Scale2
- Scale denominator
- FirstAngle
- True for first angle projection, false otherwise
- TemplateName
- Name of custom template with full directory path if using swDwgTemplateCustom
- Width
- Paper width if TemplateIn is set to swDwgTemplateNone or swDwgPapersUserDefined
- Height
- Paper height if TemplateIn is set to swDwgTemplateNone or swDwgPapersUserDefined
- PropertyViewName
- Name of view containing the model from which to get custom property values
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 13, 2016 12:03 PM (in response to Christian Chu)By the way, it's up to you: want to learn API programming or just want a macro to run on your SW
1) want to learn API: My message might be helpful for you but it'd take more time
2) just want a macro: Pick the macro you like here and all gentlemen here can help you out
-
Re: Macro to change sheet format on one drawing
Deepak Gupta Dec 13, 2016 12:04 PM (in response to Christian Chu)It turned out that new sheet format name was not added int he path (as I've stated already) and that was causing the issue. All is good now
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 13, 2016 12:16 PM (in response to Christian Chu)Thanks for all the detailed replies, Christian!
Yes, I definitely intend to learn more about API and macros. I've only used Solidworks for a few months, but I'm hopeful to be as good as you all in the future. The problem has been resolved, thanks again to everyone!
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 13, 2016 12:21 PM (in response to Gillean Gilhang)Learning curve is a long process and will be lot of fun
-
Re: Macro to change sheet format on one drawing
Gillean Gilhang Dec 13, 2016 12:28 PM (in response to Christian Chu)Prepare to see more of my questions here, then! Haha
-
Re: Macro to change sheet format on one drawing
Christian Chu Dec 13, 2016 12:34 PM (in response to Gillean Gilhang)
-
-
-
Re: Macro to change sheet format on one drawing
JOY CHRISTIAN Jun 4, 2018 4:59 AM (in response to Gillean Gilhang)Hi Gillean,
Can you share the macro that finally worked for you? I am looking for the similar macro which can update sheet formats without changing scale. Is that single macro can work for multi sheet drawing with different sheet size formats?
Thanks
-
Re: Macro to change sheet format on one drawing
Deepak Gupta Jun 4, 2018 12:49 PM (in response to JOY CHRISTIAN)Joy, check/try the macro from this post Macro: Batch Reload-Replace Drawing Sheet Format (sub folders as well)
-
Re: Macro to change sheet format on one drawing
JOY CHRISTIAN Jun 5, 2018 10:09 AM (in response to Deepak Gupta)Hi Deepak,
I have downloaded a macro to runs in individual drawing from the post that you have suggested. I have changed sheet names and its location (Macro attached) and now it needs changing some parameters to reload the sheet format as some of my drawings has different sheet sizes, so could you please have a look and suggest the changes.
Also in each of our drawing we have BOM in final sheet which has custom property value linked to drawing view in sheet1, so is it possible to get that value same? or not to update the BOM sheet while running the macro? Here I have also attached a screen shot of BOM sheet properties.
Appreciate your help..
-
Re: Macro to change sheet format on one drawing
Deepak Gupta Jun 9, 2018 12:11 PM (in response to JOY CHRISTIAN)Joy, the macro from the post I've shared earlier (Batch Reload Drawing Sheet Format) has the codes to check each sheet size and then apply the format accordingly.
For second issue you can either use SetProperties Method (ISheet) OR find the view named used by that sheet and put that in the SetupSheet5 Method in place of "Default". Here is an example Find which view is bringing custom property values
-
-
-
-
-
-
-
Re: Macro to change sheet format on one drawing
Andreas Rhomberg Dec 13, 2016 4:48 PM (in response to Gillean Gilhang) -
Re: Macro to change sheet format on one drawing
Carrie Ives Jan 15, 2019 6:13 PM (in response to Gillean Gilhang)I was looking at this post today and was trying to understand the macro. It uses the API SetupSheet5. I wasn't clear on what that was doing until looking at the help. Here's a link to the help for that API:
2017 SOLIDWORKS API Help - SetupSheet5 Method (IDrawingDoc)
Thanks,
Carrie