PDA

View Full Version : Trigger macroscript events programmically


RustyKnight
09-10-2007, 12:10 AM
Hi all!

I was wondering if any body knew of a way to trigger a macroscript event programically?

Okay I know that sounds weird, but I've been asked to put together a toolbox containing a number of scripts and macros used by a studio, this dynamic and configurable. I've so far been able to get most of it working really well, using macros.load and macros.run (as well as execute for the plain scripts)

The only thing I've not yet been able to figure out is how to watch for or trigger the "isEnabled" event so i can disable the buttons been used to represent the macro (long story).


Ideas and pointers, as always, are welcome

Cheers
Shane

PEN
09-10-2007, 10:59 AM
What have you tried? There are examples that you can look at in the help or just grab one of the macors that ship with Max and you can see how they have done it. Sorry I don't have Max infrount of me or I would look up what I have done.

RustyKnight
09-10-2007, 11:29 AM
Hi Paul!

Thus far I've not really done anything. I was thinking about attaching some listeners to some of the general callbacks and then trying to trigger the macroscripts that we are managing directly, but that raises the question of how do you make a call to a scripts event handler??

I also thought about trying to montior the macroscripts and look for changes, but I don't think that this approach overly pratical.

The current execution model we have is simple, we wrap the scripts around our own buttons and when the user clicks the button in the toolbox, we simply use a combination of execute and macros.run, so this will need to change, so that the macro is loaded and running when the toolbox is initalised.

The problem as I see it right now, is how do you reference a "running" macro?? You can't simply say "myMaco.doSomething"...??? At least from what I can tell.

Yes, given the source, we can load and run the macro, but how can we tell if the macro is in a valid state to run or not?? There doesn't appear to be any means to gain a reference to any of the macros once they have been loaded...or at least that I have found.

Shane

eek
09-10-2007, 02:33 PM
callbacks.addScript or change handlers.

RustyKnight
09-11-2007, 12:05 AM
Hi eek!

Yep, that much I understand. But now, how do I determine if a macroscript is "enabled"...how do I make that check programmically??

Cheers
Shane

eek
09-11-2007, 12:27 AM
Hi eek!

Yep, that much I understand. But now, how do I determine if a macroscript is "enabled"...how do I make that check programmically??

Cheers
Shane


What do you want to do? check if a buttons been pressed?

RustyKnight
09-11-2007, 12:38 AM
Basically, I want to know, programmically, if a macroscript can be executed. I wish to change my rollup to reflect the macroscripts current state.

Basically we have a bunch of buttons that are "wrapped" around these scripts (they simply "represent" the macro, they are not the physical macro), so that when they are pressed, the underlying macroscript (or script for that matter) is executed, programmically (we physically load the script and execute it), BUT, I don't seem to be able to tell if the underlying macroscript is actually in a state to be run. This is what I need to check..."myMacro.isEnabled"...or something equivalent.

The problem right now, is i don't seem to be able to find away to actually gain a reference to any of the macros installed. I can get the "id", but this does not help.

I want to be able to get the result of the "on isEnabled do (...)" event handler and update my rollout's ui accordingly.

Cheers
Shane

eek
09-11-2007, 01:34 AM
Basically, I want to know, programmically, if a macroscript can be executed. I wish to change my rollup to reflect the macroscripts current state.

Basically we have a bunch of buttons that are "wrapped" around these scripts (they simply "represent" the macro, they are not the physical macro), so that when they are pressed, the underlying macroscript (or script for that matter) is executed, programmically (we physically load the script and execute it), BUT, I don't seem to be able to tell if the underlying macroscript is actually in a state to be run. This is what I need to check..."myMacro.isEnabled"...or something equivalent.

The problem right now, is i don't seem to be able to find away to actually gain a reference to any of the macros installed. I can get the "id", but this does not help.

I want to be able to get the result of the "on isEnabled do (...)" event handler and update my rollout's ui accordingly.


Shane


first off, id turn it into a rollout. And secondly


" tell if the underlying macroscript is actually in a state to be run"


cant you use scene variables to do this? For example you could use a callback to check if a scene object exists and flag a varible in a struct to true. The callback of the button/ macro script could then check this struct variable and execute itself.

its like if $ != undefined, but the variable could be anything. You need to look at it from the perpective of the scene - a script is just that, it doesnt really no about itself or what to do unless variables it knows about are set.

This is why script ca are so powerful - you can make a parameter block on a object that can be a boolean, which a callback could set. Then the animator etc, pressing a macroscript - would ask if this variable is true/false etc and execute etc. So you need to give the script info from the scene.

RustyKnight
09-11-2007, 01:51 AM
Hi eek!

That all sounds really interesting, except :sad:...

I have no "access" to the original macros, so I can't make the macro check for the variable...

What the "toolbox" does, is allow an artiest to collect together all there useful scripts and macros into a central location (which they can cataglog as they see fit)...it also uses a global and user settings to allow the studio to rollout all the scripts they want to the artiest...but this is off track.

The "toolbox" simply keeps a link to the underlying script.

When the user clicks the toolbox button, it reads the script from the file and uses a combination of "execute <string>" and where required, "macros.run <int>" to do most of it's work.


This basically means that I don't have access to ANY of the underlying source and I'd prefer not to have to manipulate the source code (programmically or otherwise).

I did flurted with the idea of "stripping" out the "on isEnabled" source and executing it directly, but I'm worried about the reliance of local variables inside the macro.

I then flurted with the idea of programmically wrapping the the macro inside something like a rollout (stripping out the macro defination and changing some of the event handlers) and then using a callback setup to trigger the "isenabled" process...

Then i thought, this is all completely crazy!! I'd have some much duplicate code running around and the over head required to maintain it and...there has to be a simpler method...

eek
09-11-2007, 02:57 AM
I have no "access" to the original macros, so I can't make the macro check for the variable...

hmm.. If its a toolbox, animators/artist can just drag scripts onto - you pretty much have no control. What you could do in theory is when they add the scripts or they get called for the first time it propergates an .ini file of variables for that script the user could specify maybe? eg. you run the script for the first time and it gives you options: 'run only when...' etc etc.. that get saved for that macro.

Then when the user runs the macro, it calls the ini file and checks against it? If the rollout is being built on the fly why cant callbacks be built too? i.e i add a script to a folder outside of max. I run max and the rollout which, builds a button to the script in the folder and a ini variable for it. When the button is called it checks against the ini? Look at structs - remember the macro is like the result - cant you play with the gui of the macro somehow.

E.g you dont want to control the engine, you want to control the ignition and check if theres fuel in the car, which starts the engine :)

RustyKnight
09-11-2007, 03:05 AM
Thanks eek!

I really appriciate your suggestions on this one! It's giving me an oppurtunity to bounce some ideas about. I think your right.

If I find a suitable solution, I'll let you know

Shane

RustyKnight
09-20-2007, 01:17 AM
Just a heads up...

The only solution I have been able to find right now is to parse the macro source, remove just about every thing, other then the "on enabled do" event, rewrite that as a function and then register a whole bunch of callbacks and walk through the list call "isEnabled"...

Now I know why I'm going balled...

I've "skimmed" the sdk api and there might be some more suitable methods via a plugin...now all I need is time to re-learn c++

Cheers
Shane

CGTalk Moderation
09-20-2007, 01:17 AM
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.