draw_rectangle
Add rectangles to Aseprite pixel art files by specifying position, dimensions, color, and fill options for precise canvas modifications.
Instructions
Draw a rectangle on the canvas.
Args: filename: Name of the Aseprite file to modify x: Top-left x coordinate y: Top-left y coordinate width: Width of the rectangle height: Height of the rectangle color: Hex color code (default: "#000000") fill: Whether to fill the rectangle (default: False)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | ||
| x | Yes | ||
| y | Yes | ||
| width | Yes | ||
| height | Yes | ||
| color | No | #000000 | |
| fill | No |
Implementation Reference
- aseprite_mcp/tools/drawing.py:112-145 (handler)The draw_rectangle tool handler function in drawing.py. It validates inputs, constructs a Lua script using LuaBuilder, and executes it via Aseprite.
async def draw_rectangle(filename: str, x: int, y: int, width: int, height: int, color: str = "#000000", fill: bool = False) -> str: """Draw a rectangle on the canvas. Args: filename: Name of the Aseprite file to modify x: Top-left x coordinate y: Top-left y coordinate width: Width of the rectangle height: Height of the rectangle color: Hex color code (default: "#000000") fill: Whether to fill the rectangle (default: False) """ try: # Validate inputs file_path = validate_file_path(filename, must_exist=True) color = validate_color(color) if width < 1: raise ValidationError("width", width, "Width must be at least 1") if height < 1: raise ValidationError("height", height, "Height must be at least 1") # Build Lua script builder = LuaBuilder() builder.add_line('local spr = app.activeSprite') builder.if_condition('not spr') builder.add_line('error("No active sprite")') builder.end_if() builder.add_line() builder.begin_transaction() builder.draw_rectangle(x, y, width, height, color, fill) builder.end_transaction() builder.save_sprite()