maya.utils.converter.codegen¶
Code generation utilities for maya.cmds output.
This module handles the generation of valid Python code that uses maya.cmds from the converted AST representations.
Classes¶
Utility for building well-formatted Python code output. |
Functions¶
|
Format a cmds.connectAttr call. |
|
Format a cmds.getAttr call. |
|
Format a cmds.setAttr call. |
|
Generate the standard maya.cmds import statement. |
|
Generate a header comment for converted code. |
|
Wrap converted code in a function definition. |
Module Contents¶
- class CodeBuilder(indent_size: int = 4)¶
Utility for building well-formatted Python code output.
Handles indentation, line continuations, and comment insertion to produce readable, diff-friendly output.
- add_blank_line() CodeBuilder¶
Add a blank line.
- Returns:
Self for method chaining.
- add_comment(comment: str) CodeBuilder¶
Add a comment line.
- Args:
comment: The comment text (without #).
- Returns:
Self for method chaining.
- add_import(module: str, items: List[str] | None = None) CodeBuilder¶
Add an import statement.
- Args:
module: Module to import from. items: Specific items to import (for ‘from’ imports).
- Returns:
Self for method chaining.
- add_line(line: str) CodeBuilder¶
Add a line of code with current indentation.
- Args:
line: The line of code to add.
- Returns:
Self for method chaining.
- build() str¶
Build the final code string.
- Returns:
The generated code as a string.
- dedent() CodeBuilder¶
Decrease indentation level.
- Returns:
Self for method chaining.
- indent() CodeBuilder¶
Increase indentation level.
- Returns:
Self for method chaining.
- indent_size = 4¶
- format_connectattr_call(src_node: str, src_attr: str, dst_node: str, dst_attr: str, force: bool = True, use_fstring: bool = True) str¶
Format a cmds.connectAttr call.
- Args:
src_node: Source node expression. src_attr: Source attribute name. dst_node: Destination node expression. dst_attr: Destination attribute name. force: Whether to force the connection. use_fstring: Whether to use f-strings for paths.
- Returns:
Formatted connectAttr call.
- format_getattr_call(node_expr: str, attr_name: str, use_fstring: bool = True) str¶
Format a cmds.getAttr call.
- Args:
node_expr: Expression for the node. attr_name: Attribute name. use_fstring: Whether to use f-strings for the path.
- Returns:
Formatted getAttr call.
- format_setattr_call(node_expr: str, attr_name: str, value: str, use_fstring: bool = True) str¶
Format a cmds.setAttr call.
- Args:
node_expr: Expression for the node. attr_name: Attribute name. value: Value expression. use_fstring: Whether to use f-strings for the path.
- Returns:
Formatted setAttr call.
- generate_cmds_import() str¶
Generate the standard maya.cmds import statement.
- Returns:
Import statement string.
- generate_header_comment(original_info: str | None = None, warnings: List[str] | None = None) str¶
Generate a header comment for converted code.
- Args:
original_info: Information about the original source. warnings: List of warnings to include.
- Returns:
Header comment string.
- wrap_in_function(code: str, function_name: str = 'converted_code', docstring: str | None = None) str¶
Wrap converted code in a function definition.
- Args:
code: The code to wrap. function_name: Name for the function. docstring: Optional docstring.
- Returns:
The wrapped code.