Home Technical Talk

Maya return object name

polycounter lvl 11
Offline / Send Message
Toast polycounter lvl 11
Hi,

this is driving me crazy.

I have a mesh that is named "Model__321".

How do I query that name?

When I do

`ls -sl`;

Maya also (inconveniently) returns the above group name to which this object is apart of:

Group__127|Model__321

I only want the Model__321 part. How is that possible?

Replies

  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    Generally you will get grouping information as part of your ls query if you have two objects with the same name but under different groups (as with duplicating/instancing groups), because two objects cannot have the same name; appending grouping information as a suffix keeps the names unique.

    To split the grouping information you can tokenize the bar character. The last index in the resulting array will be your object's name, however if you do in fact have multiple objects with the same name, you will get an "more than one object matches name" error when trying to select that object.

    You should get such an error if you try to select an object with the `select` command, if it is in fact sharing the same name elsewhere.
    {
        //stores selection
        string $select[] = `ls -sl`;
        //array for storing tokenized result
        string $buffer[];
        //removes and splits string into sections based on the character(s) in quotes
        tokenize $select[0] "|" $buffer;
        //the last location of the array is the object name
        print $buffer[`size $buffer`-1];
    }
    
  • Toast
    Options
    Offline / Send Message
    Toast polycounter lvl 11
    Thank you Bartalon
Sign In or Register to comment.