Save max file twice

Save max file twice

holycause
Contributor Contributor
616 Views
12 Replies
Message 1 of 13

Save max file twice

holycause
Contributor
Contributor
hi guys,

I've a question

I'm trying to create a script which can save my file in 2 different files at the same time.

I just started with it, but i've some problems.

this my code for now
rollout rollout01 "Save Clone" width:223 height:194
(
GroupBox grp1 "Save As" pos: width:206 height:130
button btn01 "File 01" pos: width:186 height:28
button btn02 "File 02" pos: width:186 height:28
button btn03 "Save" pos: width:186 height:28

on btn01 pressed do
(
save01 = getMAXSaveFileName ()
)


on btn02 pressed do
(
save02 = getMAXSaveFileName ()
)

on btn03 pressed do
(

)
)
createDialog rollout01



but it didn't save anything.... :-S

I tried with this code:

actionMan.executeAction 0 "40007"


but it save only one of the 2 files (the last i saved).

so I don't know how to keep in memory the file path for each button.

And when i press on the btn03 button, how can i save the 2 files at the same time????

thx in advance for your help 😉
0 Likes
617 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
You never defined the save variables outside of the eventhandler (the on pressed part)
As far as your script is concerned they don't exist outside of their handler. If you do define
them like I've done, you need to make sure the data they contain is what you want, hence the
undefined check.

getmaxsavefilename does everything max does when doing "save as"...except the save part.
Why? because you might want to do everything max does, but add some smarty pants scripty
behaviours.

-EDIT- I think I get what you are up to...

Two locations...stored in the variables save01 and save02
Hit the save button and it saves in two places?

rollout rollout01 "Save Clone" width:223 height:194
(
local save01 = undefined
local save02 = undefined
GroupBox grp1 "Save As" pos: width:206 height:130
button btn01 "File 01" pos: width:186 height:28
button btn02 "File 02" pos: width:186 height:28
button btn03 "Save" pos: width:186 height:28

on btn01 pressed do
(
save01 = getMAXSaveFileName ()
)


on btn02 pressed do
(
save02 = getMAXSaveFileName ()
)

on btn03 pressed do
(
if(save01!= undefined) then savemaxfile save01
if(save02!=undefined) then savemaxfile save02
)
)
createDialog rollout01
0 Likes
Message 3 of 13

holycause
Contributor
Contributor
ok thx a lot for your answer.
0 Likes
Message 4 of 13

