Modify layer override values (without render layer change)

604 views
Skip to first unread message

jacob...@gmail.com

unread,
Oct 28, 2014, 5:41:35 AM10/28/14
to python_in...@googlegroups.com
Hi all

Does anyone know any scripting to change a layer override attribute value without actually having that render Layer active?

So active Render Layer is A and I am going to set an objects primary ray off/on for Render Layer B.

Thanks

Jacob

Justin Israel

unread,
Oct 29, 2014, 5:52:48 PM10/29/14
to python_in...@googlegroups.com

Sorry no one has replied to this. I will take a stab. Do you mean how to change RenderLayer Member Overrides, programmatically?

Like this?

cmds.setAttr("layer1.attributeOverrideScript", "primaryVisibility=", type="string")

cmds.setAttr("layer1.attributeOverrideScript", "primaryVisibility=0", type="string")

cmds.setAttr("layer1.attributeOverrideScript", "primaryVisibility=1", type="string")


--
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/44926a6c-88b8-4b0a-a7b0-630281b1d91b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Fredrik Averpil

unread,
Oct 30, 2014, 3:31:45 AM10/30/14
to python_in...@googlegroups.com

I usually do it like this (sort of):

current_layer = cmds.editRenderLayerGlobals( query=True, currentRenderLayer=True ) # Register the currently active render layer
cmds.editRenderLayerGlobals(currentRenderLayer='renderLayerA') # step to renderLayerA
cmds.setAttr('vraySettings.primaryEngine', 0) # Set some value
cmds.editRenderLayerAdjustment('vraySettings.primaryEngine') # Create the override
...
...
...
cmds.editRenderLayerGlobals(currentRenderLayer=current_layer) # Step back to the renderlayer you had active before running the script

Jacob Gonzalez

unread,
Oct 30, 2014, 7:02:50 AM10/30/14
to python_in...@googlegroups.com
Thanks for the replies

changing render layers it's exactly what I am trying to avoid as it would significantly slow down the tool I am working on. 

I can query the layer overrides from a different layer. For example:

Curr Layer is A:

print cmds.getAttr("B.adjustments[1].value")  / / return 1

But I cannot change the value of B.adjustments[1] unless I have layer B as the active layer

Thanks

J

On Thursday, 30 October 2014 07:31:45 UTC, Fredrik Averpil wrote:

I usually do it like this (sort of):

current_layer = cmds.editRenderLayerGlobals( query=True, currentRenderLayer=True ) # Register the currently active render layer
cmds.editRenderLayerGlobals(currentRenderLayer='renderLayerA') # step to renderLayerA
cmds.setAttr('vraySettings.primaryEngine', 0) # Set some value
cmds.editRenderLayerAdjustment('vraySettings.primaryEngine') # Create the override
...
...
...
cmds.editRenderLayerGlobals(currentRenderLayer=current_layer) # Step back to the renderlayer you had active before running the script
On Wed, Oct 29, 2014 at 10:52 PM, Justin Israel <justin...@gmail.com> wrote:

Sorry no one has replied to this. I will take a stab. Do you mean how to change RenderLayer Member Overrides, programmatically?

Like this?

cmds.setAttr("layer1.attributeOverrideScript", "primaryVisibility=", type="string")

cmds.setAttr("layer1.attributeOverrideScript", "primaryVisibility=0", type="string")

cmds.setAttr("layer1.attributeOverrideScript", "primaryVisibility=1", type="string")
On Tue, Oct 28, 2014 at 10:41 PM, <jacob...@gmail.com> wrote:
Hi all

Does anyone know any scripting to change a layer override attribute value without actually having that render Layer active?

So active Render Layer is A and I am going to set an objects primary ray off/on for Render Layer B.

Thanks

Jacob

--
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_maya+unsub...@googlegroups.com.

--
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_maya+unsub...@googlegroups.com.

Fredrik Averpil

unread,
Oct 30, 2014, 7:11:03 AM10/30/14
to python_in...@googlegroups.com
I may be wrong here but as far as I know you need the renderlayer you wish to modify to be the currently active renderlayer.

Regards,
Fredrik

Jacob Gonzalez

unread,
Oct 30, 2014, 8:08:36 AM10/30/14
to python_in...@googlegroups.com
by the looks of it, you are right. 

