Design#
The Design class is the top-level container
for a geometry model in PyAnsys Geometry. It extends the
Component class, meaning that all
component-level operations (creating bodies, sub-components, datum planes, and so on) are
also available directly on the design object.
A Design object is always created through the
Modeler instance:
from ansys.geometry.core import Modeler
modeler = Modeler()
design = modeler.create_design("MyDesign")
Purpose and responsibilities#
A Design object represents the root of a geometry assembly. It is responsible for:
Containing all
ComponentandBodythat make up a geometry model.Managing materials that can be assigned to bodies.
Managing named selections: named groups of geometry entities (components, bodies, faces, edges, design points, and vertices) that make it easier to reference specific portions of the model.
Managing beam profiles used for structural beam elements.
Managing parameters for parametric modeling.
Providing import and export capabilities to exchange geometry with other tools.
Key properties#
The following are the most commonly used properties on a Design object.
bodiesA list of all top-level
Bodyobjects in the design. Useget_all_bodies()to retrieve bodies at all levels of the hierarchy.componentsA list of all top-level
Componentobjects in the design.materialsA list of
Materialobjects that have been added to the design.named_selectionsA list of
NamedSelectionobjects available in the design.is_activeTrueif the design is currently the active design in the Geometry service session.
Working with materials#
Materials define physical properties (such as density, Poisson’s ratio, and tensile strength) that can be assigned to bodies. Add a material to a design before assigning it to any body.
from pint import Quantity
from ansys.geometry.core.materials import Material
from ansys.geometry.core.materials import MaterialProperty, MaterialPropertyType
from ansys.geometry.core.misc import UNITS
# Define material properties
density = Quantity(7850, UNITS.kg / UNITS.m**3)
poisson_ratio = Quantity(0.3, UNITS.dimensionless)
# Create and add material to the design
steel = Material(
"steel",
density,
[MaterialProperty(MaterialPropertyType.POISSON_RATIO, "PoissonRatio", poisson_ratio)],
)
design.add_material(steel)
To assign a material to a body:
body.assign_material(steel)
To remove a material from the design:
design.remove_material(steel)
Working with named selections#
Named selections allow you to group and later reference specific geometry entities, such as bodies, faces, edges, or vertices.
# Create a named selection containing specific bodies
ns = design.create_named_selection("ImportantBodies", bodies=[body1, body2])
# Access all named selections in the design
for ns in design.named_selections:
print(ns.name)
# Delete a named selection when no longer needed
design.delete_named_selection(ns)
Importing and exporting geometry#
PyAnsys Geometry supports importing geometry files into a design and exporting designs to several industry-standard formats.
Importing geometry
# Import a STEP file into the design
design.insert_file("path/to/geometry.step")
Exporting geometry
PyAnsys Geometry provides dedicated export_to_* methods for each supported file format.
Each method accepts an optional location argument. If omitted, the file is saved in the
current working directory using the design name as the filename.
# Export as Ansys native format (returns Path to the saved file)
path = design.export_to_scdocx()
# Export as STEP
path = design.export_to_step()
# Export as IGES
path = design.export_to_iges()
# Export as Parasolid (text)
path = design.export_to_parasolid_text()
# Export as Parasolid (binary)
path = design.export_to_parasolid_bin()
# Export as FMD
path = design.export_to_fmd()
# Export as PMDB
path = design.export_to_pmdb()
# Export as DISCO
path = design.export_to_disco()
# Export as STRIDE
path = design.export_to_stride()
You can also pass a directory path or a full path to location:
import pathlib
# Save to a specific directory; filename is "<design.name>.stp"
path = design.export_to_step("path/to/directory")
The supported file formats are defined in
DesignFileFormat.
Working with parameters#
Parameters allow for parametric modeling, where dimensions can be controlled by named variables.
# Retrieve all parameters in the design
params = design.get_all_parameters()
# Update a parameter value
design.set_parameter("Height", Quantity(50, UNITS.mm))
Closing a design#
When you are finished working with a design, close it to release server-side resources:
design.close()
For the full API reference, see
Design.