View Full Version : Query name of selected display Layer?

10 October 2010, 04:37 PM
I'm trying to write a super simple script that toggles bounding box / full mode for whatever display layer is selected. I have everything else worked out but is there a way to query the display layer's name?



10 October 2010, 07:28 PM
Please try this:

string $selLayer = (`editDisplayLayerGlobals -q -cdl` == "defaultLayer") ? "" : (`editDisplayLayerGlobals -q -cdl`);
if( size( $selLayer ) != 0 )
print( "Selected layer: " + $selLayer );
warning( "Please select 1 layer" );

10 October 2010, 07:59 PM
I'm actually doing this in python, but querying that specific cdl flag spits out the name of the selected display layer. Absolutely awesome, I had no idea, I thought that function had to do with setting or querying a name on creation, or something like that.

Thanks a ton norbertnacu!

10 October 2010, 09:59 PM
This is what I ended up with python wise. Maybe it will be useful. Thanks again

import maya.cmds as cmds lyrName = str(cmds.editDisplayLayerGlobals(q = 1, cdl = 1))
lodVar = cmds.getAttr("%s.levelOfDetail" % (lyrName))
if(lodVar == 0):
cmds.setAttr("%s.levelOfDetail" % (lyrName), 1)
if(lodVar == 1):
cmds.setAttr("%s.levelOfDetail" % (lyrName), 0)

10 October 2010, 10:44 PM
import maya.cmds as cmds
import maya.mel as mel

def SurrealToggle():
status = False
lyrName = str(cmds.editDisplayLayerGlobals(q=1, cdl=1))

if lyrName != "defaultLayer":
cmds.setAttr(("%s.lod"%lyrName), not cmds.getAttr("%s.lod"%lyrName))
mel.eval('error("Please select a valid layer" )')
status = True

return status


CGTalk Moderation
10 October 2010, 10:44 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.