create_object
Create a new FreeCAD object by specifying its document, type, name, and properties, with an optional screenshot for visual feedback.
Instructions
Create a new object in FreeCAD.
``obj_type`` must name a type registered in FreeCAD's C++ type system, such
as "Part::", "PartDesign::" or "Fem::" types. A number of FreeCAD features
are implemented in Python rather than C++ and so are not registered types;
of those, these are supported here through dedicated factories, and each
requires the properties listed beside it:
Part::Tube InnerRadius, OuterRadius, Height
Draft::Circle Radius
Draft::Rectangle Length, Height
Draft::Polygon FacesNumber, Radius
Draft::Wire Points (list of {x, y, z}), optional Closed
Any other Python-implemented type (Draft::Point, Draft::Ellipse, ...) must
be built with ``execute_code`` instead.
Note that the Draft factories name objects themselves, so for those the
returned object_name will differ from the requested obj_name, which is
applied to the object's Label instead. Always use the returned name in
later get_object/edit_object calls.
Args:
doc_name: The name of the document to create the object in.
obj_type: The type of the object to create (e.g. 'Part::Box', 'Part::Cylinder', 'Part::Cut', 'PartDesign::Body', etc.).
obj_name: The name of the object to create.
obj_properties: The properties of the object to create.
include_screenshot: Whether to return a screenshot of the model (default True).
Set to False to save tokens when visual feedback is not needed,
e.g. for intermediate steps in a longer sequence of changes.
view_name: The view orientation of the returned screenshot (default "Isometric").
Pick the view that best shows the change being made.
Returns:
A message indicating the success or failure of the object creation and a screenshot of the object.
Examples:
If you want to create a cylinder with a height of 30 and a radius of 10, you can use the following data.
```json
{
"doc_name": "MyCylinder",
"obj_name": "Cylinder",
"obj_type": "Part::Cylinder",
"obj_properties": {
"Height": 30,
"Radius": 10,
"Placement": {
"Base": {
"x": 10,
"y": 10,
"z": 0
},
"Rotation": {
"Axis": {
"x": 0,
"y": 0,
"z": 1
},
"Angle": 45
}
},
"ViewObject": {
"ShapeColor": [0.5, 0.5, 0.5, 1.0]
}
}
}
```
If you want to cut one solid out of another, create both solids first,
then reference them by name as 'Base' and 'Tool'.
```json
{
"doc_name": "MyPart",
"obj_name": "Cut",
"obj_type": "Part::Cut",
"obj_properties": {
"Base": "Box",
"Tool": "Cylinder"
}
}
```
If you want to create a pipe with an outer diameter of 250, a 10 wall
and a length of 500, you can use the following data.
```json
{
"doc_name": "MyPipe",
"obj_name": "Pipe",
"obj_type": "Part::Tube",
"obj_properties": {
"OuterRadius": 125,
"InnerRadius": 115,
"Height": 500
}
}
```
If you want to create a FEM analysis, you can use the following data.
```json
{
"doc_name": "MyFEMAnalysis",
"obj_name": "FemAnalysis",
"obj_type": "Fem::AnalysisPython",
}
```
If you want to create a FEM constraint, you can use the following data.
```json
{
"doc_name": "MyFEMConstraint",
"obj_name": "FemConstraint",
"obj_type": "Fem::ConstraintFixed",
"analysis_name": "MyFEMAnalysis",
"obj_properties": {
"References": [
{
"object_name": "MyObject",
"face": "Face1"
}
]
}
}
```
If you want to create a FEM mechanical material, you can use the following data.
```json
{
"doc_name": "MyFEMAnalysis",
"obj_name": "FemMechanicalMaterial",
"obj_type": "Fem::MaterialCommon",
"analysis_name": "MyFEMAnalysis",
"obj_properties": {
"Material": {
"Name": "MyMaterial",
"Density": "7900 kg/m^3",
"YoungModulus": "210 GPa",
"PoissonRatio": 0.3
}
}
}
```
If you want to create a FEM mesh, you can use the following data.
The `Shape` property is required (legacy `Part` is also accepted).
On FreeCAD 1.x the size limits are `CharacteristicLengthMax/Min`;
the legacy `ElementSizeMax/Min` keys are also accepted.
```json
{
"doc_name": "MyFEMMesh",
"obj_name": "FemMesh",
"obj_type": "Fem::FemMeshGmsh",
"analysis_name": "MyFEMAnalysis",
"obj_properties": {
"Shape": "MyObject",
"CharacteristicLengthMax": 10,
"CharacteristicLengthMin": 0.1
}
}
```
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doc_name | Yes | ||
| obj_name | Yes | ||
| obj_type | Yes | ||
| view_name | No | Isometric | |
| analysis_name | No | ||
| obj_properties | No | ||
| include_screenshot | No |