
Maya 提供了许多 MEL 程序。您可以使用这些程序从被引用文件上的“锁定”(Lock)选项中排除属性。例如,可以排除指定节点类型的特定属性、单个属性或所有属性。如果需要更好地控制排除,您甚至可以仅排除特定节点上的单个属性,或者排除特定节点的所有属性。
可以在 Maya 安装目录的 scripts\others 文件夹中找到这些 MEL 程序。以下部分介绍如何使用这些程序。
有关源 MEL 脚本和使用常用 MEL 程序的详细信息,请参见 MEL 和表达式。
该示例介绍了如何创建自己的 MEL 程序,以指定要从文件引用锁定操作中排除的属性。该示例中提供的 MEL 程序与 Maya 附带的程序相同。
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;
}
 
			 根据需要,添加或移除任何 $lockReferenceExcludedAttributes[n] 行,以使用与上述示例相同的语法指定要排除的属性。确保数组索引 [n] 是连续的。
如果使用与 Maya 分发的默认名称相同的名称命名该 MEL 文件,“锁定”选项将在下次启动 Maya 时,请使用该新自定义脚本来锁定文件引用。

若要从锁定操作中排除特定节点上的单个属性,必须创建 wantContextualLockReferencedAttribute 和 shouldLockReferencedAttribute 这两个 MEL 程序。
将 wantContextualLockReferencedAttribute 设置为返回 1,然后在 shouldLockReferencedAttribute 中指定排除逻辑并将其设置为返回 0。
这些排除将在上述 getLockReferenceExcludedAttributes() 中指定的属性类型排除基础上起作用。换句话说,系统将先排除 getLockReferenceExcludedAttributes() 中指定的属性,然后再排除 shouldLockReferencedAttribute 中指定的属性。
需要节点的完整路径,如果是 DAG 节点,则必须包含名称空间和完整 DAG 路径。
示例如下。在本示例中,有 3 个场景:A.ma、B.ma、C.ma,C.ma 引用 B.ma 且 B.ma 引用 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;
    }
}
 
		  如果使用与 Maya 附带的默认名称相同的名称命名该 MEL 文件,“锁定”(Lock)选项将在下次启动 Maya 时,请使用该新自定义脚本来锁定文件引用。
该示例介绍如何创建自己的 MEL 程序,以按节点类型指定要排除的属性。该示例中提供的 MEL 程序与 Maya 附带的程序相同。
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;
}
 
			 根据需要,添加或移除任何 $lockReferenceExcludedNodeTypes[n] 行,以使用与上述示例相同的语法按节点指定属性。确保数组索引 [n] 是连续的。
如果使用与 Maya 附带的默认名称相同的名称命名该 MEL 文件,“锁定”(Lock)选项将在下次启动 Maya 时,请使用该新自定义脚本来锁定文件引用。
除了排除通用节点类型的属性之外,还可以添加自定义逻辑,以指定应从锁定操作中排除的特定节点。例如,您可能仅需要解除锁定部分被引用节点的变换节点和形状节点。
若要排除这些特定节点的所有属性,则应创建 wantContextualLockReferencedNode 和 shouldLockReferencedNode 这两个 MEL 程序。
这些排除将在上述 getLockReferenceExcludedNodeTypes() 中指定的节点类型排除基础上起作用。换句话说,系统将先排除 getLockReferenceExcludedNodeTypes() 中指定的属性,然后再排除 shouldLockReferencedNode 中指定的属性。
需要节点的完整路径,如果是 DAG 节点,则必须包含名称空间和完整 DAG 路径。
示例如下。在本示例中,有 3 个场景:A.ma、B.ma、C.ma,C.ma 引用 B.ma 且 B.ma 引用 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;
	}
}
 
		  如果使用与 Maya 附带的默认名称相同的名称命名该 MEL 文件,“锁定”(Lock)选项将在下次启动 Maya 时,请使用该新自定义脚本来锁定文件引用。