Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Macro to change the template for multiple drawing files?

Status
Not open for further replies.

mkoonts

Mechanical
Apr 14, 2005
2
0
0
US
I have about 150 drawing files that need to be changed to have a new drawing template. Some of the drawings have multiple sheets.

Does anyone have a macro that will batch change all of the drawing files?
 
Replies continue below

Recommended for you

Thanks. Really I could change either the template or the sheet format. All of the custom properties needed are in the Parts/Assemblies. I just need to add and remove certain properties from the drawings for a customer.

Now, how would be the best way to go about applying this macro to all of the files without going through each one manually? I was thinking it could be done in the SolidWorks Task Scheduler, but I seem to be missing how to run it for certain folders?
 
Was anyone able to get this problem solved for an entire folder of drawings? I have somewhere around 1200 that need the sheet format changed.

Thanks,
Matt
 
Everything looked like it was specific to working with the currently open file. Which one did you have in mind?

I started a macro but am having trouble with the SetupSheet4 function.

-Matt
 
Thanks CBL!

I also want to learn, so if any VB/macro gurus can take a look at this and explain why I can't save the active document in my macro, I'd appreciate it. This is just meant to work - there's very little in the way of functionality or error handling.

-Matt

Code:
' ******************************************************************************
' chgfmt.swb - macro recorded on 08/11/08 by mdenardo
' ******************************************************************************
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
Dim MyDir As String
Dim MySheet As String
Dim MyFile As String

Sub main()

Set swApp = Application.SldWorks
MyDir = InputBox("Enter the path that contains the files you want to change.")
MySheet = InputBox("Enter the full path, including file name and extension of the sheet format you want to use.")
MyFile = Dir(MyDir & "\*.slddrw")

Do While MyFile <> ""
    MyFile = Dir()
    FileName = Split(MyFile, ".")
    Set Part = swApp.OpenDoc6(MyDir & "\" & MyFile, 3, 0, "", longstatus, longwarnings)
    swApp.OpenDoc6 MyDir & "\" & MyFile, 3, 0, "", longstatus, longwarnings
    Set Part = swApp.ActivateDoc2(FileName(0) & " - Sheet1", False, longstatus)
    swApp.ActiveDoc.ActiveView.FrameLeft = 0
    swApp.ActiveDoc.ActiveView.FrameTop = 0
    swApp.ActiveDoc.ActiveView.FrameState = 1
    swApp.ActiveDoc.ActiveView.FrameState = 1
    boolstatus = Part.Extension.SelectByID2("Sheet1", "SHEET", 0.1391084233669, 0.2266029916164, 0, False, 0, Nothing, 0)
    Part.ClearSelection2 True
    Part.SetupSheet4 "Sheet1", 12, 12, 1, 1, False, MySheet, 0.4318, 0.2794, "Default" ', True
    Part.ViewZoomtofit2
    retval1 = Part.Save3()
    Set Part = Nothing
    swApp.CloseDoc FileName(0) & " - Sheet1"
Loop
End Sub
 
Hm. Well, I solved it by changing that line to use the SaveAs method and gave it the same part name as the open part and that worked fine. No idea why Save3 didn't work.

Code:
retval = Part.SaveAs(MyDir & "\" & MyFile)
 
Status
Not open for further replies.
Back
Top