|
| 1 | +--- |
| 2 | +jupytext: |
| 3 | + text_representation: |
| 4 | + extension: .mystnb |
| 5 | + format_name: myst |
| 6 | + format_version: 0.13 |
| 7 | + jupytext_version: 1.14.1 |
| 8 | +kernelspec: |
| 9 | + display_name: Python 3 (ipykernel) |
| 10 | + language: python |
| 11 | + name: python3 |
| 12 | +--- |
| 13 | + |
| 14 | +# Modeling: Exporting designs |
| 15 | + |
| 16 | +After creating a design, you typically want to bring it into a CAD tool for further |
| 17 | +development. This notebook demonstrates how to export a design to the various supported |
| 18 | +CAD formats. |
| 19 | + |
| 20 | +## Create a design |
| 21 | + |
| 22 | +The code creates a simple design for demonstration purposes. The design consists of |
| 23 | +a set of rectangular pads with a circular hole in the center. |
| 24 | + |
| 25 | +```{code-cell} ipython3 |
| 26 | +from ansys.geometry.core import Modeler |
| 27 | +from ansys.geometry.core.math import UNITVECTOR3D_X, UNITVECTOR3D_Y, Point2D |
| 28 | +from ansys.geometry.core.sketch import Sketch |
| 29 | + |
| 30 | +# Instantiate the modeler - this connects to the service |
| 31 | +modeler = Modeler() |
| 32 | + |
| 33 | +# Create a design |
| 34 | +design = modeler.create_design("ExportDesignExample") |
| 35 | + |
| 36 | +# Create a sketch |
| 37 | +sketch = Sketch() |
| 38 | + |
| 39 | +# Create a simple rectangle |
| 40 | +sketch.box(Point2D([0, 0]), 10, 5) |
| 41 | + |
| 42 | +# Extrude the sketch and displace the resulting body |
| 43 | +# to make a plane of rectangles |
| 44 | +for x_step in [-60, -45, -30, -15, 0, 15, 30, 45, 60]: |
| 45 | + for y_step in [-40, -30, -20, -10, 0, 10, 20, 30, 40]: |
| 46 | + # Extrude the sketch |
| 47 | + body = design.extrude_sketch(f"Body_X_{x_step}_Y_{y_step}", sketch, 5) |
| 48 | + |
| 49 | + # Displace the body in the x and y directions |
| 50 | + body.translate(UNITVECTOR3D_X, x_step) |
| 51 | + body.translate(UNITVECTOR3D_Y, y_step) |
| 52 | + |
| 53 | +# Plot the design |
| 54 | +design.plot() |
| 55 | +``` |
| 56 | + |
| 57 | +## Export the design |
| 58 | + |
| 59 | +You can export the design to various CAD formats. For the formats supported |
| 60 | +see the [DesignFileFormat](https://geometry.docs.pyansys.com/version/stable/api/ansys/geometry/core/designer/design/DesignFileFormat.html) |
| 61 | +class, which is part of the the ``design`` module documentation. |
| 62 | + |
| 63 | +Nonetheless, there are a set of convenience methods that you can use to export |
| 64 | +the design to the supported formats. The following code snippets demonstrate how |
| 65 | +to do it. You can decide whether to export the design to a file in |
| 66 | +a certain directory or in the current working directory. |
| 67 | + |
| 68 | +### Export to a file in the current working directory |
| 69 | + |
| 70 | +```{code-cell} ipython3 |
| 71 | +# Export the design to a file in the current working directory |
| 72 | +file_location = design.export_to_scdocx() |
| 73 | +print(f"Design exported to {file_location}") |
| 74 | +``` |
| 75 | + |
| 76 | +### Export to a file in a certain directory |
| 77 | + |
| 78 | +```{code-cell} ipython3 |
| 79 | +from pathlib import Path |
| 80 | + |
| 81 | +# Define a downloads directory |
| 82 | +download_dir = Path.cwd() / "downloads" |
| 83 | + |
| 84 | +# Export the design to a file in a certain directory |
| 85 | +file_location = design.export_to_scdocx(download_dir) |
| 86 | +print(f"Design exported to {file_location}") |
| 87 | +``` |
| 88 | + |
| 89 | +### Export to SCDOCX format |
| 90 | + |
| 91 | +```{code-cell} ipython3 |
| 92 | +# Export the design to a file in the requested directory |
| 93 | +file_location = design.export_to_scdocx(download_dir) |
| 94 | + |
| 95 | +# Print the file location |
| 96 | +print(f"Design exported to {file_location}") |
| 97 | +print(f"Does the file exist? {Path(file_location).exists()}") |
| 98 | +``` |
| 99 | + |
| 100 | +### Export to Parasolid text format |
| 101 | + |
| 102 | +```{code-cell} ipython3 |
| 103 | +# Export the design to a file in the requested directory |
| 104 | +file_location = design.export_to_parasolid_text(download_dir) |
| 105 | + |
| 106 | +# Print the file location |
| 107 | +print(f"Design exported to {file_location}") |
| 108 | +print(f"Does the file exist? {Path(file_location).exists()}") |
| 109 | +``` |
| 110 | + |
| 111 | +### Export to Parasolid binary format |
| 112 | + |
| 113 | +```{code-cell} ipython3 |
| 114 | +# Export the design to a file in the requested directory |
| 115 | +file_location = design.export_to_parasolid_bin(download_dir) |
| 116 | + |
| 117 | +# Print the file location |
| 118 | +print(f"Design exported to {file_location}") |
| 119 | +print(f"Does the file exist? {Path(file_location).exists()}") |
| 120 | +``` |
| 121 | + |
| 122 | +### Export to STEP format |
| 123 | + |
| 124 | +```{code-cell} ipython3 |
| 125 | +# Export the design to a file in the requested directory |
| 126 | +file_location = design.export_to_step(download_dir) |
| 127 | + |
| 128 | +# Print the file location |
| 129 | +print(f"Design exported to {file_location}") |
| 130 | +print(f"Does the file exist? {Path(file_location).exists()}") |
| 131 | +``` |
| 132 | + |
| 133 | +### Export to IGES format |
| 134 | + |
| 135 | +```{code-cell} ipython3 |
| 136 | +# Export the design to a file in the requested directory |
| 137 | +file_location = design.export_to_iges(download_dir) |
| 138 | + |
| 139 | +# Print the file location |
| 140 | +print(f"Design exported to {file_location}") |
| 141 | +print(f"Does the file exist? {Path(file_location).exists()}") |
| 142 | +``` |
| 143 | + |
| 144 | +### Export to FMD format |
| 145 | + |
| 146 | +```{code-cell} ipython3 |
| 147 | +# Export the design to a file in the requested directory |
| 148 | +file_location = design.export_to_fmd(download_dir) |
| 149 | + |
| 150 | +# Print the file location |
| 151 | +print(f"Design exported to {file_location}") |
| 152 | +print(f"Does the file exist? {Path(file_location).exists()}") |
| 153 | +``` |
| 154 | + |
| 155 | +### Export to PMDB format |
| 156 | + |
| 157 | +```{code-cell} ipython3 |
| 158 | +# Export the design to a file in the requested directory |
| 159 | +file_location = design.export_to_pmdb(download_dir) |
| 160 | + |
| 161 | +# Print the file location |
| 162 | +print(f"Design exported to {file_location}") |
| 163 | +print(f"Does the file exist? {Path(file_location).exists()}") |
| 164 | +``` |
0 commit comments