Skip to main content
Glama

export_drawing_png

Export IFC building model drawings as PNG images with customizable view types, resolution, and camera height for architectural documentation.

Instructions

Export drawings as PNG images with custom resolution.

Creates a drawing, with the view type specified, of the IFC building at the specified 
height above the floor level. Supports custom resolution for high-quality architectural drawings.

Args:
    height_offset: Height in meters above the storey level for the camera position (default 0.5m)
    view_type: Type of view - "top" for plan view, "front", "right" and "left" for elevation views, and "isometric" for 3D view
    resolution_x: Horizontal resolution in pixels (default 1920, max recommended 4096)
    resolution_y: Vertical resolution in pixels (default 1080, max recommended 4096)
    storey_name: Specific storey name to add to the file name (if None, prints default in the file name)
    output_path: Optional file path to save the PNG (if None, returns as base64 image)

Returns:
    metadata and the path of the file image of the drawing at the specified resolution

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
height_offsetNo
view_typeNotop
resolution_xNo
resolution_yNo
storey_nameNo
output_pathNo

Implementation Reference

  • The handler function for the 'export_drawing_png' MCP tool. It validates input parameters, connects to Blender via the global connection, sends an 'export_drawing_png' command with parameters to the Blender addon, receives base64-encoded PNG image data, decodes it, generates a filename if not provided, saves the image to ./exports/drawings/, and returns a dictionary with status and absolute file path.
    @mcp.tool()
    def export_drawing_png(
        height_offset: float = 0.5,
        view_type: str = "top",
        resolution_x: int = 1920,
        resolution_y: int = 1080,
        storey_name: str | None = None,
        output_path: str | None = None
    ) -> dict:
        """Export drawings as PNG images with custom resolution.
        
        Creates a drawing, with the view type specified, of the IFC building at the specified 
        height above the floor level. Supports custom resolution for high-quality architectural drawings.
        
        Args:
            height_offset: Height in meters above the storey level for the camera position (default 0.5m)
            view_type: Type of view - "top" for plan view, "front", "right" and "left" for elevation views, and "isometric" for 3D view
            resolution_x: Horizontal resolution in pixels (default 1920, max recommended 4096)
            resolution_y: Vertical resolution in pixels (default 1080, max recommended 4096)
            storey_name: Specific storey name to add to the file name (if None, prints default in the file name)
            output_path: Optional file path to save the PNG (if None, returns as base64 image)
        
        Returns:
            metadata and the path of the file image of the drawing at the specified resolution
        """
        try:
            # Validate resolution limits for performance
            if resolution_x > 4096 or resolution_y > 4096:
                raise Exception("Resolution too high. Maximum recommended: 4096x4096 pixels")
            
            if resolution_x < 100 or resolution_y < 100:
                raise Exception("Resolution too low. Minimum: 100x100 pixels")
            
            # Get the global connection
            blender = get_blender_connection()
            
            # Request drawing render
            result = blender.send_command("export_drawing_png", {
                "view_type": view_type,
                "height_offset": height_offset,
                "resolution_x": resolution_x,
                "resolution_y": resolution_y,
                "storey_name": storey_name,
                "output_path": output_path
            })
            
            if "error" in result:
                raise Exception(f"Error creating {view_type} drawing: {result.get('error', 'Unknown error')}")
            
            if "data" not in result:
                raise Exception("No image data returned from Blender")
            
            # Decode the base64 image data
            image_data = base64.b64decode(result["data"])
            
            # Ensure output path exists
            if not output_path:
                os.makedirs("./exports/drawings", exist_ok=True)
                # Generate filename based on view type
                view_name = {
                    "top": "plan_view",
                    "front": "front_elevation", 
                    "right": "right_elevation",
                    "left": "left_elevation",
                    "isometric": "isometric_view"
                }.get(view_type, view_type)
                filename = f"{view_name}_{storey_name or 'default'}.png"
                output_path = os.path.join("./exports/drawings", filename)
            
            # Save to file
            with open(output_path, "wb") as f:
                f.write(image_data)
            
            # Return only metadata
            return {
                "status": "success",
                "file_path": os.path.abspath(output_path),
                # Opcional: si tienes un servidor de archivos, podrías devolver también una URL
                # "url": f"http://localhost:8000/files/{filename}"
            }
            
        except Exception as e:
            logger.error(f"Error exporting drawing: {str(e)}")
            return { "status": "error", "message": str(e) }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JotaDeRodriguez/Bonsai_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server