get_object
Retrieve an object and its properties from a FreeCAD document. Specify the document and object names to fetch details and a screenshot for further editing or analysis.
Instructions
Get an object from a document. You can use this tool to get the properties of an object to see what you can check or edit.
Args:
doc_name: The name of the document to get the object from.
obj_name: The name of the object to get.
Returns:
The object and a screenshot of the object.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doc_name | Yes | ||
| obj_name | Yes |
Implementation Reference
- src/freecad_mcp/server.py:525-548 (handler)MCP tool handler for get_object: calls proxy, serializes to JSON, adds screenshot.def get_object(ctx: Context, doc_name: str, obj_name: str) -> dict[str, Any]: """Get an object from a document. You can use this tool to get the properties of an object to see what you can check or edit. Args: doc_name: The name of the document to get the object from. obj_name: The name of the object to get. Returns: The object and a screenshot of the object. """ freecad = get_freecad_connection() try: screenshot = freecad.get_active_screenshot() response = [ TextContent(type="text", text=json.dumps(freecad.get_object(doc_name, obj_name))), ] return add_screenshot_if_available(response, screenshot) except Exception as e: logger.error(f"Failed to get object: {str(e)}") return [ TextContent(type="text", text=f"Failed to get object: {str(e)}") ]
- src/freecad_mcp/server.py:84-85 (helper)Proxy wrapper in FreeCADConnection for RPC call to get_object.def get_object(self, doc_name: str, obj_name: str) -> dict[str, Any]: return self.server.get_object(doc_name, obj_name)
- Core RPC handler: retrieves FreeCAD DocumentObject and serializes it.def get_object(self, doc_name, obj_name): doc = FreeCAD.getDocument(doc_name) if doc: return serialize_object(doc.getObject(obj_name)) else: return None
- Serialization helper that converts FreeCAD objects to JSON-serializable dictionaries, used in get_object RPC.def serialize_object(obj): if isinstance(obj, list): return [serialize_object(item) for item in obj] elif isinstance(obj, App.Document): return { "Name": obj.Name, "Label": obj.Label, "FileName": obj.FileName, "Objects": [serialize_object(child) for child in obj.Objects], } else: result = { "Name": obj.Name, "Label": obj.Label, "TypeId": obj.TypeId, "Properties": {}, "Placement": serialize_value(getattr(obj, "Placement", None)), "Shape": serialize_shape(getattr(obj, "Shape", None)), "ViewObject": {}, } for prop in obj.PropertiesList: try: result["Properties"][prop] = serialize_value(getattr(obj, prop)) except Exception as e: result["Properties"][prop] = f"<error: {str(e)}>" if hasattr(obj, "ViewObject") and obj.ViewObject is not None: view = obj.ViewObject result["ViewObject"] = serialize_view_object(view) return result