PDA

View Full Version : getting the resulting namespace of an imported reference


gmask
01-07-2009, 12:19 AM
say you use a mel command like so to reference a file

$result`file -r -type "mayaBinary" -gl -loadReferenceDepth "all" -namespace "man" -options "v=0" "c:/man.mb"`;

the result you get is "c:/man.mb"

however say you retrieve two

then the result you get is "c:/man.mb{1}"

In either case this does not tell me the the file it loaded is called man:man_CTRL & man1:man_CTRL

The problem is I need to have this references imported via a script and I don't know how many references may have allready been loaded and maya does not select what it just referenced so I'm thinking I'm really gonna have to jump through some hoops to figure out what the actual nodes are called.

I guess since I know that the namespace is "man" and I do know that the root node is :man_CTRL" that I can then parse the result to extract the {1} and come up with man1:man_CTRL .. argh

gmask
01-07-2009, 12:27 AM
ok this works well enough

$result=`file -r -type "mayaBinary" -gl -loadReferenceDepth "all" -namespace "man" -options "v=0" "c:/manrig.mb"`;


string $buffer[];
tokenize $result "{" $buffer;

string $buffer1[];
tokenize $buffer[1] "}" $buffer1;

print("\nman"+$buffer1[0]+":man_CTRL\n");

//result: man1:man_CTRL

gmask
01-08-2009, 12:00 AM
bah this doesn't work...

if you go back and delete some of the referneces the resulting numbers appending here does not match.

for now my solution is a node that keeps track of the last number used and to increment them manually so that no matter what gets deleted the next number used is higher

gmask
01-16-2009, 09:54 PM
one thing I noticed is that when you plan on having numerous copies of the same reference allways give it a name space that ends with a number... such mycharacter1

trancor
01-17-2009, 08:19 PM
Hey gmask, I've gone through a few problems like this and made huge round about ways of figuring out the name space through the tokenize command like you've tried so far.

Easiest thing I ended up doing is reference all of my references, then put them in their own group, that way you can do a `listRelatives -c` on that group and get all of the references you have. Then you can just tokenize ":" to find the namespace. Think this might work for you?

gmask
01-17-2009, 08:56 PM
That wouldn't really work for what I'm doing because after the script imports it it needs to connect some of it's nodes to other referenced nodes.

The one thing I figured out is that if you give a reference a namespace like "myref" and then it makes myref, myref1, myref2 and you go back and delete myref1 then import another one things get messed up.

Currently my script checks to see if the name exists but for some reason if any of them are named without a number and you let maya increment the number then trouble is on it's way.

trancor
01-17-2009, 09:06 PM
Know whats funny, this is one reason why I keep reloading my references (from the other forum topic), and having it take for ever to load because I'll run into issues like this, delete a ref and it doesn't change the numbering.


Is there a way you might be able to set up a script to change the attributes of a current ref you want to delete so it basically turns it into a different ref with a different seed or translates/rotates or what have you instead of deleting and rereferencing new guys?

sj_bee
04-09-2009, 01:28 PM
one thing that i do is use the fact that when you reference a file, it will straight away select the top node in the referenced file, so you can get the namespace from that
eg

file -r -type "mayaBinary" -gl -loadReferenceDepth "all" -namespace "man" -options "v=0" "c:/man.mb";
//get the selected group name
$selected = `ls -sl`;
//get the referenced children
$child = `listRelatives -c $selected[0]`;
//get the namespace of the child
$namespace = `match ".*:" $child[0]`;
or another thing that i do is generate a unique namespace before i reference a file, then i know that maya is not going to append any numbers or anything to the end
i generally use letters as suffixes to the namespace as maya can increment numbers if there is a namespace clash
eg

string $letters[] = {"A", "B", "C", "D", "E"};
string $baseNamespace= "man";
string $namespace = "manA";
int $counter = 0;
//loop until a namespace is unique
while(`namespace -exists $namespace`)
{
$namespace = ($baseNamespace + $letter[$counter]);
$counter += 1;
}
//then do reference using the unique namespace
file -r -type "mayaBinary" -gl -loadReferenceDepth "all" -namespace $namespace -options "v=0" "c:/man.mb";

of course using letters limits you to 26 (or in this example, 5) references with the same $baseNamespace. I got over this problem by adding a tool that will generate all the combinations of a certain length using a set of letters, such as the alphabet. so using one letter as a suffix to the namespace you have 26 options, then if these are all used you can use 2 letters (another 676 options) or 3 letters (another 17576 options) etc

by the way, if you reference in a file and then un reference it, the namespace it used still stays in the scene. this is why unloading the reference with the "man1" namespace will still cause the "man2" namespace to be used for the next reference, even though there are currently no objects in the scene prefixed "man1:".

you can get round this by deleting the namespace
namespace -removeNamespace "man1";
but this will fail if the namespace is still being used

sivanny
04-09-2009, 05:33 PM
Have you tried to use `file -q -namespace`? If you give it the filename (so, "c:/man.mb{1}") it should tell you which namespace it put the nodes into.

So, something like,

string $refFile = `file -r -ns "cube" "cube.ma"`;
print ($refFile + " was referenced into namespace " + `file -q -ns $refFile`);

will give you,

C:/My Documents/maya/projects/default/scenes/cube.ma{3} was referenced into namespace cube4

This will only work with references though. It won't work if you import a file with the file -import flag.

CGTalk Moderation
04-09-2009, 05:33 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.