CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 01-28-2013, 03:02 AM   #1
matrox89
New Member
portfolio
Berk Hakguder
Gnomon School
Los Angeles, United States
 
Join Date: Dec 2009
Posts: 13
Question quick question(mel for loop)

Hello everyone, I m trying to figure out how to use the node preset commend(Im a beginner). Just stuck and I need some help, so:

string $selection[] = `ls -sl`;
for ($each in $sel)
{
nodePreset -load $sel "selection";
}


My goal is to load the preset I saved to multiple objects. Since, I believe I can only load the preset 1 at a time I intended to use a for loop. yeah so its not working... what can I do?

thx.
 
Old 01-28-2013, 03:28 AM   #2
Panupat
Expert
 
Panupat's Avatar
portfolio
Panupat Chong
Thailand
 
Join Date: Feb 2004
Posts: 1,942
Well, $selection in your first line disappears and becomes a $sel on your second line. That won't work.

And I suggest you try to understand the for loop from this example first.

$lotsOfItems = {"a", "b", "c", "d"};

for ( $individualItem in $lotsOfItems) {
print $individualItem;
print "\n";
}
 
Old 01-28-2013, 03:37 AM   #3
matrox89
New Member
portfolio
Berk Hakguder
Gnomon School
Los Angeles, United States
 
Join Date: Dec 2009
Posts: 13
thx, but I forget to change that while I was copying to here, my bad though that's not the problem...
 
Old 01-28-2013, 03:39 AM   #4
matrox89
New Member
portfolio
Berk Hakguder
Gnomon School
Los Angeles, United States
 
Join Date: Dec 2009
Posts: 13
this is the whole script, in chase you wanna look up, just saying I just started scripting...

global proc bh_CopyPreset()
{
//------Delete the existing UI if any.
if (`window -exists bh_CopyPresetUI`)
deleteUI bh_CopyPresetUI;
//------Window UI
window -wh 300 400 -t "Copy Preset Tool" -mxb 0 bh_CopyPresetUI;
//------Layout
columnLayout -adj 1 mainCol;
//------checkbox
checkBox -l "Check it to transfer Transform Node Attributes" myCheckBox;
//------Separator
separator -h 10
-horizontal 1
-style "none"
topSeparator;
//------Button
text -l "Select the source Object";
button -l "Source Object" -command "bh_sourceObject" allButton;

//------Separator
separator -h 20
-horizontal 1
-style "none"
mainSeparator;
//------TextScrollList
text -l "Current Selected Items";
textScrollList -numberOfRows 1 -h 100 -allowMultiSelection true selectedObjects;
//------Button
button -l "Reload Selected Objects" -command "bh_selectedObjects" reloadButton;
//------Separator
separator -h 30
-horizontal 1
-style "none"
copySeparator;
//------Button
text -l "Select the target Object";
button -l "Copy Preset" -command "bh_targetObject" backButton;
//------Separator
separator -h 30
-horizontal 1
-style "none"
bottomSeparator;
//------delete preset button
button -l "Delete Stored Preset" -command deleteObjectPreset ;
//------Separator
separator -h 10
-horizontal 1
-style "none"
quitSeparator;
//------create a couple of button
button -l "Quit" -command bh_commandquit ;
//------show window
showWindow bh_CopyPresetUI;
}
//------------------------save the particleshape as a preset
global proc bh_sourceObject ()
{
int $value = `checkBox -q -v myCheckBox`;
if ( $value==0)
{
string $sourceObject[]= `ls -sl`;
string $sourceObjectShape[] = `pickWalk -d down`;
nodePreset -save $sourceObjectShape "bh_sourceObject_shape";
print "Preset Created bro!\n";
}
else if ( $value==1)
{
string $sourceObject[]= `ls -sl`;
nodePreset -save $sourceObject "bh_sourceObject_transform";
print "Preset Created bro!\n";
}
}
//------------------------loads up the preset to the selected patricle
global proc bh_targetObject ()
{
int $value = `checkBox -q -v myCheckBox`;
if ( $value==0)
{
string $targetObject[]= `textScrollList -q -si selectedObjects`;
string $targetObjectShape[] = `pickWalk -d down`;
for ($each in $targetObject)
{
nodePreset -load $targetObjectShape "bh_sourceObject_shape";
}
print "Done Bro!\n";
}
else if ( $value==1)
{
string $targetObject[]= `textScrollList -q -si selectedObjects`;
for ($each in $targetObject)
{
nodePreset -load $targetObject "bh_sourceObject_transform";
}
print "Done Bro!\n";
}
}
//--------------------------create a command to delete the window
global proc bh_commandquit()
{
deleteUI bh_CopyPresetUI;
print "Thank you come again!!\n";
}
//--------------------------editscrolllist
global proc bh_selectedObjects()
{
textScrollList -e -removeAll selectedObjects;
int $value = `checkBox -q -v myCheckBox`;
if ( $value==0 )
{
string $scrollList[] = `ls -sl`;
string $scrollListShape[] = `pickWalk -d down`;
for ( $each in $scrollListShape)
{
textScrollList -e -append $each selectedObjects;
}
print "Shape Nodes are added to the List!\n";
}

else if ( $value==1)
{
string $scrolllist[] = `ls -sl`;
for ( $each in $scrolllist)
{
textScrollList -e -append $each selectedObjects;
}
print "Transform Nodes are added to the List!\n";
}

}
//--------------------------editscrolllist
global proc deleteObjectPreset()
{
int $value = `checkBox -q -v myCheckBox`;
if ( $value==1 )
{

nodePreset -load "meshPreset_bh_CopynParticles_transform";
print "Preset has been terminated Bro!\n";
}
else if ( $value==0)
{

nodePreset -delete "transformPreset_bh_CopynParticles_shape";
print "Preset has been terminated Bro!\n";
}
}
 
