PDA

View Full Version : Pause/proceed within a loop


shcmack
12-01-2011, 10:53 PM
So here's what I'm trying to do;
Within a loop, I want a prompt-window to pop up on the screen, similar to the one you get from the "promptDialog" -command. However, I also want the possibility to navigate around in the viewport while having the prompt open, which doesn't seem to be possible with either of the following: promptDialog | confirmDialog | layoutDialog.

I was hoping someone could point me in the right direction :)

kevinsallee
12-01-2011, 11:09 PM
actually all the dialogs you're speaking about are modal windows so they take the focus and don't let it go until you finish with them.
But at the end a promptDialog is just a window with some text inside
so create a window with some rowlayout or whatever you want, plus an ok button that does a deleteUI and you're good to go :)

kevinsallee
12-01-2011, 11:18 PM
here's some sample mel code:
string $myWindow = `window -title "myPrompt"`;
columnLayout;
rowLayout -numberOfColumns 1;
text -label "MY PROMPT!";
setParent ..;
rowLayout -numberOfColumns 1 -cl1 "right" ;
button -label "OK" -command ("deleteUI " + $myWindow );
showWindow;
window -e -width 100 -height 100 $myWindow;

NaughtyNathan
12-01-2011, 11:28 PM
if you want your script to effectively halt when a "confirm" UI window pops up, then simply make your script finish with the pop-up ui. There must be a button on your "confrm" UI right? which, when pressed fires off the "rest" of the script. it's not halting a single script then continuing, it's simply finishing one function with a ui, then launching a second function from that UI.

If for some reason you need the modal qualities of a dialog, but just want an interactive viewport, you coulds always create a layoutDialog and embed a modelEditor panel inside it.

:nathaN

shcmack
12-02-2011, 08:23 AM
Thanks guys :) I was hoping you could explain a little further as I am struggling a bit to understand it :argh:

When dealing with normal windows within the loop, I can't get the script to pause and wait for the window to close. It just opens the window while continuing the loop.

There must be a button on your "confrm" UI right? which, when pressed fires off the "rest" of the script.Well, yes. I want the script to halt, then the user would make some changes to some objects in the scene, then when clicking "OK" the script should continue the loop and get the new attribute-values of the objects that has been changed.

uiron
12-02-2011, 08:33 AM
modal messages allow simple thread blocking until dialog is closed, but there's not easy way to have that with modeless dialogs, especially when most of commands api is not thread safe.

just go with what Nathan offered. It's much simplier.

shcmack
12-02-2011, 09:42 AM
modal messages allow simple thread blocking until dialog is closed, but there's not easy way to have that with modeless dialogs, especially when most commands api is not thread safe.

just go with what Nathan offered. It's much simplier.
If I understood Nathan correctly, I would have to know how many functions I have, as I have to call them from my UI, right? I may have misread, but that's how I understood it.

The problem with this is that I don't know how many functions I would need, as it depends on how many objects the user selects when running the script.


I'll try to explain what my script is supposed to do;
- The user selects and loads a driver object
- The user selects and loads one or more driven objects
- The script will get all of the attribute-values of the driven objects
- For each attribute of the driver-object, prompt the user to make changes to the driven objects that should be affected by the current attribute of the driver
- When the user has manually made some changes to the driven object(s), he clicks "Next" on the prompt
- The script checks to see which of the driven object's attributes that has been changed, and stores the changed values
- The script should continue with the loop, going on to the next of it's attribute, then prompting with the same message

NaughtyNathan
12-02-2011, 11:20 AM
yeah, if you want to do this inside a loop you are going to be stuck. You need to refactor your code somehow so it is broken into two distinct functions, the first which ends with a UI window, and the second which is started from this UI window and completes the operation for each single object in a previously defined list of objects.

I don't know exactly what you're doing, but as a rough guess/guide, make your first function get and process all the objects in a loop as you have done, but don't make it actually run the operations that happen after the "confirm". during this initial run you will need to construct a list of items you are operating on, and potentially some other details about what you will be doing to them, all of which you will have to dump into global arrays (as you're using MEL) so your second function can know what to operate on and over, and how.
Once this first step is done, and you have some global arrays of items and maybe instructions, you then finish this initial function by firing off the first "confirm" UI. When you press the button on this UI it looks at the first object in your global array, and what to do with it, and does it, then respawns itself as a second confirm UI with the array indices incremented so you keep track of what object you are working on.

I hope that makes sense, maybe I could knock up an example if I get the time.
:nathaN

shcmack
12-03-2011, 09:05 AM
I hope that makes sense, maybe I could knock up an example if I get the time.
:nathaNIt did, thanks a lot for takin the time to explain :)

The script I'm building is relying on so many variables that it's too confusing trying to work my way through them by calling procedures within procedures, passing on global incremental variables to get the loops to work correctly and such. So I'm wondering, is this something that can be achieved easier with Python?

CGTalk Moderation
12-03-2011, 09:05 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.