Can I script job or HUD element have more than one event to trigger it?

Can I script job or HUD element have more than one event to trigger it?

malcolm_341
Collaborator Collaborator
644 Views
5 Replies
Message 1 of 6

Can I script job or HUD element have more than one event to trigger it?

malcolm_341
Collaborator
Collaborator

Hi, I'm trying to use an event to update my HUD element, the problem is I need it to update in on selection change and also update on UV set change. Is there a way to assign two events to the same HUD or script job?

0 Likes
645 Views
5 Replies
Replies (5)
Message 2 of 6

FirespriteNate
Advocate
Advocate

I don't think a ScriptJob needs to support multiple events, because you just create multiple scriptJobs, one for each event you want to trigger it, but point them all to the same command. 

As for HUDs, are you using the headsUpDisplay command? That has an optional -nodeChanges flag that pairs with the -event flag for "SelectionChanged" events, so that the update can be triggered on Selection changes OR any attribute changes on the selection. This should work for changing UV Sets.

For example, this Python code should print "TRIGGERING!" whenever you change selection, or change UVSet on any selection:

 

def dualTrigger():
    print('TRIGGERING!')

from maya import cmds
cmds.headsUpDisplay('exampleHUD_dualTriggers', command=dualTrigger, 
                    event='SelectionChanged', nodeChanges='attributeChange',
                    section=1, block=0, blockSize='medium', label='dual')

 

(The same should work fine in MEL too btw)

Message 3 of 6

malcolm_341
Collaborator
Collaborator

@FirespriteNatethanks for your reply, do you know how to write that same code in Mel I'm developing a Mel script for somebody.

0 Likes
Message 4 of 6

FirespriteNate
Advocate
Advocate

sorry, I assumed that'd be the easy part 😅 - converting basic cmds from python to MEL (and vice versa) is pretty straightforward, all the flags and stuff is the same, just the syntax is a bit different:

global proc dualTrigger()
{
    print "TRIGGERING!";
}

headsUpDisplay -command "dualTrigger"
               -event "SelectionChanged" -nodeChanges "attributeChange"
               -section 1 -block 0 -blockSize "medium" -label "dual" 
               "exampleHUD_dualTriggers";

 

Message 5 of 6

mcw0
Advisor
Advisor

This is what ChatGPT is for!!!  LOL!  Couldn't resist.  🙂

0 Likes
Message 6 of 6

malcolm_341
Collaborator
Collaborator

Oops I replied to the wrong message, sorry I thought we were on a different topic. I'll give it a try next time I need to convert something.

0 Likes