Object Properties and Inspection
These functions and properties let you inspect and extract data from solid objects.
size
Get the bounding box dimensions of an object.
Syntax:
Returns: A list [width, height, depth] for 3D objects or [width, height] for 2D objects.
Examples:
position
Get the minimum corner coordinates of the bounding box.
Syntax:
Returns: A list [x, y, z] for 3D objects or [x, y] for 2D objects, representing the minimum corner of the bounding box.
Examples:
bbox
Get the bounding box as a solid object.
Syntax:
Returns: A cube (3D) or square (2D) representing the bounding box of the object.
Examples:
mesh
Extract the mesh data (vertices and triangles) from a solid.
Syntax:
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
obj |
solid | — | The object to extract mesh from |
triangulate |
bool | True |
Triangulate faces |
color |
bool | False |
Include color data |
Returns: A tuple (points, triangles) where points is a list of [x, y, z] coordinates and triangles is a list of vertex index lists.
Examples:
from openscad import *
c = cube(10)
pts, tris = c.mesh()
# Modify vertices and reconstruct
for pt in pts:
if pt[2] > 5:
pt[0] += 3
polyhedron(pts, tris).show()
faces
Get a list of face solids from an object. Each face is a 2D solid with a matrix property indicating its orientation in 3D space.
Syntax:
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
obj |
solid | — | The object to extract faces from |
triangulate |
bool | False |
Return triangulated faces |
Returns: A list of 2D solid objects, each with a .matrix attribute (4x4 transformation matrix showing the face's position and orientation).
Examples:
from openscad import *
core = sphere(r=2)
face_list = core.faces()
flower = core
for f in face_list:
flower |= f.linear_extrude(height=4)
flower.show()
edges
Get a list of edge solids from a face or 2D object.
Syntax:
Returns: A list of edge solids, each with a .matrix attribute.
Examples:
inside
Check whether a given point is inside the solid.
Syntax:
Parameters:
| Parameter | Type | Description |
|---|---|---|
obj |
solid | The solid to test against |
point |
[x, y, z] |
The point to test |
Returns: True if the point is inside the solid, False otherwise.
Examples:
from openscad import *
c = cube(10)
print(c.inside([5, 5, 5])) # True
print(c.inside([15, 5, 5])) # False
children
Get the child nodes of a compound solid as a tuple.
Syntax:
Returns: A tuple of child solid objects.
Examples:
Dynamic Attributes
Solid objects support dynamic attribute access for node-specific data. These attributes are available through both dot notation (obj.attr) and subscript notation (obj["attr"]).
These attributes cannot only be read, but also overwriten.
Built-in dynamic attributes
| Attribute | Available on | Description |
|---|---|---|
points |
polygon nodes |
Read/write access to polygon vertex coordinates |
paths |
polygon nodes |
Read/write access to polygon paths |
faces |
polyhedron nodes |
Read access to face indices |
matrix |
face/edge solids | 4x4 transformation matrix showing orientation in space |
Custom attributes
You can store arbitrary data on any solid:
from openscad import *
c = cube(10)
c["name"] = "my cube"
c.material = "PLA"
print(c["name"]) # "my cube"
print(c.material) # "PLA"
See Object Model for more details on attribute access.