Object Model
In PythonSCAD, every 3D or 2D solid is a Python object of type openscad.PyOpenSCAD. These objects support method chaining, metadata storage, iteration over children, and operator overloading.
Method Chaining
All transformation and operation functions are available as methods on solid objects, enabling a fluent coding style:
The following methods are available on every solid object:
Transforms: translate, rotate, scale, mirror, multmatrix, divmatrix,
resize, color, offset, right, left, front, back, up, down,
rotx, roty, rotz, pull, wrap, align
Booleans: union, difference, intersection
Extrusions: linear_extrude, rotate_extrude, path_extrude
Inspection: mesh, faces, edges, inside, bbox, children
Mesh ops: explode, oversample, debug, repair, fillet, separate
Display: show, export, render, projection, highlight, background, only
Other: clone, hasattr, getattr, setattr, dict, _repr_mimebundle_
clone
Create a deep copy of a solid object, including its metadata dictionary.
Syntax:
Examples:
dict
Return the metadata dictionary stored on the solid.
Syntax:
Returns: A Python dictionary containing all custom attributes stored on the object.
Examples:
Attribute Access
Solids support both dot notation and subscript notation for storing and retrieving custom data:
hasattr / getattr / setattr
These methods check for, retrieve, and set attributes on solids:
Iteration
Solids are iterable. Iterating over a compound solid (e.g. a union) yields ChildRef objects for each child node:
ChildRef
Each iteration yields a ChildRef object with:
.value-- get or set the child solid- Attribute access is forwarded to the underlying child solid
len and indexing
Jupyter Support
Solids implement _repr_mimebundle_ for rendering in Jupyter notebooks. When a solid is the last expression in a cell, it is automatically rendered as an image.
memberfunction
Register a user-defined method that becomes available on all solid objects.
Syntax:
Parameters:
| Parameter | Type | Description |
|---|---|---|
name |
string | Method name |
func |
callable | Function that receives the solid as its first argument |
docstring |
string | Optional documentation string |
Examples:
String Representation
Solids have __repr__ and __str__ methods that return an ASCII tree dump of the CSG node structure: