Exclude attributes from locked references

Maya provides MEL procedures that you can use to exclude attributes from the Lock option on referenced files. For example, you can exclude specific, individual attributes, or all attributes of a specified node type. If more control over your exclusions is required, you can even exclude individual attributes on only particular nodes, or exclude all attributes of specific nodes.

These MEL procedures can be found in the scripts\others folder of your Maya installation directory. The follows sections demonstrate how to use these procedures.

For more information on sourcing MEL scripts and working with MEL procedures in general, see MEL and Expressions.

MEL procedure for excluding individual attributes

This example shows you how to create your own MEL procedure to specify which attributes to exclude from the file referencing lock operation. The MEL procedure provided in this example is the same procedure that is distributed with Maya.

  1. Create a MEL file using a text editor, and name the MEL file: getLockReferenceExcludedAttributes.mel.
  2. Add the following text to the file, ensuring you follow the exact syntax:
    global proc string[] getLockReferenceExcludedAttributes()
    {
    // Return a string array containing a list of attributes
    // to be skipped during locking of a referenced file. The
    // listed attributes locked state will remain the same as
    // in the referenced file.
    string $lockReferenceExcludedAttributes[];
    $lockReferenceExcludedAttributes[0] = "visibility";
    return $lockReferenceExcludedAttributes;
    }
    

    Add or remove any $lockReferenceExcludedAttributes[n] lines as necessary to specify the attributes to exclude using the same syntax as in the above example. Ensure that the array indices [n] are consecutive.

  3. Save the MEL file and place it in your Maya script path.

    If you named the MEL file exactly the same as the default one that is distributed with Maya, the Lock option uses this new customized script for locking file references the next time Maya starts.

MEL procedure for excluding individual attributes on a particular node

To exclude individual attributes on a particular node from the lock operation, two MEL procedures wantContextualLockReferencedAttribute and shouldLockReferencedAttribute must be created.

Set wantContextualLockReferencedAttribute to return 1, and specify the exclusion logic in shouldLockReferencedAttribute and set it to return 0.

Note:

These exclusions work on top of the attribute type exclusions specified in getLockReferenceExcludedAttributes() above. In other words, the attributes specified in getLockReferenceExcludedAttributes() are first excluded, then the ones specified in shouldLockReferencedAttribute are excluded.

Full path for the node is required, and must include the namespace and full dag path if it is a DAG node.

  1. Create a MEL file using a text editor, and name the MEL file: getLockReferenceExcludedAttributes.mel.
  2. Add MEL procedure wantContextualLockReferencedAttribute as shown below, and set it to return 1.
  3. Add MEL procedure shouldLockReferencedAttribute as shown below, and specify the attribute(s) for the specific node(s) that you want to exclude from the lock operation, and set the procedure to return 0.

    An example is as follows. In this example, there are 3 scenes: A.ma, B.ma, C.ma, and C.ma references B.ma, and B.ma references A.ma.

    global proc int wantContextualLockReferencedAttribute()
    {
        // By default, only attribute type lock operations are excluded.
        // Return 1 if you want Maya to call the shouldLockReferencedAttribute procedure
        return 1;
    }
    
    global proc int shouldLockReferencedAttribute(string $node, string $attr)
    {
        // Exclude transform node |C:B:A:A 's  translateY and visibility attribute from being locked
        // Return 0 to indicate that these attributes should be unlocked
        if(($node == "|C:B:A:A") && ($attr == "translateY" || $attr == "translate" || $attr == "visibility"))
        {
    
            return 0;
        }
    
        else
        {
            return 1;
        }
    }
  4. Save the MEL file and place it in your Maya script path.

    If you named the MEL file the same as the default one that is shipped with Maya, the Lock option uses this new customized script for locking file references the next time Maya starts.

MEL procedure for excluding attributes by node type

This example shows you how to create your own MEL procedure to specify which attributes get excluded by node type. The MEL procedure provided in this example is the same procedure that is distributed with Maya.

  1. Create your MEL file using your favorite text editor, and name the MEL file: getLockReferenceExcludedNodeTypes.mel.
  2. Add the following text to the file, ensuring you follow the exact syntax:
    global proc string[] getLockReferenceExcludedNodeTypes()
    {
    // Return a string array containing a list of node types 
    // whose attributes should be skipped during locking of a referenced file.
    string $lockReferenceExcludedNodeTypes[];
    $lockReferenceExcludedNodeTypes[0] = "lightLinker";
    $lockReferenceExcludedNodeTypes[1] = "displayLayerManager";
    $lockReferenceExcludedNodeTypes[2] = "displayLayer";
    $lockReferenceExcludedNodeTypes[3] = "renderLayerManager";
    $lockReferenceExcludedNodeTypes[4] = "renderLayer";
    return $lockReferenceExcludedNodeTypes;
    }
    

    Add or remove any $lockReferenceExcludedNodeTypes[n] lines as necessary to specify the attributes by node type using the same syntax as in the above example. Ensure that the array indices [n] are consecutive.

  3. Save the MEL file and place it in your Maya script path.

    If you named the MEL file the same as the default one that is shipped with Maya, the Lock option uses this new customized script for locking file references the next time Maya starts.

MEL procedure for excluding all attributes of specific nodes

In addition to excluding attributes for a general node type, you can also add custom logic to specify the specific node(s) that should be excluded from lock operations. For example, you may only want to unlock the transform and shape nodes of a subset of your referenced nodes.

To exclude all attributes of these specific nodes, two MEL procedures wantContextualLockReferencedNode and shouldLockReferencedNode should be created.

Note:

These exclusions work on top of the node type exclusions specified in getLockReferenceExcludedNodeTypes() above. In other words, the attributes specified in getLockReferenceExcludedNodeTypes() are first excluded, then the ones specified in shouldLockReferencedNode are excluded.

Full path for the node is required, and must include the namespace and full dag path if it is a DAG node.

  1. Create a MEL file using a text editor, and name the MEL file: getLockReferenceExcludedNodeTypes.mel.
  2. Add MEL procedure wantContextualLockReferencedNode as shown below, and set it to return 1.
  3. Add MEL procedure shouldLockReferencedNode as shown below, and specify the node(s) that you want to exclude from the lock operation, and set the procedure to return 0.

    An example is as follows. In this example, there are 3 scenes: A.ma, B.ma, C.ma, and C.ma references B.ma, and B.ma references A.ma.

    global proc int wantContextualLockReferencedNode()
    {
        // By default, only node type lock operations are excluded. 
        // Return 1 if you want Maya to call the shouldLockReferencedNode procedure
        return 1;
    }
    
    global proc int shouldLockReferencedNode(string $node)
    {
        // Exclude transform node "|C:B:B" and its shape node "|C:B:B|C:B:BShape" from being locked
        // Exclude shape node "|C:C|C:CShape" from being locked
        // Return 0 to indicate that these attributes should be unlocked
        if ($node == "|C:B:B" || $node == "|C:B:B|C:B:BShape" || $node == "|C:C|C:CShape")
    	{
    	    return 0;
    	}
    	else
    	{ 
    	    return 1;
    	}
    }
  4. Save the MEL file and place it in your Maya script path.

    If you named the MEL file the same as the default one that is shipped with Maya, the Lock option uses this new customized script for locking file references the next time Maya starts.

Related topics