Auto Increment Macro File Name

Hello

 

I have an assembly with 50 configurations, and I want to have an image of each configuration.

For this I created a macro that gives me:

 

______________________________________________________________________________________________

 

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim I As Integer
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
boolstatus = Part.Extension.SelectByID2("1@Assemblage1.SLDASM", "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)

 

For I = 1 To 50

 

boolstatus = Part.ShowConfiguration2(I)
boolstatus = Part.ForceRebuild3(True)
longstatus = Part.SaveAs3("C:\Users\michel2\Desktop\Macro\I.JPG", 0, 0)

 

Next I

 

End Sub

 

________________________________________________________________________________________________________

 

 

I created a loop with "For I = 1 to 50" and "Next I" with my steps in the middle:

Line 1 : Choosing the configuration

Line 2: Rebuild

line 3: save as JPG in the specified path

 

The problem I have when I launch my macro is that I can see my configurations scroll by, but in the end I only have an image of the last saved configuration (named I.JPG), The I does not increment in the file name (line 3) and so with each new save the I.JPG file is deleted and replaced by the new one.

 

 

Is there a way to automatically increment the file name? If anyone has an example of a macro...

 

Thank you in advance for your help.

 

 

Hello

 

You can look at the link below if macro is right for you. (or to be modified)

http://www.3dcontentcentral.fr/macros/184/files/macro.aspx?id=179396

 

S.B

1 Like

Hello!

I think you have to make a variable "File name + config name" and put it in the save as...

 

1 Like

Hello

 

Actually your "For I = 1 To 50" is correct, but you don't apply it to your filename!

 

 

The line must be replaced:

 

longstatus = Part.SaveAs3("C:\Users\michel2\Desktop\Macro\I.JPG", 0, 0)

 

By:

 

longstatus = Part.SaveAs3("C:\Users\michel2\Desktop\Macro\" & I & ".JPG", 0, 0)

 

And it works!

3 Likes

Thank you s.b your answer helped me but Lucas' is better.

Thank you Lucas, it works nikel, I had already done it yesterday but without the spaces to the & and it didn't work...

1 Like