AnsweredAssumed Answered

Record a macro that works on "all" drawings..

Question asked by Stig Morten Thu on Aug 26, 2016
Latest reply on Aug 27, 2016 by Ivana Kolin

Hi.

 

First of all - I'm NOT a macro/VBA programmer, so my knowledge on the theme is very limited, but I've created "macros" for AutoCAD back in the days and I've made some macros/actions for Photoshop lately. Now I was hoping that some of that knowledge and same methods could be used to create a macro that can reduce the number of clicks involved in the following scene. To give you some background information, I'll let you know what the plan is.

 

We're going to migrate a lot of the files currently present in our vault to TeamCenter during this autumn. Part of the process has been to go through the vault and extract the files that we need to bring along. All this is now done. In the process, we discovered that some files had been duplicated and renamed and so on, so a little bit of housekeeping needed to be done as well. To make sure all links and references are working the way they should, I'm currently opening all the drawings and assemblies to let SW tell me if it finds the files or not. When all references and links have been restored, I want to just hit a macro button and have the drawing/assembly saved and closed automatically. If the files weren't "read only", it wouldn't have been a problem to just hit save and close, but a whole bunch of the files are opened as read only, even though the read only check box in windows explorer properties dialogue box has been removed and I haven't been able to figure out how to forcefully make all the files in that folder NOT read only, so any tips on that are most welcome as well, but back to the macro...

 

The macro should work as follows:

1. Save the file.

2. If the file was read only when opened, I want it to hit OK when the warning pops up.

3. I want it to hit save when the save as dialogue box pops up (no name change)

4. I want it to say YES when prompted if I want to overwrite the existing file, which I do

5. When saved, I want the document to be closed.

 

I tried to record a macro and got the following result:

' ******************************************************************************
' C:\Users\stithu\AppData\Local\Temp\swx12368\Macro1.swb - macro recorded on 08/26/16 by stithu
' ******************************************************************************
Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _
Application.SldWorks

Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Part.ViewZoomtofit2
Part.ViewZoomtofit2
Set Part = Nothing
swApp.CloseDoc "4671309 - Sheet1"
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 180
myModelView.FrameTop = 180
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "4669118_Control - Sheet1", False, longstatus
Set Part = swApp.ActiveDoc
End Sub

 

Despite my lacking knowledge of VB, the above makes me think that this will only work for the file "4671309 - Sheet1" which was the one that was open when I recorded the macro. Is there any "easy" fix or way to create a macro that will work as described above? Any help will be greatly appreciated as it will save me

humongus amounts of time.

 

Best regards and wishes for a happy week-end for all of you.


Stig M. Thu

Outcomes