Hi Matt:

Thanks for the advice! I was looking to do something like what I do right now in Maya, such as having a scriptNode execute things like importing rig references by default, display/render layer setups and other things that animators might forget to set by default like setting scene frame rates etc.; basically take human error in scene setup out of the equation as far as possible. Usually I have this scriptNode call an external python script, though, so that I don't have to re-save an existing scene should what I want this scene setup/check script to do changes.)

I was afraid that having global custom event handlers scan each scene as it is opened and only execute if a condition is met (i.e. scene filename or unique paramset or similar) would affect overall performance, but I guess since you guys are doing this too, it should be fine for my purposes (which are far simpler to yours)

I guess it would be nicer if I could limit my plugin for the event handler to be project-scope, instead of user/workgroup-scope, if that makes sense.

Again, thanks for the insight!  :D

On 7/29/2014 11:13 AM, Matt Lind wrote:
What specifically must your scene-specific script do?

Generally speaking, you should write your events to be very generic.  The event 
will always fire, but will only do meaningful work if certain data or criteria 
is met in the scene.  The advantage to this method over the scriptNode 
technique is users can't mess with script events easily ensuring a certain 
level of stability within your production.

We have a few event scripts along this fashion.  One has the responsibility of 
scanning the scene for customparamsets and converting them to the equivalent 
self installing custom property while preserving parameter values and 
connections to sources such as expressions or FCurves.  If there are no 
customparamsets in the scene, the event doesn't do any work.

Another example is our face animation system.  Our faces are built like 
components of a Mr. Potato Head doll.  Each face asset is a model which plugs 
into the body and has a self installing custom property applied to its model 
root for identification.  If the scene load event sees this scenario, it knows 
to clear out the animation mixer of the face and rebuild it from data stored in 
a database table.  If there are no faces in the scene, then the event does 
nothing.

Basically I structured it so there is one event of each type installed, and the 
event's job is to determine if work needs to be done at the time it's called.  
If so, a command is called by the event which performs the actual work.  A 
command is called for two reasons: 1) keeps event code simple and generic 2) a 
command is logged as a single edit in the undo history and is undoable with a 
single undo operation, code written directly in the event script is not.


If you insist on going the scriptNode route, you can get a text or annotation 
property and stick it at the scene root injecting it with your script code to 
setup a bootstrap environment.  Your event script would look for these 
properties, and if found, execute the code contained within the property.   
It's easy to set up, but it's also very easy to cause all sorts of problems as 
users can interact with this data and mishandle or abuse it to create really 
big headaches for you.  Some of which may not be solvable.  Another problem is 
when the script code needs updating.  You'll have to save a new version of the 
scene to induce the change.  If the user needs to roll back the scene for a 
different reason, well, you're code is now out of sync and may possibly 
introduce a bug you've just fixed.  Since the user doesn't know about the 
problem, he/she won't know not to roll back or won't be able to recover your 
bug fix because it was lost when the scene was rolled back to a previous 
verison.  Using the script event system, your code is abstracted away from the 
scene and not prone to this type of problem.


Matt




-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Yi Liang Siew
Sent: Tuesday, July 29, 2014 7:32 AM
To: [email protected]
Subject: Making custom events scene-specific?

Hi all!

Lately I've been trying to port a small little PyQT tool I made over to XSI, 
but I'm running into a little problem: I've been trying to figure out a way I 
could get a python script to fire off upon loading of a specific scene (Ideally 
this would be the equivalent of the scriptNode in Maya).

I guess I could make a plugin that looks specifically for a custom event of the 
scene load and match it by name, then store that with my project, but I'm 
wondering if there is a more elegant solution already for this that I've 
overlooked.

Thanks!




Reply via email to