Is it possible to modify a script through a Rollout before running it?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  04 April 2009
Is it possible to modify a script through a Rollout before running it?

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!
 
  04 April 2009
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
 
  04 April 2009
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!
 
  04 April 2009
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).
 
  04 April 2009
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.
 
  04 April 2009
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
 
  04 April 2009
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
 
  04 April 2009
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
 
  04 April 2009
Smile

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.
 
  04 April 2009
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:14 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.