so basically, what I'd like to achieve can't be done!

Thans

Felipe Ruiz

unread,
Dec 17, 2015, 7:30:10 PM12/17/15
to Python Programming for Autodesk Maya
It can be done. It's not fool proof but it'll get you working with float values

def get_attr_in_layer(attr=None, layer=None):
    """
    Same as cmds.getAttr but this gets the attribute's value in a given render layer without having to switch to it
    :param attr: string - ex: "node.attribute"
    :param layer: string - ex: "layer_name"
    :return: multi - can return any objects
    """
    connection_list = cmds.listConnections(attr, plugs=True)
    if connection_list is None:
        return cmds.getAttr(attr)
    for connection in connection_list:
        attr_component_list = connection.split(".")
        if attr_component_list[0] == layer:
            attr = ".".join(attr_component_list[0:-1])
            print attr
            return cmds.getAttr("%s.value" % attr)
    return cmds.getAttr(attr)

def set_attr_in_layer(attr=None, layer=None, value=None):
    """
    Same as cmds.setAttr but this sets the attribute's value in a given render layer without having to switch to it
    :param attr: string - ex: "node.attribute"
    :param layer: string - ex: "layer_name"
    :param value: value you want to set the override to
    :return: bool - True if successful, False if not
    """
    cmds.editRenderLayerAdjustment(attr, layer=layer)
    connection_list = cmds.listConnections(attr, plugs=True)
    if connection_list is not None:
        for connection in connection_list:
            attr_component_list = connection.split(".")
            if attr_component_list[0] == layer:
                attr = ".".join(attr_component_list[0:-1])
                cmds.setAttr("%s.value" % attr, value)
                return True
    return False

Fredrik Averpil

unread,
Mar 17, 2016, 5:19:30 AM3/17/16
to python_in...@googlegroups.com

Old thread, but I stumbled upon this recently.

Thanks to the layer.adjustments hint from Justin in this thread, I’m now fetching overrides without stepping to a renderlayer (yay!):

def get_overrides(layer):
    overrides = {}
    c = 0
    for plug in cmds.listConnections(layer+'.adjustments', destination=False, source=True, plugs=True):
        print 'Override found:', plug
        adjusted_values = []
        attr_values = cmds.getAttr(layer+'.adjustments[' + str(c) + ']')
        for attr_value in attr_values:
            unadjusted_value = attr_value[0]
            adjusted_value = attr_value[1]
            adjusted_values.append(adjusted_value)
        overrides[plug] = adjusted_values
        c += 1
    return overrides

overrides = get_overrides(layer='defaultRenderLayer')

Right now, this function returns any overrides for the given render layer.

Figured I’d share this.

Cheers,
Fredrik

Justin Israel

unread,
Mar 17, 2016, 5:46:30 AM3/17/16
to python_in...@googlegroups.com

Looking at the history it seems the others offered far more than I did on this one.


--
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/CAD%3DwhWMEgRHkY3BkAfMC9%2B_xR53bVsOmMGsvcz7xOY4B40Nt1A%40mail.gmail.com.

Fredrik Averpil

unread,
Mar 17, 2016, 7:31:28 AM3/17/16
to python_in...@googlegroups.com

Just stumbled upon a weird one.

When you cmds.getAttr('defaultRenderglobals.endframe') you get e.g. 1, if your end frame is set to 1.

However, and this is the weird part, if you have an override in a render layer and you use the snipped I just previously posted to fetch it, you won’t get an integer back. Instead you’ll get a float. At first glance it looks like you’re getting 1/25 of the actual value back. But if you try different endframe values, you’ll see that this factor changes.

Does anyone on here know how this value is actually stored in Maya?

Cheers,
Fredrik

tokej...@gmail.com

unread,
Apr 14, 2016, 3:39:59 PM4/14/16
to Python Programming for Autodesk Maya
Just wanted to chime in on this. The time values in the adjustments are divided by the frame rate, ei 10 frame / 25 frame/sec = 0.4 sec.

Here is a script for setting the attribute values: https://gist.github.com/tokejepsen/f5315c0e7f9de22a5b319374d9700774

And one for getting the values: https://gist.github.com/tokejepsen/c674146a5565893b9085898fef005377
Reply all
Reply to author
Forward
0 new messages