script create display layer automatically


#1

Hi everyone !
I hope someone can help me with this… :slight_smile:

In Maya I would like to create some Display Layer automatically, one for each object I have in the scene.

per example:
in the scene I have: -character1 -character2 -environment

If someone want to share his knowledge of scripting I would be very grateful !
cheers !


#2

Do it manually and look in the script editor and see what the command looks like. If you are new to scripting then you might have to read up on that.

In this case the command you need is “createDisplayLayer”.
There are some simple examples in the manual.
Here is a slightly more complex one using python.

import pymel.core as pm
for obj in pm.ls(type='transform'):
    pm.createDisplayLayer(obj, name=obj.name()+'_dl', nr=True)

David


#3

Awesome ! thanks ! your script works great ! :slight_smile:

My only concern now is that it creates layer even for the default Maya cameras (persp, front , side, top)

I’m trying to give him this command line to delete those layer after created:
“delete persp_dl;”

but its not working, I guess because its in mel and not in phyton… Can you help me with the correct syntax ?


#4

oook I think I did it :smiley:

It works… but professionally talking: is it correct ?

import pymel.core as pm
for obj in pm.ls(type=‘transform’):
pm.createDisplayLayer(obj, name=obj.name()+’_dl’, nr=True);

cmds.delete( ‘front_dl’)
cmds.delete( ‘persp_dl’)
cmds.delete( ‘side_dl’)
cmds.delete( ‘top_dl’)

thank you for the help ! :bowdown:


#5

Professionally speaking I’d have to say if it works then it is correct :wink:
You should spend a bit of time learning some basic scripting. It can save you so much time even if you only use it to write a few lines and save some repetitive manual labour.

Here is one of many possible ways to get a list of objects while filtering out certain types.

import pymel.core as pm
objects = pm.ls(type='transform')
typesToExclude = ['camera', 'nurbsSurface', 'empty group']
for o in list(objects):
    if o.type() in typesToExclude:
        pass
    elif o.getShape() and o.getShape().type() in typesToExclude:
        pass
    elif not o.listRelatives() and 'empty group' in typesToExclude:
        pass
    else:
        continue
    objects.remove(o)
        
print objects

David


#6

yeah you right, I’m an Animator but I would definitely try to learn more about scripting. :keenly:

Now I have a problem… the script used to works on my test scene because I created just few geometry, but in my shots is not working because it will create layer for EVERY objects I have in the outliner (this mean all characters joints and ctrls ecc…)
… ops… :frowning:

Is there a way to point it just to the higher hierarchy node ?


#7

Do you need it to be completely automatic?

If it was me, I would prefer something that would allow me to select all the nodes I need from the outliner and click a button to create a layer for each thing I selected.

So in your case, just select those top level groups and run this.

import pymel.core as pm
for obj in pm.selected():
    pm.createDisplayLayer(obj, name=obj.name()+'_dl', nr=True)

David


#8

No It doesn’t :slight_smile:

I think the last script you wrote is PERFECT !!

thanks a lot !! :bowdown: