View Full Version : Scripting for a referenced model?
01-14-2004, 05:22 PM
I don't know if there's a way around this, but I thought I'd ask.
I made a small script for my rhino project to use when I'm animating him. Based on suggestions I've heard from other people, I'm keeping the rig in one file and referencing it into another file for animation. (so I can implement small changes to the rig if I need to)
The script I wrote uses the name of each object as it appears in the original file, eg. "frontFootControllerL"
But when the rig is referenced, all the names change... eg. "painting_weights06_frontFootControllerL" So the script no longer recognizes the objects it's supposed to be looking for.
Now, I could rewrite the script, simply replacing the old names with the referenced names... but what if I decide to update the rig in a new file called, say, "painting_weights07"? I'd have to change the script again.
Is there any way to avoid this? Any way to tell the script to look at what's referenced and use the original names? Or even to change the names based on the current file reference?
Any help is appreciated... thanks! :)
01-14-2004, 06:13 PM
I don't know how referencing decides to rename nodes, but from what you describe it appears to prepend the name of the file you referenced into. If this is the case, you could have your script query the name of the currently opened file, and store that in a variable that you add to your existing names.
if the file is named "painting_weights06.mb" you query the name of the scene into a string and get back either:
"painting_weights06" or "painting_weights06.mb".
If you get the file extension back, use tokenize to strip off the extension, and then you would just add the name of the scene to the name of your controllers, like this.
select -r ($returnedSceneName+"frontFootControllerL");
Did that make sense, or did I loose you?
01-14-2004, 11:01 PM
Yeah, what you're saying makes sense... I figured it'd be something like that. Only, I think I may have been unclear and you misunderstood (or I'm misunderstanding)...
What's going on is this (simplified for the sake of an example):
There's a banana in file A
The banana has a peel named "peel"
I open a new file called B and reference the banana
The banana now has a peel called "A_peel"
So, it's not the currently open file I need to query, it's the name of the referenced file. And I didn't know how to do that.
But I just found out about the `reference` command, which is, by the way, so logically named that I didn't even think to look under "R" in the MEL help file. :) I'm going to play around with this and then see what I can do about chopping letters of of node names.
01-15-2004, 07:30 AM
I work only with referenced characters. The trick here is to reference the file using a namespace on every node- this will append the names with "<<namespace>>:". Now, to identify these nodes via MEL, you have to incorporate some procedure that can strip the namespace - basically tokenized based on ":". This has always worked for me, even when there are multiple layers of reference in the scene (ie, referencing an already referenced file).
Additionally, commands like `ls "peel" "*:peel"` will return either the referenced "peel" obj, or the original if necessary. It´s fundamental to have a good naming system for this stuff to work.
Let me know if this is unclear to you.
01-15-2004, 07:31 AM
Whoa, that should be "* : p e e l" (with no spaces..damn smilies).
01-15-2004, 08:11 AM
I'm a little unclear as to what you mean by "namespace on every node"
Could I request a quick, *ahem*, banana example?
01-15-2004, 12:33 PM
Could I request a quick, *ahem*, banana example?
Sure. Open your reference option window, select "Use Namespaces", and "Resolve-All Nodes" with "String". Now enter an identifying string for the referenced file, like "rig", for example. Now when you reference your banana.ma file, you´ll see its nodes listed like "rig:banana".
The problem arises when you want to locate this obj in a scene, but you are unsure if it has a namespace or not. If there was no namespace, you could locate the obj like this:
string $obj = `ls "banana"`;
This won´t work if it´s referenced, so you´d need to do this:
string $obj = `ls "*: banana`; (I added a space between : and b because of the darn smilies; you wouldn´t do this in your scene obviously).
So this will return everything called <<namespace>>:banana - hopefully, you only have one object named such in your scene. This is why strict naming conventions are a must in 3d.
So for this, you´re gonna´ need to know how many namespaces are in your scene (the above wouldn´t work if the referenced file itself contained a referenced banana obj).
In one of my scripts (dwPoser.mel, I think), I have a proc which matches referenced names to non-referenced names. This works even with multiple reference depths (ie, referencing a referenced file, etc). For that I tokenized the names by ":", found the last buffer index (see tokenize command if that´s unclear), and matched them up. Works great.
01-15-2004, 12:38 PM
In case I forgot to mention, the above is based exclusively on the notion that the character ":" appears only in a namespaced (referenced) objects. If you deselect namespaces in the reference options, Maya will add a prefix to all referenced nodes, separated by the "_" (underscore) character. This doesn´t work for us, then, because regular Maya obj names *can* contain the underscore character, and therefore we would have no way of knowing which underscores are part of the obj names, and which are added as a reference prefix.
I hope this is clear, and that it answers your questions.
01-17-2006, 05:00 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.
vBulletin v3.0.5, Copyright ©2000-2014, Jelsoft Enterprises Ltd.