maya.utils.converter.rules ========================== .. py:module:: maya.utils.converter.rules .. autoapi-nested-parse:: Conversion rules for tik.maya → maya.cmds transformation. Rules define how specific tik.maya patterns should be expanded into their maya.cmds equivalents. Each rule is a deterministic, testable unit of transformation. Rule categories: 1. Language-level expressions (always convertible) 2. Blessed helpers (explicitly registered, opt-in) Classes ------- .. autoapisummary:: maya.utils.converter.rules.ConversionRule maya.utils.converter.rules.CurveCreateRule maya.utils.converter.rules.DagNodeSelectRule maya.utils.converter.rules.JointCreateRule maya.utils.converter.rules.LocatorCreateRule maya.utils.converter.rules.MeshCreateRule maya.utils.converter.rules.NodeAddAttrRule maya.utils.converter.rules.NodeDeleteRule maya.utils.converter.rules.NodeDuplicateRule maya.utils.converter.rules.NodeRenameRule maya.utils.converter.rules.PlugConnectRule maya.utils.converter.rules.PlugGetRule maya.utils.converter.rules.PlugLockRule maya.utils.converter.rules.PlugRshiftRule maya.utils.converter.rules.PlugSetRule maya.utils.converter.rules.PlugUnlockRule maya.utils.converter.rules.PlugValueGetRule maya.utils.converter.rules.PlugValueSetRule maya.utils.converter.rules.ResolveRule maya.utils.converter.rules.RuleContext maya.utils.converter.rules.RuleMatch maya.utils.converter.rules.TransformCreateRule maya.utils.converter.rules.TransformFreezeRule maya.utils.converter.rules.TransformPropertySetRule Functions --------- .. autoapisummary:: maya.utils.converter.rules.get_default_rules Module Contents --------------- .. py:class:: ConversionRule Bases: :py:obj:`abc.ABC` Base class for all conversion rules. A rule defines: - A pattern to match in the AST - A transformation to apply when matched - Metadata about the rule (name, category, etc.) .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch :abstractmethod: Convert the matched AST node to maya.cmds code. Args: node: AST node that matched this rule. context: Context with variable type information. Returns: RuleMatch with the converted code. .. py:method:: matches(node: ast.AST, context: RuleContext) -> 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_rule' .. py:class:: CurveCreateRule Bases: :py:obj:`ConversionRule` Convert Curve.create() to cmds.curve(...). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.curve(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match Curve.create(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: 'Convert Curve.create() to cmds.curve' .. py:attribute:: name :value: 'curve_create' .. py:class:: DagNodeSelectRule Bases: :py:obj:`ConversionRule` Convert node.select() to cmds.select(node, replace=True). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.select(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node.select() patterns. .. py:attribute:: category :value: 'node_methods' .. py:attribute:: description :value: 'Convert DagNode.select() to cmds.select' .. py:attribute:: name :value: 'dagnode_select' .. py:class:: JointCreateRule Bases: :py:obj:`ConversionRule` Convert Joint.create() to cmds.joint(...). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.joint(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match Joint.create(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: 'Convert Joint.create() to cmds.joint' .. py:attribute:: name :value: 'joint_create' .. py:class:: LocatorCreateRule Bases: :py:obj:`ConversionRule` Convert Locator.create() to cmds.spaceLocator(...). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.spaceLocator(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match Locator.create(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: 'Convert Locator.create() to cmds.spaceLocator' .. py:attribute:: name :value: 'locator_create' .. py:class:: MeshCreateRule Bases: :py:obj:`ConversionRule` Convert Mesh.create() to cmds.poly* or cmds.createNode('mesh', ...). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to appropriate cmds call. .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match Mesh.create(...) calls. .. py:attribute:: POLY_PRIMITIVES .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: 'Convert Mesh.create() to cmds.poly* commands' .. py:attribute:: name :value: 'mesh_create' .. py:class:: NodeAddAttrRule Bases: :py:obj:`ConversionRule` Convert node.add_attr(name, **kwargs) to cmds.addAttr(...). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.addAttr(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node.add_attr() patterns. .. py:attribute:: category :value: 'node_methods' .. py:attribute:: description :value: 'Convert Node.add_attr() to cmds.addAttr' .. py:attribute:: name :value: 'node_add_attr' .. py:class:: NodeDeleteRule Bases: :py:obj:`ConversionRule` Convert node.delete() to cmds.delete(node). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.delete(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node.delete() patterns. .. py:attribute:: category :value: 'node_methods' .. py:attribute:: description :value: 'Convert Node.delete() to cmds.delete' .. py:attribute:: name :value: 'node_delete' .. py:class:: NodeDuplicateRule Bases: :py:obj:`ConversionRule` Convert node.duplicate() to cmds.duplicate(node). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.duplicate(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node.duplicate() patterns. .. py:attribute:: category :value: 'node_methods' .. py:attribute:: description :value: 'Convert Node.duplicate() to cmds.duplicate' .. py:attribute:: name :value: 'node_duplicate' .. py:class:: NodeRenameRule Bases: :py:obj:`ConversionRule` Convert node.rename(name) to cmds.rename(node, name). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.rename(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node.rename(...) patterns. .. py:attribute:: category :value: 'node_methods' .. py:attribute:: description :value: 'Convert Node.rename() to cmds.rename' .. py:attribute:: name :value: 'node_rename' .. py:class:: PlugConnectRule Bases: :py:obj:`ConversionRule` Convert plug.connect(other) to cmds.connectAttr(src, dst). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.connectAttr(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match plug.connect(other) patterns. .. py:attribute:: category :value: 'connections' .. py:attribute:: description :value: 'Convert Plug.connect() to cmds.connectAttr' .. py:attribute:: name :value: 'plug_connect' .. py:class:: PlugGetRule Bases: :py:obj:`ConversionRule` Convert node["attr"].get() to cmds.getAttr('node.attr'). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.getAttr(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node["attr"].get() or node["attr"].value patterns. .. py:attribute:: category :value: 'attribute_access' .. py:attribute:: description :value: 'Convert Plug.get() to cmds.getAttr' .. py:attribute:: name :value: 'plug_get' .. py:class:: PlugLockRule Bases: :py:obj:`ConversionRule` Convert plug.lock() to cmds.setAttr(plug.path, lock=True). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.setAttr(..., lock=True). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node["attr"].lock() patterns. .. py:attribute:: category :value: 'attribute_methods' .. py:attribute:: description :value: 'Convert Plug.lock() to cmds.setAttr with lock flag' .. py:attribute:: name :value: 'plug_lock' .. py:class:: PlugRshiftRule Bases: :py:obj:`ConversionRule` Convert src_plug >> dst_plug to cmds.connectAttr(...). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.connectAttr(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match plug >> other_plug patterns. .. py:attribute:: category :value: 'connections' .. py:attribute:: description :value: 'Convert >> operator connection to cmds.connectAttr' .. py:attribute:: name :value: 'plug_rshift_connect' .. py:class:: PlugSetRule Bases: :py:obj:`ConversionRule` Convert node["attr"].set(value) to cmds.setAttr('node.attr', value). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.setAttr(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node["attr"].set(value) patterns. .. py:attribute:: category :value: 'attribute_access' .. py:attribute:: description :value: 'Convert Plug.set() to cmds.setAttr' .. py:attribute:: name :value: 'plug_set' .. py:class:: PlugUnlockRule Bases: :py:obj:`ConversionRule` Convert plug.unlock() to cmds.setAttr(plug.path, lock=False). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.setAttr(..., lock=False). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node["attr"].unlock() patterns. .. py:attribute:: category :value: 'attribute_methods' .. py:attribute:: description :value: 'Convert Plug.unlock() to cmds.setAttr with lock=False' .. py:attribute:: name :value: 'plug_unlock' .. py:class:: PlugValueGetRule Bases: :py:obj:`ConversionRule` Convert node["attr"].value (read) to cmds.getAttr('node.attr'). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.getAttr(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node["attr"].value read patterns. .. py:attribute:: category :value: 'attribute_access' .. py:attribute:: description :value: 'Convert Plug.value property read to cmds.getAttr' .. py:attribute:: name :value: 'plug_value_get' .. py:class:: PlugValueSetRule Bases: :py:obj:`ConversionRule` Convert node["attr"].value = x to cmds.setAttr('node.attr', x). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.setAttr(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node["attr"].value = x assignment patterns. Note: This matches Assign nodes where target is attr.value on subscript. .. py:attribute:: category :value: 'attribute_access' .. py:attribute:: description :value: 'Convert Plug.value property assignment to cmds.setAttr' .. py:attribute:: name :value: 'plug_value_set' .. py:class:: ResolveRule Bases: :py:obj:`ConversionRule` Convert resolve(name) to name (pass-through for string node names). Handles: - resolve('nodeName') - tm.resolve('nodeName') - tik.maya.resolve('nodeName') .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert resolve(name) to just name. .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match resolve(...) calls in various forms. .. py:attribute:: category :value: 'utilities' .. py:attribute:: description :value: 'Convert resolve() to direct node name usage' .. py:attribute:: name :value: 'resolve_call' .. py:class:: RuleContext Context information available during rule matching. Provides access to tracked variable names and their types, allowing rules to make informed decisions about conversions. .. 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:: source_lines :type: List[str] .. py:attribute:: variable_types :type: Dict[str, str] .. py:class:: RuleMatch Result of a successful rule match. .. py:attribute:: confidence :type: float :value: 1.0 .. py:attribute:: converted_code :type: str .. py:attribute:: notes :type: Optional[str] :value: None .. py:attribute:: original_node :type: ast.AST .. py:attribute:: rule_name :type: str .. py:class:: TransformCreateRule Bases: :py:obj:`ConversionRule` Convert Transform.create() to cmds.createNode('transform', ...). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.createNode('transform', ...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match Transform.create(...) calls. .. py:attribute:: category :value: 'node_creation' .. py:attribute:: description :value: 'Convert Transform.create() to cmds.createNode' .. py:attribute:: name :value: 'transform_create' .. py:class:: TransformFreezeRule Bases: :py:obj:`ConversionRule` Convert transform.freeze() to cmds.makeIdentity(...). .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.makeIdentity(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match transform.freeze() patterns. .. py:attribute:: category :value: 'transform_methods' .. py:attribute:: description :value: 'Convert Transform.freeze() to cmds.makeIdentity' .. py:attribute:: name :value: 'transform_freeze' .. py:class:: TransformPropertySetRule Bases: :py:obj:`ConversionRule` Convert transform property assignment to cmds.setAttr. .. py:method:: convert(node: ast.AST, context: RuleContext) -> RuleMatch Convert to cmds.setAttr(...). .. py:method:: matches(node: ast.AST, context: RuleContext) -> bool Match node.property = value patterns for known properties. .. py:attribute:: PROPERTY_MAP .. py:attribute:: category :value: 'properties' .. py:attribute:: description :value: 'Convert transform property assignment to cmds.setAttr' .. py:attribute:: name :value: 'transform_property_set' .. py:function:: get_default_rules() -> List[ConversionRule] Return the default set of conversion rules. Returns: List of ConversionRule instances in priority order.