Old 01-28-2013, 04:43 AM   #5
djx
Where's my pony?
 
djx's Avatar
David Johnson
vfx & creature td
Melbourne, Australia
 
Join Date: Jun 2003
Posts: 3,389
Quote:
Originally Posted by matrox89
so its not working... what can I do?

Don't take this the wrong way, but your question is a bit vague.

In your first post you have incorrectly copy-and-pasted some code, which makes it difficult to guess what you were trying to do or where the real problem was. And in your second post the formatting makes it really difficult for anyone to read (admittedly this is not entirely your fault since these forums are pretty bad for code posting, but you should at least try to use the code tags, by selecting your code and clicking the # symbol in the message window menu bar).
But most importantly, it is always advisable to include an error message, or a description of what happens that is "not working".

People here are pretty helpful, so someone might spend the time figuring it out anyway, but the easier you make it for them, the quicker you'll get an answer.

David
__________________
http://www.djx.com.au
 
Old 01-28-2013, 04:50 AM   #6
djx
Where's my pony?
 
djx's Avatar
David Johnson
vfx & creature td
Melbourne, Australia
 
Join Date: Jun 2003
Posts: 3,389
Ok, so I dont think this would work...
Code:
string $targetObjectShape[] = `pickWalk -d down`; for ($each in $targetObject) { nodePreset -load $targetObjectShape "bh_sourceObject_shape"; }

Its realy still what Panupat suggested. You are looping through the $targetObject array, but within the loop you are trying to do something with $targetObjectShape array. My guess as to what you wanted is this:
Code:
string $targetObjectShape[] = `pickWalk -d down`; for ($each in $targetObjectShape) { nodePreset -load $each "bh_sourceObject_shape"; }


Since your other loops seem to indicate you do understand how they work, maybe this was just a typo?

David
__________________
http://www.djx.com.au
 
Old 01-28-2013, 05:04 AM   #7
matrox89
New Member
portfolio
Berk Hakguder
Gnomon School
Los Angeles, United States
 
Join Date: Dec 2009
Posts: 13
Yeah you are right I m sorry about that mess, I wasnt aware of the `#` option.

So the problem is with the loop, because when you select olny one object and apply the nodePreset command it works. But when you put it inside of a loop it doesnt, and this is the error line:

// Warning: line 4: Found two selection items when one was expected. Choosing one. //

Thus you probably cant use each in there:

Code:
string $targetObjectShape[] = `pickWalk -d down`; for ($each in $targetObjectShape) { nodePreset -load $each "bh_sourceObject_shape"; }


Only because each is the variable of the 'for loop' command, right? I tried it and it didnt work... I ve spend a lot of time looking at the `for loop`examples but notting came up...

Btw thank you for your concern.

Last edited by matrox89 : 01-28-2013 at 05:08 AM.
 
Old 01-30-2013, 04:25 AM   #8
matrox89
New Member
portfolio
Berk Hakguder
Gnomon School
Los Angeles, United States
 
Join Date: Dec 2009
Posts: 13
I figured it out, thanks for your helps everyone.
 
Old 01-30-2013, 07:28 AM   #9
Panupat
Expert
 
Panupat's Avatar
portfolio
Panupat Chong
Thailand
 
Join Date: Feb 2004
Posts: 1,942
Glad you have to sorted out.

Hope I'm not stating the obvious, but allow me to use your code as an example. Modified a bit for demonstration purposes.

Code:
string $targetObjectShape[] = `ls -sl`; for ($each in $targetObjectShape) { nodePreset -load $each "bh_sourceObject_shape"; }


Let's say you have 4 objects when you run this script. $targetObjectShape will become
[ "sphere", "box", "cone", "tube" ]

Next, in your for-loop, since the array has 4 items the command in the middle will happen 4 times. Each time, $each will become each items in the array.

1 - nodePreset -load sphere "bh_sourceObject_shape";
2 - nodePreset -load box "bh_sourceObject_shape";
3 - nodePreset -load cone "bh_sourceObject_shape";
4 - nodePreset -load tube "bh_sourceObject_shape";

However if you use $targetObjectShape instead of $each, it will run the exact same command 4 times. Destroying the whole point of a for-loop

nodePreset -load ["sphere", "box", "cone", "tube"] "bh_sourceObject_shape"; (x4)

Which obviously will not work because "nodePreset -load" only accepts string and not array according to the documentation.
 
Old 01-30-2013, 07:28 AM   #10
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:09 PM.


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