macro to change sheet formats

I have a series of drawings which need to be released to the factory
on a standard company title block, and also published to a spare parts
manual on a spare parts specific title block. The drawings are exactly
the same in both instances, except for the title block. I have tried
to create a macro to do this for me, however I am not having much
luck. I begin recording the macro and do the following steps:
1. right-click in a blank area in the drawing sheet
2. select 'Properties' from the menu
3. select alternative sheet format
4. click 'OK' to accept the change
5. stop recording
When i go to run the macro i get a run-time 450 message, saying wrong
number of argument or invalid property assignment. Can anyone suggest
anything or any existing macros to do the same thing? Any help would
be much appreciated
Reply to
Loading thread data ...
This is beyond the Recorder's abilities. However, can you post what you do have?
Matt Lorono
formatting link
Reply to
Hi Matt, thanks for the reply. i thought it would have been too complex for the recorder to handle, but thought i'd give it a go. I am basically a beginner to VBA. The code i got when i recorded the macro is as follows:
' ****************************************************************************** ' C:\DOCUME~1\robryan\LOCALS~1\Temp\swx2688\Macro1.swb - macro recorded on 07/23/07 by robryan ' ****************************************************************************** Dim swApp As Object Dim Part As Object Dim SelMgr As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim Feature As Object Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc Set SelMgr = Part.SelectionManager boolstatus = Part.Extension.SelectByID2("Model", "SHEET", 0.05811514508374, 0.05515442212416, 0, False, 0, Nothing, 0) Part.ClearSelection2 True Part.SetupSheet4 "Model", 12, 12, 1, 10, False, "A4 - SPARE.slddrt", 0.21, 0.297, "Default", True End Sub
Reply to
One of my coworkers made a similar macro. I don't have it with me, but I remember he had an issues with it. When you record the macro, the call setting the sheet format has an extra argument that won't play back. It's the argument telling the sheet format to be visible, the last argument in the call. If you delete that one, then the macro will run, but it will have the sheet format turned off. You'll need to add an extra command to turn the sheet format back on.
Reply to
Hello Ross
Go to
formatting link
is the Stefan Berlitz site and the macro does just what you want. Its in german but thats okay...
Reply to
Hi Eman, thanks for the link. It sounds like that would be ideal if i were able to get it working properly, however i have a very limited experience with macros. i thought i followed the instructions fairly well, but still had an error message come up. i keep getting msgtext(3) appear "***ERROR: Can't set new sheetformat. Sheetformat file exists?" i changed the path and also added in the sheetformat names that currently exist. am a bit lost. attached is the code:
' *
********************************************************************* ' * PLEASE change the path/filename for the sheet templates (see below) ' ********************************************************************** ' * Macro changes the sheetformat (=3D 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 -
formatting link
' * ' * 17.12.2003 Stefan Berlitz ' * SolidWorks Solution Partner ' *
formatting link
' *
formatting link
' * ' **********************************************************************
Dim msgtext(6) As String ' some texts for multi-language support
Sub main()
Dim sheetformatpath(12) As String Dim sheetformatdir As String
' choose active language CheckLanguage
' *
*********** 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") =3D vbOK Then End
' Path to directory with sheetformats sheetformatdir =3D "U:\SOLIDWORKS\SOLIDWORKS ADMIN\TEREX-Templates"
' path to the various sheet formats from A to A0, you may also use ' full pathnames, but if they are all in the same subdir it's easier this way sheetformatpath(0) =3D sheetformatdir & "A4 - TEREX.slddrt" sheetformatpath(1) =3D sheetformatdir & "A4 - SPARE.slddrt" sheetformatpath(2) =3D sheetformatdir & "A3 - TEREX.slddrt" 'sheetformatpath(3) =3D sheetformatdir & "temp_c.slddrt" 'sheetformatpath(4) =3D sheetformatdir & "temp_d.slddrt" 'sheetformatpath(5) =3D sheetformatdir & "temp_e.slddrt" 'sheetformatpath(6) =3D sheetformatdir & "temp_a4.slddrt" 'sheetformatpath(7) =3D sheetformatdir & "temp_a4v.slddrt" 'sheetformatpath(8) =3D sheetformatdir & "temp_a3.slddrt" 'sheetformatpath(9) =3D sheetformatdir & "temp_a2.slddrt" 'sheetformatpath(10) =3D sheetformatdir & "temp_a1.slddrt" 'sheetformatpath(11) =3D sheetformatdir & "temp_a0.slddrt" ' already user defined sheetformatpath(12) =3D sheetformatdir & "A4 - BLANK.slddrt"
' *
************************ EDIT END *******************************
' zun=E4chst mal ein paar Deklarartionen die gebraucht werden 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 AnzahlBl As Long Dim SheetNames As Variant Dim SheetProperties As Variant
Const swDocDRAWING =3D 3 Const swDwgTemplateCustom =3D 12 Const swDwgTemplateNone =3D 13
' attach to SolidWorks Set SwApp =3D CreateObject("SldWorks.Application")
Set DrawingDoc =3D SwApp.ActiveDoc
If DrawingDoc Is Nothing Then ' check if document is open MsgBox msgtext(0) Exit Sub End If
If (DrawingDoc.GetType swDocDRAWING) Then ' check if document is a drawing MsgBox msgtext(1) Exit Sub End If
' get sheet count and traverse all sheets to reload sheetformat ' AnzahlBl =3D DrawingDoc.GetSheetCount SheetNames =3D DrawingDoc.GetSheetNames
' reset error messages msgtxt =3D ""
For i =3D 0 To AnzahlBl - 1 ' activate next sheet If DrawingDoc.ActivateSheet(SheetNames(i)) Then ' attach to sheet object Set Sheet =3D DrawingDoc.GetCurrentSheet SheetProperties =3D 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 =3D Sheet.GetName paperSize =3D SheetProperties(0) ' set NO SHEETFORMAT templateIn =3D swDwgTemplateNone scale1 =3D SheetProperties(2) scale2 =3D SheetProperties(3) firstAngle =3D CBool(SheetProperties(4)) ' no sheetformat =3D no path templateName =3D "" ' but we need the sheet size Width =3D SheetProperties(5) Height =3D SheetProperties(6) propertyViewName =3D Sheet.CustomPropertyView
retval =3D DrawingDoc.SetupSheet4( _ Name, _ paperSize, _ templateIn, _ scale1, _ scale2, _ firstAngle, _ templateName, _ Width, _ Height, _ propertyViewName) If retval =3D False Then msgtxt =3D msgtxt & msgtext(2) & vbCrLf Else
' and now we set the new sheetformat; it is necessary to set ' USER DEFINED sheetformat for SolidWorks will look for the ' standard templates temp_??.slddrt in your spefified folder ' if using the standard sheet sizes. templateIn =3D swDwgTemplateCustom
' get correct sheetformat for this size depending on the ' papersize, this will allow aleady userdefined sheetformats ' to properly be reloaded paperSize =3D GetSheetSizeFromPaperSize(Width, Height) templateName =3D sheetformatpath(paperSize)
retval =3D DrawingDoc.SetupSheet4( _ Name, _ paperSize, _ templateIn, _ scale1, _ scale2, _ firstAngle, _ templateName, _ Width, _ Height, _ propertyViewName) If retval =3D False Then ' ERROR : can't load new sheetformat msgtxt =3D msgtxt & msgtext(3) & 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 msgtxt =3D msgtxt & msgtext(5) & vbCrLf End If
End If
End If Else msgtxt =3D msgtxt & msgtext(4) & Name & vbCrLf End If Next i
' und noch die Zusammenfassung =FCbers Speichern ausgeben If Len(msgtxt) Then MsgBox msgtxt End If
End Sub
Private Sub CheckLanguage()
' check which language to apply. To make another language ' copy one of the CASE fileds and make your changes '
Set SwApp =3D CreateObject("SldWorks.Application") ' set by Sub main() Select Case SwApp.GetCurrentLanguage Case "german" msgtext(0) =3D "Kein Dokument offen, was sollte ich denn wohl tun?" msgtext(1) =3D "Nur sinnvoll bei Zeichnungen" msgtext(2) =3D "*
** FEHLER: konnte Blatt nicht zur=FCcksetzen " msgtext(3) =3D "*** FEHLER: konnte Blatt nicht auf neuen Vordruck setzen. Vordruck vorhanden? " msgtext(4) =3D "*** FEHLER: konnte Blatt nicht aktivieren " msgtext(5) =3D "*** FEHLER: konnte Dokument nicht speichern " msgtext(6) =3D "Bitte erst das Makro anpassen, dazu auf Extras/ Makros/Editieren klicken" ' Case "english" ' english is default, so change there ' Case "spanish" ' Case "french" ' Case "italian" ' Case "japanese" Case Else ' english is default msgtext(0) =3D "Nothing opened, so what should I look at?" msgtext(1) =3D "Only useful with drawing" msgtext(2) =3D "*** ERROR: can't reset sheet " msgtext(3) =3D "*** ERROR: can't set new sheetformat for drawing. Sheetformat file exists? " msgtext(4) =3D "*** ERROR: cant activate sheet " msgtext(5) =3D "*** ERROR: cant save document " msgtext(6) =3D "Please edit macro first (Extras/Macros/Edit)" End Select
End Sub
Function GetSheetSizeFromPaperSize(SheetWidth, SheetHeight) ' Function returns the SheetSize constant based on the width and heigth ' useful for userdefined sheetformats
Const swDwgPaperAsize =3D 0 Const swDwgPaperAsizeVertical =3D 1 Const swDwgPaperBsize =3D 2 Const swDwgPaperCsize =3D 3 Const swDwgPaperDsize =3D 4 Const swDwgPaperEsize =3D 5 Const swDwgPaperA4size =3D 6 Const swDwgPaperA4sizeVertical =3D 7 Const swDwgPaperA3size =3D 8 Const swDwgPaperA2size =3D 9 Const swDwgPaperA1size =3D 10 Const swDwgPaperA0size =3D 11 Const swDwgPapersUserDefined =3D 12
If (Round(SheetWidth, 4) =3D 0.2794) And (Round(SheetHeight, 4) =3D 0=2E2159) Then GetSheetSizeFromPaperSize =3D swDwgPaperAsize ElseIf (Round(SheetWidth, 4) =3D 0.2159) And (Round(SheetHeight, 4) =3D 0.2794) Then GetSheetSizeFromPaperSize =3D swDwgPaperAsizeVertical ElseIf (Round(SheetWidth, 4) =3D 0.4318) And (Round(SheetHeight, 4) =3D 0.2794) Then GetSheetSizeFromPaperSize =3D swDwgPaperBsize ElseIf (Round(SheetWidth, 4) =3D 0.5588) And (Round(SheetHeight, 4) =3D 0.4318) Then GetSheetSizeFromPaperSize =3D swDwgPaperCsize ElseIf (Round(SheetWidth, 4) =3D 0.8636) And (Round(SheetHeight, 4) =3D 0.5588) Then GetSheetSizeFromPaperSize =3D swDwgPaperDsize ElseIf (Round(SheetWidth, 4) =3D 1.1176) And (Round(SheetHeight, 4) =3D 0.8636) Then GetSheetSizeFromPaperSize =3D swDwgPaperEsize ElseIf (Round(SheetWidth, 4) =3D 0.297) And (Round(SheetHeight, 4) =3D 0=2E21) Then GetSheetSizeFromPaperSize =3D swDwgPaperA4size ElseIf (Round(SheetWidth, 4) =3D 0.21) And (Round(SheetHeight, 4) =3D 0=2E297) Then GetSheetSizeFromPaperSize =3D swDwgPaperA4sizeVertical ElseIf (Round(SheetWidth, 4) =3D 0.42) And (Round(SheetHeight, 4) =3D 0=2E297) Then GetSheetSizeFromPaperSize =3D swDwgPaperA3size ElseIf (Round(SheetWidth, 4) =3D 0.594) And (Round(SheetHeight, 4) =3D 0=2E42) Then GetSheetSizeFromPaperSize =3D swDwgPaperA2size ElseIf (Round(SheetWidth, 4) =3D 0.841) And (Round(SheetHeight, 4) =3D 0=2E594) Then GetSheetSizeFromPaperSize =3D swDwgPaperA1size ElseIf (Round(SheetWidth, 4) =3D 1.189) And (Round(SheetHeight, 4) =3D 0=2E841) Then GetSheetSizeFromPaperSize =3D swDwgPaperA0size Else GetSheetSizeFromPaperSize =3D swDwgPapersUserDefined End If
End Function
any ideas?
Reply to
What about putting a border that has 2 levels on it. One would be for the shop border and the other level would be for the manual border.
Reply to

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.