ls selection prints output differently

49 views
Skip to first unread message

likage

unread,
Nov 17, 2015, 3:36:18 AM11/17/15
to Python Programming for Autodesk Maya
I have created some locators with hierarchy levels in them, for eg.
locator1
   
|- locator2
       
|- locator3
   
|- locator4
       
|- locator5
       
|- locator6
   
|- locator7
       
|- locator8
       
|- locator9
       
|- locator10

While I am inputting the following code:
import maya.cmds as cmds
sel
= cmds.ls(sl=True)
print sel

When I tried running the code on locator2 (selection includes its children too), instead of getting [u'locator4', u'locator5', u'locator6'] etc as my output, I am getting [u'locator2', u'locator2|locator3'], notice that the latter output seems to give the full path. I am seeing the same result within the list should I be selecting everything too

Can someone tell me why this is so? FYI, I am trying to get each item individual name or is there a better way to deal this?

Mahmoodreza Aarabi

unread,
Nov 17, 2015, 3:45:18 AM11/17/15
to python_in...@googlegroups.com
hey
this locators based on your tree aren't children of locator2:

[u'locator4', u'locator5', u'locator6']

this code just give you everything you select, not their childrens

what exactly you want to print out?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9008456d-acf4-4c9f-80ab-229972aafb6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

likage

unread,
Nov 17, 2015, 3:47:59 AM11/17/15
to Python Programming for Autodesk Maya
Hi there, I using [u'locator4', u'locator5', u'locator6'], using that as an example.. Pardon me if I did not state that clearly.

I am trying to get the same/similar output when you select locator2 but instead, [u'locator2', u'locator2|locator3'] is the result of it
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--


Bests,
madoodia

Mahmoodreza Aarabi

unread,
Nov 17, 2015, 3:51:01 AM11/17/15
to python_in...@googlegroups.com

but when i select just locator2 and run your code it give me [u'locator2'] not its children with fullpath. :)

​

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.



--


Bests,
madoodia

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5898840d-82ee-458f-8b17-e9b0839288e2%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

likage

unread,
Nov 17, 2015, 3:54:09 AM11/17/15
to Python Programming for Autodesk Maya
Select both locator2 and locator3 instead

Mahmoodreza Aarabi

unread,
Nov 17, 2015, 3:56:37 AM11/17/15
to python_in...@googlegroups.com

i did
this is the result [u'locator2', u'locator3']

restart maya and create a new scene, create locator1 and duplicate it a few times then parent together as you want then test the code again

​

On Tue, Nov 17, 2015 at 12:24 PM, likage <dissid...@gmail.com> wrote:
Select both locator2 and locator3 instead

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

Mahmoodreza Aarabi

unread,
Nov 17, 2015, 3:58:29 AM11/17/15
to python_in...@googlegroups.com

if you use long (l) flag, it will return fullpath

import maya.cmds as cmds
sel = cmds.ls(sl=True, l=True)
print sel

result: [u'|locator1|locator2', u'|locator1|locator2|locator3']

​
--


Bests,
madoodia

Mahmoodreza Aarabi

unread,
Nov 17, 2015, 4:00:24 AM11/17/15
to python_in...@googlegroups.com
You can use this for formatting your code in your email:
http://markdown-here.com/
--


Bests,
madoodia

likage

unread,
Nov 17, 2015, 4:05:11 AM11/17/15
to Python Programming for Autodesk Maya
Okay, this is freaking weird now... :/

When I selected locator2, it is actually giving me [u'locator2', u'locator2|locator3'] and not [u'locator2', u'locator3']
Now that I try to recreate the same set of hierarchy as I did, it is working correctly, whether the locators are created newly or duplicated many times from just one..

Nicolas Combecave

unread,
Nov 17, 2015, 4:09:28 AM11/17/15
to python_in...@googlegroups.com
It looks like that you have another locator3 outside this hierarchy in the scene giving you results with a pipe "|"...
Can you try cmds.ls('locator3', l=True), just to be sure you don't have another one burried somewhere?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Mahmoodreza Aarabi

unread,
Nov 17, 2015, 4:13:25 AM11/17/15
to python_in...@googlegroups.com

my tree in outliner is like this

>locator1
    --->locator2
        ---->locator3

and cmds.ls('locator3', l=True) give me this result: [u'|locator1|locator2|locator3']

​


For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

Mahmoodreza Aarabi

unread,
Nov 17, 2015, 4:14:53 AM11/17/15
to python_in...@googlegroups.com
This is logical.
what is the problem?
--


Bests,
madoodia

Mahmoodreza Aarabi

unread,
Nov 17, 2015, 4:20:44 AM11/17/15
to python_in...@googlegroups.com

Nicolas, based on his first post he don’t have locator3 another place

locator1
    |- locator2
        |- locator3
    |- locator4
        |- locator5
        |- locator6
    |- locator7
        |- locator8
        |- locator9
        |- locator10

but if have another one yes he will get full path of that he selected

​
--


Bests,
madoodia

likage

unread,
Nov 17, 2015, 4:30:40 AM11/17/15
to Python Programming for Autodesk Maya
Unfortunately I have killed off that 'problematic' scene but I can be sure that I do not have an extra locator3...
Still trying to find the root cause of why I am getting the [u'locator2', u'locator2|locator3'] initially...
Reply all
Reply to author
Forward
0 new messages