holycause
Contributor
Contributor
It's make me crazy...
Yesterday it was working fine and now I've a error message.
-- Syntax error: at rollout, expected (
-- In line: rollout r
0 Likes
Message 5 of 13

bhnh
Advocate
Advocate
Sounds like a simple typing error... you've got an odd number of parens, ie you're missing a " ) " or a " ( ".
0 Likes
Message 6 of 13

Anonymous
Not applicable
Or you are missing a quote...something else I noticed...outlook and possibly other microsoft
products do a smarty pants replace on the usual double quotes and use open/close double
quotes.
0 Likes
Message 7 of 13

holycause
Contributor
Contributor
i didn't change anything....

my code:

macroScript SaveClone
category:"File"
internalCategory:"File"

rollout rollout01 "Save Clone" width:223 height:194
(
local save01 = undefined
local save02 = undefined
GroupBox grp1 "Save As" pos: width:206 height:130
button btn01 "File 01" pos: width:186 height:28
button btn02 "File 02" pos: width:186 height:28
button btn03 "Save" pos: width:186 height:28


on btn01 pressed do
(
save01 = getMAXSaveFileName ()
)

on btn02 pressed do
(
save02 = getMAXSaveFileName ()
)

on btn03 pressed do
(
if(save01!= undefined) then savemaxfile save01
if(save02!=undefined) then savemaxfile save02
)
)
createDialog rollout01
0 Likes
Message 8 of 13

Anonymous
Not applicable


rollout rollout01 "Save Clone" width:223 height:194
(
local save01 = undefined
local save02 = undefined
GroupBox grp1 "Save As" pos: width:206 height:130
button btn01 "File 01" pos: width:186 height:28
button btn02 "File 02" pos: width:186 height:28
button btn03 "Save" pos: width:186 height:28


on btn01 pressed do
(
save01 = getMAXSaveFileName ()
)

on btn02 pressed do
(
save02 = getMAXSaveFileName ()
)

on btn03 pressed do
(
if(save01!= undefined) then savemaxfile save01
if(save02!=undefined) then savemaxfile save02
)
)

macroScript SaveClone
category:"File"
internalCategory:"File"
(
if rollout01 != undefined do
(
destroydialog rollout01
)
createdialog rollout01
)


You need to "wrap" the rollout in the scope of the macroscript. I also added a get rid of the old dialog check.
0 Likes
Message 9 of 13

holycause
Contributor
Contributor
thx,

but i was the same problem :S

grrrr

if I evaluate the script without the mcr part, It works but otherwise not
0 Likes
Message 10 of 13

Anonymous
Not applicable
This seems to work. Drop it into the scripts folder, Open the Macroscript, Eveluate it to check for errors and to register it in Max, Go to customize the UI, drag the Save Clone utility to a quad or toolbar or whatever.

By the way, I didn't change anything, just moved the Macroscript header to the top of the script where it is most commonly placed, and placed the entire rollout inside the body of the Macroscript definision as it really should be.

7038_Zs9J9qmZCvssDmJk5Yg2.zip

0 Likes
Message 11 of 13

Anonymous
Not applicable
It's make me crazy...
Yesterday it was working fine and now I've a error message.
-- Syntax error: at rollout, expected (
-- In line: rollout r


How much more obvious could this error message be?!
It says it expected an opening bracket to start the MacroScript body definition, but encountered "rollout" instead which is a bad syntax. Every MacroScript opens a ( and closes with a ).

So your code should have


MacroScript TheMacroName category:"TheMacroCategory"
(--OPEN A BODY DEFINITION!!!

rollout ....

)--CLOSE IT!

🙂
0 Likes
Message 12 of 13

Anonymous
Not applicable
By the way, I didn’t change anything, just moved the Macroscript header to the top of the script where it is most commonly placed, and placed the entire rollout inside the body of the Macroscript definision as it really should be.


Is this a preference? or an actual requirement?

I haven't done a huge amount of version checking, but in the past dumping everything into the macroscript
body would cause the dialog to lose it's "handle" and you'd end up with many copies of the dialog window.
0 Likes
Message 13 of 13

Anonymous
Not applicable
By the way, I didn’t change anything, just moved the Macroscript header to the top of the script where it is most commonly placed, and placed the entire rollout inside the body of the Macroscript definision as it really should be.


Is this a preference? or an actual requirement?

I haven't done a huge amount of version checking, but in the past dumping everything into the macroscript
body would cause the dialog to lose it's "handle" and you'd end up with many copies of the dialog window.


Understanding how scopes work would help in this case.
If the macro is defined AFTER the rollout definition, the rollout will be in global scope, but evaluating the script will place a copy of the MacroScript body ONLY (!) into the macroscripts folder, making it impossible to use the script after a restart of Max unless the whole script is saved in some autoload/startup folder.

Thus, the better way to deal with this is to put everything into the MacroScript body (inside the parentheses), which of course will make the rollout local to the MacroScript and "hide" its handle from the global scope.
To avoid this, just add the lines

global theRolloutVariableName
try(destroyDialog theRolloutVariableName)catch()

to the beginning of the script right after the MacroScript definition and BEFORE the actual rollout definition, where 'theRolloutVariableName' is the name of the variable used to define the rollout. The second line will attempt to close the dialog if existing.

This setup works great and is the preferred way to define rollouts inside MacroScript.
0 Likes