maya.utils.converter.rules_reverse¶
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¶
Classes¶
Convert cmds.addAttr(node, ...) to node.add_attr(...). |
|
Convert cmds.connectAttr(src, dst) to src_plug.connect(dst_plug). |
|
Convert cmds.createNode('transform', ...) to Transform.create(...). |
|
Convert cmds.curve(...) to Curve.create(...). |
|
Convert cmds.delete(node) to node.delete(). |
|
Convert cmds.duplicate(node) to node.duplicate(). |
|
Convert cmds.getAttr('node.attr') to node['attr'].get(). |
|
Convert cmds.joint(...) to Joint.create(...). |
|
Convert cmds.makeIdentity(node, apply=True, ...) to node.freeze(...). |
|
Convert cmds.polyCube(...) to Mesh.create('polyCube', ...). |
|
Convert cmds.polyCylinder(...) to Mesh.create('polyCylinder', ...). |
|
Convert cmds.polyPlane(...) to Mesh.create('polyPlane', ...). |
|
Convert cmds.polySphere(...) to Mesh.create('polySphere', ...). |
|
Convert cmds.rename(node, name) to node.rename(name). |
|
Base class for all cmds → tik.maya conversion rules. |
|
Context information available during reverse rule matching. |
|
Result of a successful reverse rule match. |
|
Convert cmds.select(node, replace=True) to node.select(). |
|
Convert cmds.setAttr('node.attr', lock=True) to node['attr'].lock(). |
|
Convert cmds.setAttr('node.attr', value) to node['attr'].set(value). |
|
Convert cmds.spaceLocator(...) to Locator.create(...). |
Functions¶
|
Extract node and attribute from a string argument or f-string. |
|
Extract a keyword argument from a call node. |
|
Extract a keyword argument value as a string. |
|
Extract a string argument from a call node. |
|
Return the default set of reverse conversion rules. |
|
Get the reason why a cmds function is unsupported. |
|
Check if node is a cmds.func_name() call. |
|
Parse a 'node.attribute' path string. |
Module Contents¶
- class AddAttrToNodeAddAttrRule¶
Bases:
ReverseConversionRuleConvert cmds.addAttr(node, …) to node.add_attr(…).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to node.add_attr(name, …).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.addAttr(…) calls.
- category = 'node_operations'¶
- description = 'Convert cmds.addAttr() to Node.add_attr()'¶
- name = 'addattr_to_node_addattr'¶
- class ConnectAttrToPlugConnectRule¶
Bases:
ReverseConversionRuleConvert cmds.connectAttr(src, dst) to src_plug.connect(dst_plug).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to src[‘attr’].connect(dst[‘attr’]).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.connectAttr(…) calls.
- category = 'connections'¶
- description = 'Convert cmds.connectAttr() to Plug.connect()'¶
- name = 'connectattr_to_plug_connect'¶
- class CreateNodeToTransformRule¶
Bases:
ReverseConversionRuleConvert cmds.createNode(‘transform’, …) to Transform.create(…).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to Transform.create(…).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.createNode(‘transform’, …) calls.
- category = 'node_creation'¶
- description = "Convert cmds.createNode('transform') to Transform.create()"¶
- name = 'createnode_to_transform'¶
- class CurveToCurveCreateRule¶
Bases:
ReverseConversionRuleConvert cmds.curve(…) to Curve.create(…).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to Curve.create(…).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.curve(…) calls.
- category = 'node_creation'¶
- description = 'Convert cmds.curve() to Curve.create()'¶
- name = 'curve_to_curve_create'¶
- class DeleteToNodeDeleteRule¶
Bases:
ReverseConversionRuleConvert cmds.delete(node) to node.delete().
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to node.delete().
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.delete(…) calls with single node argument.
- category = 'node_operations'¶
- description = 'Convert cmds.delete() to Node.delete()'¶
- name = 'delete_to_node_delete'¶
- class DuplicateToNodeDuplicateRule¶
Bases:
ReverseConversionRuleConvert cmds.duplicate(node) to node.duplicate().
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to node.duplicate().
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.duplicate(…) calls.
- category = 'node_operations'¶
- description = 'Convert cmds.duplicate() to Node.duplicate()'¶
- name = 'duplicate_to_node_duplicate'¶
- class GetAttrToPlugGetRule¶
Bases:
ReverseConversionRuleConvert cmds.getAttr(‘node.attr’) to node[‘attr’].get().
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to node[‘attr’].get().
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.getAttr(…) calls.
- category = 'attribute_access'¶
- description = 'Convert cmds.getAttr() to Plug.get()'¶
- name = 'getattr_to_plug_get'¶
- class JointToJointCreateRule¶
Bases:
ReverseConversionRuleConvert cmds.joint(…) to Joint.create(…).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to Joint.create(…).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.joint(…) calls.
- category = 'node_creation'¶
- description = 'Convert cmds.joint() to Joint.create()'¶
- name = 'joint_to_joint_create'¶
- class MakeIdentityToFreezeRule¶
Bases:
ReverseConversionRuleConvert cmds.makeIdentity(node, apply=True, …) to node.freeze(…).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to node.freeze(…).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.makeIdentity(…, apply=True) calls.
- category = 'transform_operations'¶
- description = 'Convert cmds.makeIdentity() to Transform.freeze()'¶
- name = 'makeidentity_to_freeze'¶
- class PolyCubeToMeshCreateRule¶
Bases:
ReverseConversionRuleConvert cmds.polyCube(…) to Mesh.create(‘polyCube’, …).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to Mesh.create(‘polyCube’, …).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.polyCube(…) calls.
- category = 'node_creation'¶
- description = "Convert cmds.polyCube() to Mesh.create('polyCube')"¶
- name = 'polycube_to_mesh_create'¶
- class PolyCylinderToMeshCreateRule¶
Bases:
ReverseConversionRuleConvert cmds.polyCylinder(…) to Mesh.create(‘polyCylinder’, …).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to Mesh.create(‘polyCylinder’, …).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.polyCylinder(…) calls.
- category = 'node_creation'¶
- description = "Convert cmds.polyCylinder() to Mesh.create('polyCylinder')"¶
- name = 'polycylinder_to_mesh_create'¶
- class PolyPlaneToMeshCreateRule¶
Bases:
ReverseConversionRuleConvert cmds.polyPlane(…) to Mesh.create(‘polyPlane’, …).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to Mesh.create(‘polyPlane’, …).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.polyPlane(…) calls.
- category = 'node_creation'¶
- description = "Convert cmds.polyPlane() to Mesh.create('polyPlane')"¶
- name = 'polyplane_to_mesh_create'¶
- class PolySphereToMeshCreateRule¶
Bases:
ReverseConversionRuleConvert cmds.polySphere(…) to Mesh.create(‘polySphere’, …).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to Mesh.create(‘polySphere’, …).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.polySphere(…) calls.
- category = 'node_creation'¶
- description = "Convert cmds.polySphere() to Mesh.create('polySphere')"¶
- name = 'polysphere_to_mesh_create'¶
- class RenameToNodeRenameRule¶
Bases:
ReverseConversionRuleConvert cmds.rename(node, name) to node.rename(name).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to node.rename(name).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.rename(…) calls.
- category = 'node_operations'¶
- description = 'Convert cmds.rename() to Node.rename()'¶
- name = 'rename_to_node_rename'¶
- class ReverseConversionRule¶
Bases:
abc.ABCBase 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.)
- abstractmethod convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
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.
- abstractmethod matches(node: ast.AST, context: ReverseRuleContext) bool¶
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.
- category: str = 'general'¶
- description: str = ''¶
- name: str = 'unnamed_reverse_rule'¶
- 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.
- get_node_variable(node_name: str) str | None¶
Get the variable name for a node string literal.
- get_variable_type(name: str) str | None¶
Get the tracked type for a variable name.
- imports: Dict[str, str]¶
- node_variables: Dict[str, str]¶
- source_lines: List[str]¶
- variable_types: Dict[str, str]¶
- class ReverseRuleMatch¶
Result of a successful reverse rule match.
- confidence: float = 1.0¶
- converted_code: str¶
- node_mappings: Dict[str, str] | None = None¶
- notes: str | None = None¶
- original_node: ast.AST¶
- rule_name: str¶
- class SelectToNodeSelectRule¶
Bases:
ReverseConversionRuleConvert cmds.select(node, replace=True) to node.select().
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to node.select().
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.select(…) calls with single node and replace=True.
- category = 'node_operations'¶
- description = 'Convert cmds.select() to Node.select()'¶
- name = 'select_to_node_select'¶
- class SetAttrLockToPlugLockRule¶
Bases:
ReverseConversionRuleConvert cmds.setAttr(‘node.attr’, lock=True) to node[‘attr’].lock().
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to node[‘attr’].lock() or unlock().
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.setAttr(…, lock=True/False) calls.
- category = 'attribute_access'¶
- description = 'Convert cmds.setAttr(lock=True) to Plug.lock()'¶
- name = 'setattr_lock_to_plug_lock'¶
- class SetAttrToPlugSetRule¶
Bases:
ReverseConversionRuleConvert cmds.setAttr(‘node.attr’, value) to node[‘attr’].set(value).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to node[‘attr’].set(value).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.setAttr(…) calls without lock/keyable flags.
- category = 'attribute_access'¶
- description = 'Convert cmds.setAttr() to Plug.set()'¶
- name = 'setattr_to_plug_set'¶
- class SpaceLocatorToLocatorCreateRule¶
Bases:
ReverseConversionRuleConvert cmds.spaceLocator(…) to Locator.create(…).
- convert(node: ast.AST, context: ReverseRuleContext) ReverseRuleMatch¶
Convert to Locator.create(…).
- matches(node: ast.AST, context: ReverseRuleContext) bool¶
Match cmds.spaceLocator(…) calls.
- category = 'node_creation'¶
- description = 'Convert cmds.spaceLocator() to Locator.create()'¶
- name = 'spacelocator_to_locator_create'¶
- extract_attr_path_from_arg(arg: ast.AST) Tuple[str | None, str | None]¶
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).
- extract_kwarg(node: ast.Call, kwarg_name: str) ast.AST | None¶
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.
- extract_kwarg_value(node: ast.Call, kwarg_name: str) str | None¶
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.
- extract_string_arg(node: ast.AST, index: int = 0) str | None¶
Extract a string argument from a call node.
- Args:
node: Call AST node. index: Argument index.
- Returns:
The string value if found, None otherwise.
- get_default_reverse_rules() List[ReverseConversionRule]¶
Return the default set of reverse conversion rules.
- Returns:
List of ReverseConversionRule instances in priority order.
- get_unsupported_cmds_reason(func_name: str) str | None¶
Get the reason why a cmds function is unsupported.
- Args:
func_name: The cmds function name.
- Returns:
The reason string if unsupported, None otherwise.
- 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.
- parse_attr_path(attr_path: str) Tuple[str | None, str | None]¶
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.
- UNSUPPORTED_CMDS¶