maya.utils.converter.rules_reverse ================================== .. py:module:: maya.utils.converter.rules_reverse .. autoapi-nested-parse:: Conversion rules for maya.cmds → tik.maya transformation. Rules define how specific maya.cmds patterns should be lifted into their tik.maya equivalents. Each rule is a deterministic, testable unit of transformation. This module mirrors the structure of rules.py but operates in the reverse direction: compressing cmds into tik.maya. Attributes ---------- .. autoapisummary:: maya.utils.converter.rules_reverse.UNSUPPORTED_CMDS Classes ------- .. autoapisummary:: maya.utils.converter.rules_reverse.AddAttrToNodeAddAttrRule maya.utils.converter.rules_reverse.ConnectAttrToPlugConnectRule maya.utils.converter.rules_reverse.CreateNodeToTransformRule maya.utils.converter.rules_reverse.CurveToCurveCreateRule maya.utils.converter.rules_reverse.DeleteToNodeDeleteRule maya.utils.converter.rules_reverse.DuplicateToNodeDuplicateRule maya.utils.converter.rules_reverse.GetAttrToPlugGetRule maya.utils.converter.rules_reverse.JointToJointCreateRule maya.utils.converter.rules_reverse.MakeIdentityToFreezeRule maya.utils.converter.rules_reverse.PolyCubeToMeshCreateRule maya.utils.converter.rules_reverse.PolyCylinderToMeshCreateRule maya.utils.converter.rules_reverse.PolyPlaneToMeshCreateRule maya.utils.converter.rules_reverse.PolySphereToMeshCreateRule maya.utils.converter.rules_reverse.RenameToNodeRenameRule maya.utils.converter.rules_reverse.ReverseConversionRule maya.utils.converter.rules_reverse.ReverseRuleContext maya.utils.converter.rules_reverse.ReverseRuleMatch maya.utils.converter.rules_reverse.SelectToNodeSelectRule maya.utils.converter.rules_reverse.SetAttrLockToPlugLockRule maya.utils.converter.rules_reverse.SetAttrToPlugSetRule maya.utils.converter.rules_reverse.SpaceLocatorToLocatorCreateRule Functions --------- .. autoapisummary:: maya.utils.converter.rules_reverse.extract_attr_path_from_arg maya.utils.converter.rules_reverse.extract_kwarg maya.utils.converter.rules_reverse.extract_kwarg_value maya.utils.converter.rules_reverse.extract_string_arg maya.utils.converter.rules_reverse.get_default_reverse_rules maya.utils.converter.rules_reverse.get_unsupported_cmds_reason maya.utils.converter.rules_reverse.is_cmds_call maya.utils.converter.rules_reverse.parse_attr_path Module Contents --------------- .. py:class:: AddAttrToNodeAddAttrRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.addAttr(node, ...) to node.add_attr(...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to node.add_attr(name, ...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.addAttr(...) calls. .. py:attribute:: category :value: 'node_operations' .. py:attribute:: description :value: 'Convert cmds.addAttr() to Node.add_attr()' .. py:attribute:: name :value: 'addattr_to_node_addattr' .. py:class:: ConnectAttrToPlugConnectRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.connectAttr(src, dst) to src_plug.connect(dst_plug). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to src['attr'].connect(dst['attr']). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.connectAttr(...) calls. .. py:attribute:: category :value: 'connections' .. py:attribute:: description :value: 'Convert cmds.connectAttr() to Plug.connect()' .. py:attribute:: name :value: 'connectattr_to_plug_connect' .. py:class:: CreateNodeToTransformRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.createNode('transform', ...) to Transform.create(...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to Transform.create(...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.createNode('transform', ...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: "Convert cmds.createNode('transform') to Transform.create()" .. py:attribute:: name :value: 'createnode_to_transform' .. py:class:: CurveToCurveCreateRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.curve(...) to Curve.create(...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to Curve.create(...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.curve(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: 'Convert cmds.curve() to Curve.create()' .. py:attribute:: name :value: 'curve_to_curve_create' .. py:class:: DeleteToNodeDeleteRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.delete(node) to node.delete(). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to node.delete(). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.delete(...) calls with single node argument. .. py:attribute:: category :value: 'node_operations' .. py:attribute:: description :value: 'Convert cmds.delete() to Node.delete()' .. py:attribute:: name :value: 'delete_to_node_delete' .. py:class:: DuplicateToNodeDuplicateRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.duplicate(node) to node.duplicate(). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to node.duplicate(). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.duplicate(...) calls. .. py:attribute:: category :value: 'node_operations' .. py:attribute:: description :value: 'Convert cmds.duplicate() to Node.duplicate()' .. py:attribute:: name :value: 'duplicate_to_node_duplicate' .. py:class:: GetAttrToPlugGetRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.getAttr('node.attr') to node['attr'].get(). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to node['attr'].get(). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.getAttr(...) calls. .. py:attribute:: category :value: 'attribute_access' .. py:attribute:: description :value: 'Convert cmds.getAttr() to Plug.get()' .. py:attribute:: name :value: 'getattr_to_plug_get' .. py:class:: JointToJointCreateRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.joint(...) to Joint.create(...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to Joint.create(...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.joint(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: 'Convert cmds.joint() to Joint.create()' .. py:attribute:: name :value: 'joint_to_joint_create' .. py:class:: MakeIdentityToFreezeRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.makeIdentity(node, apply=True, ...) to node.freeze(...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to node.freeze(...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.makeIdentity(..., apply=True) calls. .. py:attribute:: category :value: 'transform_operations' .. py:attribute:: description :value: 'Convert cmds.makeIdentity() to Transform.freeze()' .. py:attribute:: name :value: 'makeidentity_to_freeze' .. py:class:: PolyCubeToMeshCreateRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.polyCube(...) to Mesh.create('polyCube', ...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to Mesh.create('polyCube', ...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.polyCube(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: "Convert cmds.polyCube() to Mesh.create('polyCube')" .. py:attribute:: name :value: 'polycube_to_mesh_create' .. py:class:: PolyCylinderToMeshCreateRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.polyCylinder(...) to Mesh.create('polyCylinder', ...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to Mesh.create('polyCylinder', ...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.polyCylinder(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: "Convert cmds.polyCylinder() to Mesh.create('polyCylinder')" .. py:attribute:: name :value: 'polycylinder_to_mesh_create' .. py:class:: PolyPlaneToMeshCreateRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.polyPlane(...) to Mesh.create('polyPlane', ...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to Mesh.create('polyPlane', ...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.polyPlane(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: "Convert cmds.polyPlane() to Mesh.create('polyPlane')" .. py:attribute:: name :value: 'polyplane_to_mesh_create' .. py:class:: PolySphereToMeshCreateRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.polySphere(...) to Mesh.create('polySphere', ...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to Mesh.create('polySphere', ...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.polySphere(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: "Convert cmds.polySphere() to Mesh.create('polySphere')" .. py:attribute:: name :value: 'polysphere_to_mesh_create' .. py:class:: RenameToNodeRenameRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.rename(node, name) to node.rename(name). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to node.rename(name). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.rename(...) calls. .. py:attribute:: category :value: 'node_operations' .. py:attribute:: description :value: 'Convert cmds.rename() to Node.rename()' .. py:attribute:: name :value: 'rename_to_node_rename' .. py:class:: ReverseConversionRule Bases: :py:obj:`abc.ABC` Base class for all cmds → tik.maya conversion rules. A rule defines: - A pattern to match in the AST (cmds calls) - A transformation to apply when matched (tik.maya expression) - Metadata about the rule (name, category, etc.) .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch :abstractmethod: Convert the matched AST node to tik.maya code. Args: node: AST node that matched this rule. context: Context with variable type information. Returns: ReverseRuleMatch with the converted code. .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool :abstractmethod: Check if this rule applies to the given AST node. Args: node: AST node to check. context: Context with variable type information. Returns: True if this rule can convert the node. .. py:attribute:: category :type: str :value: 'general' .. py:attribute:: description :type: str :value: '' .. py:attribute:: name :type: str :value: 'unnamed_reverse_rule' .. py:class:: ReverseRuleContext Context information available during reverse rule matching. Provides access to tracked variable names and their inferred types, allowing rules to make informed decisions about conversions. .. py:method:: get_node_variable(node_name: str) -> Optional[str] Get the variable name for a node string literal. .. py:method:: get_variable_type(name: str) -> Optional[str] Get the tracked type for a variable name. .. py:attribute:: imports :type: Dict[str, str] .. py:attribute:: node_variables :type: Dict[str, str] .. py:attribute:: source_lines :type: List[str] .. py:attribute:: variable_types :type: Dict[str, str] .. py:class:: ReverseRuleMatch Result of a successful reverse rule match. .. py:attribute:: confidence :type: float :value: 1.0 .. py:attribute:: converted_code :type: str .. py:attribute:: node_mappings :type: Optional[Dict[str, str]] :value: None .. py:attribute:: notes :type: Optional[str] :value: None .. py:attribute:: original_node :type: ast.AST .. py:attribute:: rule_name :type: str .. py:class:: SelectToNodeSelectRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.select(node, replace=True) to node.select(). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to node.select(). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.select(...) calls with single node and replace=True. .. py:attribute:: category :value: 'node_operations' .. py:attribute:: description :value: 'Convert cmds.select() to Node.select()' .. py:attribute:: name :value: 'select_to_node_select' .. py:class:: SetAttrLockToPlugLockRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.setAttr('node.attr', lock=True) to node['attr'].lock(). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to node['attr'].lock() or unlock(). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.setAttr(..., lock=True/False) calls. .. py:attribute:: category :value: 'attribute_access' .. py:attribute:: description :value: 'Convert cmds.setAttr(lock=True) to Plug.lock()' .. py:attribute:: name :value: 'setattr_lock_to_plug_lock' .. py:class:: SetAttrToPlugSetRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.setAttr('node.attr', value) to node['attr'].set(value). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to node['attr'].set(value). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.setAttr(...) calls without lock/keyable flags. .. py:attribute:: category :value: 'attribute_access' .. py:attribute:: description :value: 'Convert cmds.setAttr() to Plug.set()' .. py:attribute:: name :value: 'setattr_to_plug_set' .. py:class:: SpaceLocatorToLocatorCreateRule Bases: :py:obj:`ReverseConversionRule` Convert cmds.spaceLocator(...) to Locator.create(...). .. py:method:: convert(node: ast.AST, context: ReverseRuleContext) -> ReverseRuleMatch Convert to Locator.create(...). .. py:method:: matches(node: ast.AST, context: ReverseRuleContext) -> bool Match cmds.spaceLocator(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: 'Convert cmds.spaceLocator() to Locator.create()' .. py:attribute:: name :value: 'spacelocator_to_locator_create' .. py:function:: extract_attr_path_from_arg(arg: ast.AST) -> Tuple[Optional[str], Optional[str]] Extract node and attribute from a string argument or f-string. Handles: - 'nodeName.attrName' - f'{var}.attrName' - f'{var}.{attr}' Args: arg: AST node for the argument. Returns: Tuple of (node_expr, attr_name) or (None, None). .. py:function:: extract_kwarg(node: ast.Call, kwarg_name: str) -> Optional[ast.AST] Extract a keyword argument from a call node. Args: node: Call AST node. kwarg_name: Name of the keyword argument. Returns: The AST node for the value if found, None otherwise. .. py:function:: extract_kwarg_value(node: ast.Call, kwarg_name: str) -> Optional[str] Extract a keyword argument value as a string. Args: node: Call AST node. kwarg_name: Name of the keyword argument. Returns: The string representation of the value if found. .. py:function:: extract_string_arg(node: ast.AST, index: int = 0) -> Optional[str] Extract a string argument from a call node. Args: node: Call AST node. index: Argument index. Returns: The string value if found, None otherwise. .. py:function:: get_default_reverse_rules() -> List[ReverseConversionRule] Return the default set of reverse conversion rules. Returns: List of ReverseConversionRule instances in priority order. .. py:function:: get_unsupported_cmds_reason(func_name: str) -> Optional[str] Get the reason why a cmds function is unsupported. Args: func_name: The cmds function name. Returns: The reason string if unsupported, None otherwise. .. py:function:: is_cmds_call(node: ast.AST, func_name: str) -> bool Check if node is a cmds.func_name() call. Args: node: AST node to check. func_name: The cmds function name (e.g., 'createNode'). Returns: True if this is a cmds.func_name() call. .. py:function:: parse_attr_path(attr_path: str) -> Tuple[Optional[str], Optional[str]] Parse a 'node.attribute' path string. Args: attr_path: Attribute path like 'pCube1.translateX'. Returns: Tuple of (node_name, attr_name) or (None, None) if invalid. .. py:data:: UNSUPPORTED_CMDS