how to convert locator to groups?

how to convert locator to groups?

gebert
Participant Participant
4,007 Views
10 Replies
Message 1 of 11

how to convert locator to groups?

gebert
Participant
Participant

Hello, in Blender can not create groups. If you open a Blender scene in Maya they are all locators.
How can I use Mel to convert all the locators of a Blender scene into groups?
The outline hierarchy that remains the same.

0 Likes
Accepted solutions (1)
4,008 Views
10 Replies
Replies (10)
Message 2 of 11

Kahylan
Advisor
Advisor

Hi!

 

This is rather easy to do because in Maya Locators are basically a group/transform node with a locator shape. All locator specific attributes are stored on the shape-node. So if you delete the shapes the locators turn into groups without changing the hierarchy.

 

You can do this using the ‚listRelatives‘ command on the object highest in the hierarchy to search all shapes and the using the ‚attributeQuery‘ command to look for one of the locator specific attributes on the shape. And then delete those shapes.

 

I hope this helps!

Message 3 of 11

gebert
Participant
Participant

can post an example of this?

0 Likes
Message 4 of 11

Kahylan
Advisor
Advisor

You asked for MEL and thats a language that I don't code in, so I can't help you with that.

But heres how to do it in Python:

import maya.cmds as mc

def  locToGRP():
    
    sel = mc.ls(selection = True)[0]
    children = mc.listRelatives(sel, ad = True)or []

    for c in children:
        if mc.objectType(c, isType = 'locator') == True and mc.attributeQuery("localScaleX",n = c, ex= True )== True:
            mc.delete(c)
            
locToGRP()

 Select the highest object in your hierachy an run the script from a python tab in the Script Editor. That should solve your problem.

 

Have a nice day

Message 5 of 11

Kahylan
Advisor
Advisor

I just realised that only the locator shape has objectType 'locator' so the attributeQuery isn't needed:

import maya.cmds as mc

def  locToGRP():
    
    sel = mc.ls(selection = True)[0]
    children = mc.listRelatives(sel, ad = True)or []

    for c in children:
        if mc.objectType(c, isType = 'locator') == True:
            mc.delete(c)
            
locToGRP()
Message 6 of 11

gebert
Participant
Participant

Thanks for your help, unfortunately I only have the LT version without Python support 😞

 

I will try to write your example on mel.


Maybe there is someone else who can write an example in mel.

thanks again for your help this helped me a lot

Message 7 of 11

Kahylan
Advisor
Advisor
Accepted solution

I see. If you work with Maya LT, learing the basics of MEL is rather important, because there isn't too many people that code in MEL anymore since Python and C++ are a lot more dynamic and powerful.

But I tried to dust of my MEL for this one, since it very simple:

string $sel[] = `ls -sl`;
string $obj = $sel[0];
string $children[] = `listRelatives -ad $obj`;

for($c in $children){

    $t = `objectType -isType "locator" $c`;
    print($t);
    if($t){
       delete($c);
    }
}

It's not really good form since it should optimally be all packaged in a function which then is called. But I couldn't get that to work in MEL for the life of me.

But that is not too important for such a standalone script that goes into a shelf button. And the script works. So there you go!

Have a nice day

Message 8 of 11

abogoev
Explorer
Explorer

Got curious to try it myself. This worked for me:

proc deleteLocatorShapes() {
    string $sel[] = `ls -sl`;
    string $obj = $sel[0];
    string $children[] = `listRelatives -ad $obj`;
    for($c in $children){
        $t = `objectType -isType "locator" $c`;
        print($t);
        if($t){
           delete($c);
            }
        }
    }

deleteLocatorShapes();

MEL syntax is hard! haha

 

Message 9 of 11

Kahylan
Advisor
Advisor

Ah cool, so thats how it is done!
I forgot to add the () brackets before opening the function.
Now that I see it, it's seems obvious. xD
Your script is way better form than mine!
Thumbs up

Message 10 of 11

gebert
Participant
Participant

Thanks it works

Message 11 of 11

mcw0
Advisor
Advisor

You can streamline this a lot by adding the type to the "listRelatives" command.  🙂 

 

delete `listRelatives -ad -type "locator"`