PDA

View Full Version : scriptCtx: issues with selection sets


GearSpinner
11-09-2011, 05:24 PM
Hey all,

I'm having some issues with the scriptCtx command in MEL. I'm trying to make a tool that chains together some functions that perform some operations on a list of objects. My selection sets don't seem to be working at all.

At the end of the scriptCtx, it does call the functions I have listed, but the contents of the selections are wrong. In addition, the second set will not accept a single object alone, I press enter and nothing happens until I select 2 or 3. Then, testProcB prints the wrong set of objects, to boot!http://tech-artists.org/forum/images/smilies/27.gif

So clearly I'm doing something crazy wrong here

This is what I'd like to accomplish:

Press a button in a UI
User selects a set of objects and presses Enter
Objects are added $Selection1

User selects another set of objects presses Enter
Objects are added to $Selection2

$Selection1 is passed to testProcA
do some things to objects in $Selection1

$Selection1 is passed to testProcB
do some things to objects in $Selection2

and so on until the end of the chain (set to 2, currently)...


Here's my code and thanks for reading.

proc testProcA(string $a[]) {
for ($object in $a) {
print("In Selection A: "+$object +"\n");
}
}

proc testProcB(string $a[]) {
for ($object in $a) {
print("In Selection B: "+$object +"\n");
}
}

if (`contextInfo -exists chainTest`)
deleteUI chainTest;

window;
columnLayout;
button -c "setToolTo chainTest" chainTest;
showWindow;

scriptCtx
-title "chainTest"
-totalSelectionSets 2
-finalCommandScript "testProcA($Selection1); testProcB($Selection2);"

-setNoSelectionPrompt ("1: Select objects")
-setSelectionPrompt ("1: Select more and hit ENTER")
-setAutoToggleSelection false
-setAutoComplete false
-setSelectionCount 0

-setNoSelectionPrompt ("2: Select objects")
-setSelectionPrompt ("2: Select more and hit ENTER")
-setAutoToggleSelection false
-setAutoComplete false
-setSelectionCount 0

chainTest;

GearSpinner
11-13-2011, 12:56 AM
Update:

Well I was able to get this to work the other day, finally, but not exactly the way I intended. I ended up using two scriptCtx calls, and calling the second from the procedure started by the the first.

I found it was important to use evalDeferred("setToolTo yourScriptCtx;") when calling scriptCtx from inside a function like this, or you may get bad results. In my case, it caused Maya to crash :o

I wanted to post this solution in case anyone runs into a problem like this. Maybe somebody will find it useful. I don't know if this is the best way, but it worked for me.


proc testProcA(string $a[]) {

for ($object in $a) {
print("In Selection A: "+$object +"\n");
evalDeferred("setToolTo chainTestB;");
select -cl;
}
}

proc testProcB(string $a[]) {

for ($object in $a) {
print("In Selection B: "+$object +"\n");
select -cl;
}
}


if (`contextInfo -exists chainTestA`)
deleteUI chainTestA;

if (`contextInfo -exists chainTestB`)
deleteUI chainTestB;

window;
columnLayout;
button -c "setToolTo chainTestA" chainTestA;
showWindow;

scriptCtx
-title "chainTestA"
-totalSelectionSets 1
-finalCommandScript "testProcA($Selection1)"

-setNoSelectionPrompt ("1: Select objects")
-setSelectionPrompt ("1: Select more and hit ENTER")
-setAutoToggleSelection false
-setAutoComplete false
-setSelectionCount 0

chainTestA;

scriptCtx
-title "chainTestB"
-totalSelectionSets 1
-finalCommandScript "testProcB($Selection1)"

-setNoSelectionPrompt ("2: Select objects")
-setSelectionPrompt ("2: Select more and hit ENTER")
-setAutoToggleSelection false
-setAutoComplete false
-setSelectionCount 0

chainTestB;

CGTalk Moderation
11-13-2011, 12:56 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.