PDA

View Full Version : Is it possible to modify a script through a Rollout before running it?


Guibou
04-09-2009, 06:16 PM
Hi,
I'm looking for a way to change the prefixe of some objects created in a scripts.

Ultimately, what i'd like is having the artist click on a button. That would pop a window where he would be asked to write the name of the Character he wants to rig.

That name would then replace the "placeholder" prefixe that is place in the script. So Entering "John" in the window would change one of the objects name for example:
MyChar_Bone_Arm_Right for John_Bone_Arm_Right.

I don't want to do it with the Rename Tool because the name would need to be changed in the script before running it, since i'm using the name of certain objects in custom attributes to perform various action.

I would like to find a way that is simpler in the long run than to change it manually in the script before running it. Something more intuitive to the user, like a window where he writes the Characters name and he can than move on to rigging the character.

Thanks for your time and have a nice long week-end all!

ZeBoxx2
04-09-2009, 06:22 PM
Try opening a rollout with a text input field as modal so that your main script halts execution until that dialog is closed. The text input dialog then only needs to set a variable for the main script to check.


global myInput
rollout roll_input "Enter input" (
edittext edit_input ""
on edit_input entered str do ( myInput = edit_input.text; destroyDialog roll_input )
on roll_input open do ( setFocus edit_input )
)

rollout roll_test "test" (
button btn_rename "rename current object"
on btn_rename pressed do (
myObj = getCurrentSelection()
if (isValidNode myObj[1]) do (
myInput = undefined
createDialog roll_input modal:true
if (myInput != undefined) do (
$.name = myInput
)
)
)
)
createDialog roll_test

Guibou
04-09-2009, 07:00 PM
Thanks ZeBoxx2!

With the code you showed me, would the objects that will be renamed have to be created first and than renamed?

What i would like is to change the name of the objects in my script before they are even created.

So really i want to be able to alter my script, kind of like using the Replace option in the Search Menu of the Maxscript Editor. I would like to look for every area where my script says MyChar and replace it with whatever name is needed at that time.

Thanks again for your time!

ZeBoxx2
04-09-2009, 07:11 PM
well that would just be a matter of changing -where- that string gets inserted into a variable..

global myInput = "Default"
rollout roll_input "Enter input" (
edittext edit_input ""
on edit_input entered str do ( myInput = edit_input.text; destroyDialog roll_input )
on roll_input open do ( setFocus edit_input )
)

rollout roll_test "test" (
button btn_changerename "change rename string"
button btn_rename "rename current object"
on btn_changerename pressed do (
createDialog roll_input modal:true
)
on btn_rename pressed do (
myObj = getCurrentSelection()
if (isValidNode myObj[1]) do (
$.name = myInput
)
)
)
createDialog roll_test


If you actually want it stored, hardcoded, into a new script file (which is what Search > Replace) would do, then you'd have to open the original script file, read each line to a buffer while using substituteString or so to replace "myChar" with whatever string you wanted to use instead, and save the buffer to a new script file.

Using a variable (as per the above scripts) is much more flexible, though.. although in most cases I wouldn't use a popup - I'd just add some edittext field somewhere in the main script (like most of the name prefixer / postfixer scripts do).

thatoneguy
04-09-2009, 08:07 PM
Another idea that's a little more like what you want would be for an ini file.

But a variable seems like a better alternative.

ZeBoxx2
04-09-2009, 08:36 PM
well, the variable's default value could still be read from that ini, first-run, and written to the ini when appropriate.. that sort of thing

Guibou
04-14-2009, 04:31 PM
Sorry you guys, you might think I'm done and i simply don't understand, but...

With the examples you gave me this would actually enable me to change part of a name in my script no matter what that name refers to and how it is used. Even if i simply want to change the prefixe of a name.

Let's say i'm rigging character "Bumbo". What i'm doing right now manually is open my Character Rig script. Go in "Search" / "Replace"
Search: MyChar
Replace by: Bumbo

So now anywhere in my script where i might have MyChar, it will be replaced by Bumbo. Example, MyChar_Shape_Foot_Right would now be Bumbo_Shape_Foot_Right.

I haven't had time to try your script yet, but i'll be working on that this week. Thanks a lot for your time and help. Have a good week :)

thatoneguy
04-14-2009, 05:50 PM
Sounds like you want a dynamic rollout then.

If you want a dynamic rollout you use the execute command and a stringstream


stringvar = stringstream ""

format "rollout % \"%\"(" charname charname to:stringvar
format "button % \"%\"" (charname+"button") charname to:stringvar
format ")" to:stringvar
execute stringvar

Guibou
04-28-2009, 02:47 AM
Hi thatoneguy, i don't really understand your script. Would you mind explaining a bit your code. It would help me a lot to understand what's going on. Thanks for your response and thanks for your time.

CGTalk Moderation
04-28-2009, 02:47 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.