PDA

View Full Version : Need Help In Making My First Script


light03
09-15-2010, 07:07 PM
Hi i m trying to make one small script in MEL , as i don't know much of MEL programming i am trying by reading some tutorials from net ,,
m trying to make simple mel script to make render layers
i written some code with interface , n now need to automate , this is my WIP mel script till now which creates render layer by clicking button ,,,,

if (`window -exists windowName`) deleteUI windowName;
window -title "LayerMaker" windowName;
columnLayout ;
button -l "make layers" -c layers;
showWindow windowName;
proc layers()
{
createRenderLayer -name "SQ00_SC00_CHAR_DIFF_V01" -number 1 -noRecurse `ls-sl`;
}



help would b highly appreciated ,,, thanks

NaughtyNathan
09-15-2010, 10:51 PM
you want the promptDialog command. take a look at the MEL docs for that command and there's an example script you can use. You'll just need to tokenize the user input to extract the 2 separate strings they type in (SQ00 SC00)

:nathaN

light03
09-16-2010, 08:43 PM
Hi Thank you for replying quickly ,,,,
last nite i tried alot to work out ,,,, ur above reply helped me alot ,,,,
so dis is my WIP now ,,,
i am able to take user input with help of promptDialog
it stored the input but when i click OK it create a default renderlayer , i know its incomplete
so now i want the renderlayer which is created should be replaced by the user input ...
I tried alot Tokenize i understood the concept but fail to use it in script ,I know dis could help but not able to do so :-(( ,,,
plz chek n run my script and see my progress ,,, n plz help me with next step ,,,

it should simply create renderLayer just by including the user input ,,,,,
thanks
waiting for your reply ,,,,,,,
=====================script========================

if (`window -exists windowName`) deleteUI windowName;
window -title "LayerMaker" windowName;
columnLayout ;
button -l "make layers" -c userinput;
showWindow windowName;

proc layers()
{
createRenderLayer -name "SQ00_SC00_CHAR_DIFF_V01" -number 1 -noRecurse `ls-sl`;
}

proc userinput()
{
string $text;
string $result = `promptDialog
-title "Rename Object"
-message "ENTER SQ00_SC00"
-button "OK" -button "Cancel"
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;



if ($result == "OK") {
layers;
}

}

mlefevre
09-16-2010, 10:41 PM
Been a while since I've done some MEL, haven't fully tested this!
- not 100% sure what you need to extract from the user, or what your naming system is, but perhaps parts of this might put you in the right direction.

if (`window -exists windowName`) deleteUI windowName;
window -title "LayerMaker" windowName;
columnLayout ;
button -l "make layers" -c userinput;
showWindow windowName;

global proc layers(string $text)
{
$text = `substituteAllString $text " " "_"`; //substitute whitespace for underscores
$text = `match "^[a-zA-Z][0-9a-zA-Z_]*$" $text`; //check name is valid

if($text != "")
createRenderLayer -name $text -number 1 -noRecurse `ls -sl`;
else
userinput;
}

global proc userinput()
{
string $result;
string $text = "";
while($text == "" && $result != "Cancel")
{
$result = `promptDialog
-title "Rename Object"
-message "ENTER SQ00_SC00"
-button "OK" -button "Cancel"
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;

$text = `promptDialog -q -text`;
}

if ($result == "OK")
layers($text);
}

light03
09-17-2010, 06:29 PM
,,,,,,,,thnkyou

mlefevre
09-17-2010, 06:43 PM
ah, ok. This might do the trick for now.

if (`window -exists windowName`) deleteUI windowName;
window -title "LayerMaker" windowName;
columnLayout ;
button -l "make layers" -c userinput;
showWindow windowName;

global proc layers(string $text)
{
string $suffix = "_CHAR_DIFF_V01";
$text = `substituteAllString $text " " "_"`; //substitute whitespace for underscores
$text = `match "^[a-zA-Z][0-9a-zA-Z_]*$" $text`; //check name is valid

if($text != "")
createRenderLayer -name ($text + $suffix) -number 1 -noRecurse `ls -sl`;
else
userinput;
}

global proc userinput()
{
string $result;
string $text = "";
while($text == "" && $result != "Cancel")
{
$result = `promptDialog
-title "Rename Object"
-message "ENTER SQ00_SC00"
-button "OK" -button "Cancel"
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;

$text = `promptDialog -q -text`;
}

if ($result == "OK")
layers($text);
}

light03
09-18-2010, 07:24 PM
, u doing great job ,,,,


thanks a lot ,,,,

light03
09-19-2010, 06:14 PM
hey friend ,,,, waiting for ur input ,,,,,,,

mlefevre
09-20-2010, 12:04 PM
if (`window -exists windowName`) deleteUI windowName;
window -title "LayerMaker" windowName;
columnLayout ;
button -l "make layers" -c userinput;
showWindow windowName;

global proc layers(string $text)
{
//add or remove suffixes to this list
string $suffixList[] = {
"_CHAR_SPEC_V01",
"_CHAR_REFL_V01",
"_CHAR_KEY_V01",
"_CHAR_SDW_V01",
"_CHAR_OCC_V01",
"_CHAR_AMB_V01",
"_CHAR_DIFF_V01" };

$text = `substituteAllString $text " " "_"`; //substitute whitespace for underscores
$text = `match "^[a-zA-Z][0-9a-zA-Z_]*$" $text`; //check name is valid

if($text != "")
{
for($suffix in $suffixList)
createRenderLayer -name ($text + $suffix) -number 1 -noRecurse `ls -sl`;
}
else
userinput;
}

global proc userinput()
{
string $result;
string $text = "";
while($text == "" && $result != "Cancel")
{
$result = `promptDialog
-title "Rename Object"
-message "ENTER SQ00_SC00"
-button "OK" -button "Cancel"
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;

$text = `promptDialog -q -text`;
}

if ($result == "OK")
layers($text);
}

CGTalk Moderation
09-20-2010, 12:04 PM
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.