PDA

View Full Version : Macroscripts? Can someone help me?


Guibou
01-14-2009, 10:05 PM
Hi i've created a Macroscript, so that i have a toolbar with buttons executing a script.
My macroscript is placed in the following folder...
Program Files\Autodesk\3ds Max 9\ui\macroscripts

In the macroscript i call a script, SCRIPT#1, that i made, placed in the following folder...
\Program Files\Autodesk\3ds Max 9\Scripts\Startup

It seems that i would always have to evaluate my SCRIPT#1 everytime i reboot Max so that my macroscript works properly

It's my first time working with macroscripts so there's obviously something i'm missing. Thanks for the help :)

ZeBoxx2
01-14-2009, 10:11 PM
nope - you have that pretty much right. Unless you can inline the code from 'SCRIPT#1' into the macroscript definition (directly or via an include), you'll have to evaluate SCRIPT#1 before interacting with anything inside it.

Guibou
01-14-2009, 10:24 PM
Here's one of the example.

-- Creates Main Shape for Character
macroscript MainShape
category:"Longtail Studio Rigging"
buttontext: "Main Shape"
toolTip:"Creates the Main Shape Control"
(
on execute do
(
createMainShape() --that would be SCRIPT#1
)
)

Guibou
01-14-2009, 10:29 PM
Oh ok, i get it. That's a bit annoying :(

Thanks a lot ZeBoxx2

ZeBoxx2
01-14-2009, 10:30 PM
-- Creates Main Shape for Character
macroscript MainShape
category:"Longtail Studio Rigging"
buttontext: "Main Shape"
toolTip:"Creates the Main Shape Control"
(
-- either stick all of the code from SCRIPT#1 here
on execute do
(
-- or include the file that has SCRIPT#1 here - e.g. via fileIn
createMainShape() --that would be SCRIPT#1
)
)

Either that, or have SCRIPT#1 run on startup...
- place SCRIPT#1 in the scripts\Startup\ folder
OR
- place SCRIPT#1 in any of the plugin paths or subfolders of those paths.

Edit: Looks like you posted while I posted this - yes, it is slightly annoying... but at least that bit makes sense. Macroscripts being copied about.. makes a little less sense and is a tad more annoying.. but that's another story ;)

martroyx
01-15-2009, 12:06 AM
use filein to execute your script this way you dont have to update the macro definition every time, unless you change the script name !

-- either stick all of the code from SCRIPT#1 here[/color]
on execute do
(
-- or include the file that has SCRIPT#1 here - e.g. via fileIn
filein (getdir #scripts +"\\startup\\scriptname.ms")
createMainShape() --that would be SCRIPT#1
)
)]



by the way, user macro are stored in :

Documents and Settings\Administrator\Local Settings\Application Data\Autodesk\3dsmax\2009 - 32bit\enu\UI\usermacros

martin

diffx
01-15-2009, 06:47 AM
-- or include the file that has SCRIPT#1 here - e.g. via fileIn
filein (getdir #scripts +"\\startup\\scriptname.ms")

In that case, this might even be easier:

filein ("$scripts\\startup\\scriptname.ms")

Guibou
01-15-2009, 06:37 PM
Thanks guys, i really appreciate all the help i've been given these past two weeks. Maxscript Reference helps to, but it never beats having somebody explaining it in normal syntaxe ;)

Have a good day all

JHN
01-15-2009, 09:43 PM
In that case, this might even be easier:

filein ("$scripts\\startup\\scriptname.ms")

Be aware though, fileIn executes the code in the global scope, not in the macroscript scope, so that means you'll have to set global variables to access whatever function you need to access! This has gotten me a while ago to. "include <file>" injects the code right there where you place the statement, so you can acces it directly. "fileIn <file>" runs the script in a global scope, so to get access through it's content you either need to set global vars in the fileIn'ed file or don't use braces in that file, meaning all vars and functions will be made global right there (not a great solution!). fileIn is like, "run script", include is like "I need to run that code in this place".

-Johan

martroyx
01-15-2009, 09:58 PM
I'm I right to say that include is slower than putting the actual code since it have to read from disk ?

JHN
01-15-2009, 10:13 PM
Depending on the speed of your disk I'd say yes, but how much including and fileIn'ing will you be doing.. I think it's neglectable speed wise, if your looping 10.000 times you'll need to consider speed optimizations, including of fileIn'ing a file once should be dictated by the "program flow" ease of use, imo!

-Johan

martroyx
01-15-2009, 10:16 PM
yes, this shouldn't be such a big deal :-P
I never used it, and I'm wondering in witch case this could be useful ?

JHN
01-15-2009, 10:26 PM
1st. I have build a menu system that build's macroscripts dynamicly, the macroscript are just simple menu placeholders that fileIn the script/Tool I need. So for my work scripts I don't really make anymore "real" macroscripts, I build them dynamicly and they fileIn the actual scriptfile.
2nd. If you have scripts going over 1500 lines of code and a lot of generic (reusable) code, you can consider building library scripts (like dll's) that you can reference from in the script, you can then either fileIn them and set them up from with a global variable, or include them directly compiling the code in your script. Or run them from stdScripts dir and simply call the functions you need, since it was already loaded with max.

So it can be usefull, but honestly I don't use it, except for the dynamic menu. But over TechArtists.org some interresting stuff is going on.

Cheers,
-Johan

martroyx
01-15-2009, 10:34 PM
Thank for the explanation !
so it's useful when working on big script but I still prefer to see all my code at once ;)

CGTalk Moderation
01-15-2009, 10:34 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.