Python for Maya: Change Display Layer to "Reference"

Question:

Is there a way to set a display layer’s layer state to reference using python? It doesn’t matter if the change happens at the layer’s creation, or after the fact.

To provide a little context: I’m writing a script that creates image planes, pulls in a reference image with a ‘standardized’ image name, applies it to the image plane, moves them into place, and creates a display layer with it’s state set to reference. So far, everything but setting the layer’s state to reference is working.

This is an example of what I’m doing:

    front_ip = cmds.imagePlane(
    name="front_IP",
    fileName="front_ref.jpg",
    lookThrough="front",
    showInAllViews=False)
    cmds.move(0,0,-950)
    cmds.createDisplayLayer(name="front_ref_L")
Asked By: TurtlesAndBacon

||

Answers:

As far as I know you can’t change a display layer to reference exactly at creation, but you can use setAttr to do it afterwards:

cmds.polySphere() # Create a sphere.
layer = cmds.createDisplayLayer() # Create a layer and add selected sphere.
cmds.setAttr("{}.displayType".format(layer), 2) # Change layer to reference.
Answered By: Green Cell

Where did you find your method of creating? The below code works but it needs a delay before running the reference code.

layer = cmds.createDisplayLayer()
cmds.layerButton(layer, edit=True, layerState='reference')
Answered By: Keerthy Kumar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.