Display Layer Editor / get selected layers

72 views
Skip to first unread message

johan Borgström

unread,
Sep 30, 2020, 2:45:53 AM9/30/20
to Python Programming for Autodesk Maya
Hi,
I am trying to get the selected display layer.
I know you can get the display layers with:

pm.ls(type='displayLayer')

But that just returns a list of the available layers. As far as I could see there were no attribute on the returned layers to hold info whether they were "selected" or not. So I am guessing I need to get that info from the "layer editor itself".

Should be quite straightforward, but I havent found any good docs on how to do this, any tips?

Cheers, Johan

David Moulder

unread,
Sep 30, 2020, 11:47:08 AM9/30/20
to python_inside_maya
Hi Johan,

getLayerSelection "Display" is the MEL command you need

Regards

-Dave

--
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/7a508a51-5b35-48bc-9934-7e59314a6a0an%40googlegroups.com.


--

johan Borgström

unread,
Sep 30, 2020, 12:42:43 PM9/30/20
to Python Programming for Autodesk Maya
Hi Dave,

Thanks a lot!

Regards, Johan

johan Borgström

unread,
Oct 3, 2020, 7:18:34 AM10/3/20
to Python Programming for Autodesk Maya
Hi,

I am trying to set layer visibility, tried both pymel and cmds:

import pymel.core as pm

layer = pm.PyNode('layer1')
layer.visibility.set(True)
print layer.visibility.get()
# True

import maya.cmds
cmds.setAttr('layer1.visibility', True)
print cmds.getAttr('layer1.visibility')
# True

The layer visibility is set but the display layer editor won´t reflect this. Is this a bug? Do I need to call an "refresh/update" on the editor or set the vis "through" the editor object somehow...

Regards, Johan





Neil Roche

unread,
Oct 21, 2020, 9:14:25 AM10/21/20
to Python Programming for Autodesk Maya
Hi Johan,

You need to use the layerButton command after setting the visibility of the layer:

layer = pm.PyNode('layer1')
layer.visibility.set(False)
layerVisibility =  layer.visibility.get()
# True
layerButton(layer, e = True, layerVisible = layerVisibility)

johan Borgström

unread,
Oct 21, 2020, 1:33:18 PM10/21/20
to Python Programming for Autodesk Maya
Hi Neil,

Thank you very much!

johan Borgström

unread,
Oct 22, 2020, 2:56:56 AM10/22/20
to Python Programming for Autodesk Maya
Hi again,

Regarding the "getLayerSelection" MEL script. I had a look at the proc found in: (C:/Program Files/Autodesk/Maya2019/scripts/startup/layerEditor.mel) and it seems like it loops through the layer editor and appends the selected layers to an array which is then returned. This means that we can not get the layers in the order they were selected. Can this be done someway? (Not super important but interesting to know)

BR,
Johan

Reply all
Reply to author
Forward
0 new messages