Skip to content

Commit 3874efe

Browse files
RobPasMuepyansys-ci-botpre-commit-ci[bot]PipKat
authored
docs: add example on exporting designs (#1149)
Co-authored-by: pyansys-ci-bot <pyansys.github.bot@ansys.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>
1 parent feb5af6 commit 3874efe

File tree

7 files changed

+193
-9
lines changed

7 files changed

+193
-9
lines changed

doc/changelog.d/1149.miscellaneous.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs: add example on exporting designs
64.5 KB
Loading

doc/source/conf.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import os
66
from pathlib import Path
7+
import time
78

89
from ansys_sphinx_theme import (
910
ansys_favicon,
@@ -32,12 +33,25 @@ def get_wheelhouse_assets_dictionary():
3233
assets_context_runners = ["ubuntu-latest", "windows-latest", "macos-latest"]
3334
assets_context_python_versions = ["3.9", "3.10", "3.11", "3.12"]
3435
if get_version_match(__version__) == "dev":
35-
# Just point to the latest version
36-
assets_context_version = json.loads(
37-
requests.get(
36+
37+
# Try to retrieve the content three times before failing
38+
content = None
39+
for _ in range(3):
40+
response = requests.get(
3841
"https://api.github.com/repos/ansys/pyansys-geometry/releases/latest"
39-
).content
40-
)["name"]
42+
)
43+
if response.status_code == 200:
44+
content = response.content
45+
break
46+
else:
47+
print(f"Failed to retrieve the latest release. Retrying...")
48+
time.sleep(2)
49+
50+
if content is None:
51+
raise requests.exceptions.RequestException("Failed to retrieve the latest release.")
52+
53+
# Just point to the latest version
54+
assets_context_version = json.loads(content)["name"]
4155
else:
4256
assets_context_version = f"v{__version__}"
4357

@@ -261,6 +275,7 @@ def intersphinx_pyansys_geometry(switcher_version: str):
261275
"examples/03_modeling/boolean_operations": "_static/thumbnails/boolean_operations.png",
262276
"examples/03_modeling/scale_map_mirror_bodies": "_static/thumbnails/scale_map_mirror_bodies.png", # noqa: E501
263277
"examples/03_modeling/sweep_chain_profile": "_static/thumbnails/sweep_chain_profile.png",
278+
"examples/03_modeling/export_design": "_static/thumbnails/export_design.png",
264279
}
265280
nbsphinx_epilog = """
266281
----

doc/source/examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ These examples demonstrate service-based modeling operations.
4040
examples/03_modeling/boolean_operations.mystnb
4141
examples/03_modeling/scale_map_mirror_bodies.mystnb
4242
examples/03_modeling/sweep_chain_profile.mystnb
43+
examples/03_modeling/export_design.mystnb
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.scdocx
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
```

doc/styles/.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/*
2-
!**/ANSYS/accept.txt
3-
!**/ANSYS/reject.txt
4-
!.gitignore
1+
*
2+
!config
3+
!config/vocabularies
4+
!config/vocabularies/ANSYS
5+
!config/vocabularies/ANSYS/**
6+
!.gitignore

0 commit comments

Comments
 (0)