Run a script on multiple nodes?

Become a member of the CGSociety

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

Thread Tools Search this Thread Display Modes
  02 February 2013
Run a script on multiple nodes?

I have a problem running a script on multiple nodes

I have a script that analyses the the file location ".object_filename" of an mip_binaryproxy node and removes everything except for the file name.

what I want to do is with multiple mip_binaryproxy nodes selected, run the script on each of the them one by one. I have tried to put the mip_binaryproxy nodes in a loop then run the script but couldn't get it to work.

any help would be much appreciated its probably something easy im missing hopefully
  02 February 2013
Well, just saying 'it doesn't work' doesn't aid in telling us what the problem is. Could you post your code and tell us what exactly isn't working?
  02 February 2013
Hi Nyro

I thought it maybe a simple fix to the top loop?

string $nodes[] = `ls -sl `;
string $currentnode;
string $subStrs[] ;

for ($currentnode in $nodes[]

//This section works on a single selected node//

string $findFileName = "getAttr " + ".object_filename";
string $fullPathFileName = `eval $findFileName`;

$slashNums = `tokenize $fullPathFileName "/" $subStrs` ;
string $extName = $subStrs [$slashNums -1];

setAttr -type "string" (".object_filename") $extName ;

I am not a coder at all really so this is probably completely wrong the top loop seems to be where I am going wrong
  02 February 2013
Don't have Maya in front of me now, so I can't be sure.

But after reading your code I wonder how come it works at all, even for a single object.

The reason, I guess, is that Maya by default uses the objects on the active list if you fail to supply an argument to a command.


// with an argument supplied,
// the translation is applied to the object pSphere1
xform -ws -a -translate 1 0 0 pSphere1;

// without an argument supplied, 
// the translation is applied to any transform node in the selection
xform -ws -a -translate 1 0 0;

In your case, you are using the 'getAttr' command to retrieve an attribute, but you don't specify from which object.

The part up until "for... {" looks ok in your code;here's what the rest shoud look like:

for ($currentNode in $nodes) {
// there was a syntax error in that line in your code; arrays are referenced without the [] brackets
// unless you want to reference a single element within them
	// notice how I use $currentNode so Maya knows what object I want to refer to
	string $filePath = `getAttr ($currentNode + ".object_filename")`;	

	// now we make use of the built-in 'basename' command to extract the filename
	string $fileName = basename($filePath, "");

	// again, use $currentNode to identify which attribute on which object
	setAttr ($currentNode + ".object_filename") -type "string" $fileName;


Last edited by Nyro : 02 February 2013 at 10:35 AM.
  02 February 2013

Thanks man this works like a charm..... been trying to figure this out like I say I am not much of a coder so I basically used echo all commands and google to hash together what I had.

Now I need to understand all of it and get into mel a bit!! It seems so simple now lol

Thanks man!!

Time for me to go and work out how to make a little gui with buttons so that I can build myself a little toolbox of mel scripts
  02 February 2013
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
Society of Digital Artists

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

All times are GMT. The time now is 06:45 AM.

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