Download this example

Download this example as a Jupyter Notebook or as a Python script.


Modeling: Exporting designs#

After creating a design, you typically want to bring it into a CAD tool for further development. This notebook demonstrates how to export a design to the various supported CAD formats.

Create a design#

The code creates a simple design for demonstration purposes. The design consists of a set of rectangular pads with a circular hole in the center.

[1]:
from ansys.geometry.core import Modeler
from ansys.geometry.core.math import UNITVECTOR3D_X, UNITVECTOR3D_Y, Point2D
from ansys.geometry.core.sketch import Sketch

# Instantiate the modeler - this connects to the service
modeler = Modeler()

# Create a design
design = modeler.create_design("ExportDesignExample")

# Create a sketch
sketch = Sketch()

# Create a simple rectangle
sketch.box(Point2D([0, 0]), 10, 5)

# Extrude the sketch and displace the resulting body
# to make a plane of rectangles
for x_step in [-60, -45, -30, -15, 0, 15, 30, 45, 60]:
    for y_step in [-40, -30, -20, -10, 0, 10, 20, 30, 40]:
        # Extrude the sketch
        body = design.extrude_sketch(f"Body_X_{x_step}_Y_{y_step}", sketch, 5)

        # Displace the body in the x and y directions
        body.translate(UNITVECTOR3D_X, x_step)
        body.translate(UNITVECTOR3D_Y, y_step)

# Plot the design
design.plot()

Export the design#

You can export the design to various CAD formats. For the formats supported see the DesignFileFormat class, which is part of the the design module documentation.

Nonetheless, there are a set of convenience methods that you can use to export the design to the supported formats. The following code snippets demonstrate how to do it. You can decide whether to export the design to a file in a certain directory or in the current working directory.

Export to a file in the current working directory#

[2]:
# Export the design to a file in the current working directory
file_location = design.export_to_scdocx()
print(f"Design exported to {file_location}")
Design exported to C:\Users\Public\actions-runner\_work\pyansys-geometry\pyansys-geometry\doc\source\examples\03_modeling\ExportDesignExample.scdocx

Export to a file in a certain directory#

[3]:
from pathlib import Path

# Define a downloads directory
download_dir = Path.cwd() / "downloads"

# Export the design to a file in a certain directory
file_location = design.export_to_scdocx(download_dir)
print(f"Design exported to {file_location}")
Design exported to C:\Users\Public\actions-runner\_work\pyansys-geometry\pyansys-geometry\doc\source\examples\03_modeling\downloads\ExportDesignExample.scdocx

Export to SCDOCX format#

[4]:
# Export the design to a file in the requested directory
file_location = design.export_to_scdocx(download_dir)

# Print the file location
print(f"Design exported to {file_location}")
print(f"Does the file exist? {Path(file_location).exists()}")
Design exported to C:\Users\Public\actions-runner\_work\pyansys-geometry\pyansys-geometry\doc\source\examples\03_modeling\downloads\ExportDesignExample.scdocx
Does the file exist? True

Export to Parasolid text format#

[5]:
# Export the design to a file in the requested directory
file_location = design.export_to_parasolid_text(download_dir)

# Print the file location
print(f"Design exported to {file_location}")
print(f"Does the file exist? {Path(file_location).exists()}")
Design exported to C:\Users\Public\actions-runner\_work\pyansys-geometry\pyansys-geometry\doc\source\examples\03_modeling\downloads\ExportDesignExample.xmt_txt
Does the file exist? True

Export to Parasolid binary format#

[6]:
# Export the design to a file in the requested directory
file_location = design.export_to_parasolid_bin(download_dir)

# Print the file location
print(f"Design exported to {file_location}")
print(f"Does the file exist? {Path(file_location).exists()}")
Design exported to C:\Users\Public\actions-runner\_work\pyansys-geometry\pyansys-geometry\doc\source\examples\03_modeling\downloads\ExportDesignExample.xmt_bin
Does the file exist? True

Export to STEP format#

[7]:
# Export the design to a file in the requested directory
file_location = design.export_to_step(download_dir)

# Print the file location
print(f"Design exported to {file_location}")
print(f"Does the file exist? {Path(file_location).exists()}")
Design exported to C:\Users\Public\actions-runner\_work\pyansys-geometry\pyansys-geometry\doc\source\examples\03_modeling\downloads\ExportDesignExample.stp
Does the file exist? True

Export to IGES format#

[8]:
# Export the design to a file in the requested directory
file_location = design.export_to_iges(download_dir)

# Print the file location
print(f"Design exported to {file_location}")
print(f"Does the file exist? {Path(file_location).exists()}")
Design exported to C:\Users\Public\actions-runner\_work\pyansys-geometry\pyansys-geometry\doc\source\examples\03_modeling\downloads\ExportDesignExample.igs
Does the file exist? True

Export to FMD format#

[9]:
# Export the design to a file in the requested directory
file_location = design.export_to_fmd(download_dir)

# Print the file location
print(f"Design exported to {file_location}")
print(f"Does the file exist? {Path(file_location).exists()}")
Design exported to C:\Users\Public\actions-runner\_work\pyansys-geometry\pyansys-geometry\doc\source\examples\03_modeling\downloads\ExportDesignExample.fmd
Does the file exist? True

Export to PMDB format#

[10]:
# Export the design to a file in the requested directory
file_location = design.export_to_pmdb(download_dir)

# Print the file location
print(f"Design exported to {file_location}")
print(f"Does the file exist? {Path(file_location).exists()}")
Design exported to C:\Users\Public\actions-runner\_work\pyansys-geometry\pyansys-geometry\doc\source\examples\03_modeling\downloads\ExportDesignExample.pmdb
Does the file exist? True