|
| 1 | +--- |
| 2 | +title: PyAnsys Geometry cheat sheet |
| 3 | +format: cheat_sheet-pdf |
| 4 | +params: |
| 5 | + version: main |
| 6 | +footer: PyAnsys Geometry |
| 7 | +footerlinks: |
| 8 | + - urls: 'https://geometry.docs.pyansys.com/version/stable/' |
| 9 | + text: Documentation |
| 10 | + - urls: 'https://geometry.docs.pyansys.com/version/stable/getting_started/index.html' |
| 11 | + text: Getting started |
| 12 | + - urls: 'https://geometry.docs.pyansys.com/version/stable/examples.html' |
| 13 | + text: Examples |
| 14 | + - urls: 'https://geometry.docs.pyansys.com/version/stable/api/index.html' |
| 15 | + text: API reference |
| 16 | + - urls: 'https://geometry.docs.pyansys.com/version/stable/getting_started/faq.html' |
| 17 | + text: FAQ |
| 18 | + - urls: 'https://github.com/ansys/pyansys-geometry/discussions' |
| 19 | + text: Discussions |
| 20 | + - urls: 'https://github.com/ansys/pyansys-geometry/issues' |
| 21 | + text: 'Issues' |
| 22 | +# execute: |
| 23 | +# output: false |
| 24 | + |
| 25 | +latex-clean: true |
| 26 | +jupyter: |
| 27 | + jupytext: |
| 28 | + text_representation: |
| 29 | + extension: .qmd |
| 30 | + format_name: quarto |
| 31 | + format_version: '1.0' |
| 32 | + jupytext_version: 1.16.1 |
| 33 | + kernelspec: |
| 34 | + display_name: Python 3 (ipykernel) |
| 35 | + language: python |
| 36 | + name: python3 |
| 37 | +--- |
| 38 | + |
| 39 | +# Verify your installation |
| 40 | + |
| 41 | +## Check your PyAnsys Geometry version |
| 42 | +```{python} |
| 43 | +from ansys.geometry.core import __version__ |
| 44 | +print(f"PyAnsys Geometry version: {__version__}") |
| 45 | +``` |
| 46 | + |
| 47 | +# Sketching |
| 48 | + |
| 49 | +There are two ways of creating 2D sketches in PyAnsys Geometry. |
| 50 | + |
| 51 | +```{python} |
| 52 | +from ansys.geometry.core.sketch import Sketch |
| 53 | +from ansys.geometry.core.math import Point2D |
| 54 | +``` |
| 55 | + |
| 56 | +## Functional-style sketching |
| 57 | + |
| 58 | +```{python} |
| 59 | +#| output: false |
| 60 | +sketch = Sketch() |
| 61 | +
|
| 62 | +( |
| 63 | + sketch |
| 64 | + .segment_to_point(Point2D([3, 3]), "Segment2") |
| 65 | + .segment_to_point(Point2D([3, 2]), "Segment3") |
| 66 | + .segment_to_point(Point2D([0, 0]), "Segment4") |
| 67 | +) |
| 68 | +``` |
| 69 | + |
| 70 | +You can visualize the sketch by calling the `plot` method. |
| 71 | + |
| 72 | +```{python} |
| 73 | +#| output: false |
| 74 | +sketch.plot() |
| 75 | +``` |
| 76 | + |
| 77 | +## Object-oriented sketching |
| 78 | + |
| 79 | +```{python} |
| 80 | +#| output: false |
| 81 | +sketch = Sketch() |
| 82 | +
|
| 83 | +sketch.triangle( |
| 84 | + Point2D([-10, 10]), |
| 85 | + Point2D([5, 6]), |
| 86 | + Point2D([-10, -10]), |
| 87 | +) |
| 88 | +``` |
| 89 | + |
| 90 | +# Modeling |
| 91 | + |
| 92 | +## Launch a modeling session |
| 93 | + |
| 94 | +```{python} |
| 95 | +from ansys.geometry.core import launch_modeler |
| 96 | +modeler = launch_modeler() |
| 97 | +print(modeler) |
| 98 | +``` |
| 99 | + |
| 100 | +By default, it will detect which modeling service |
| 101 | +is available on your system and launch it. If you |
| 102 | +have multiple modeling services installed, you can |
| 103 | +specify which one to use by passing the `mode` argument. |
| 104 | + |
| 105 | +```{python} |
| 106 | +#| eval: false |
| 107 | +modeler = launch_modeler(mode='spaceclaim') |
| 108 | +modeler = launch_modeler(mode='discovery') |
| 109 | +modeler = launch_modeler(mode='geometry_service') |
| 110 | +``` |
| 111 | + |
| 112 | +## Connect to an existing modeler |
| 113 | + |
| 114 | +```{python} |
| 115 | +#| output: false |
| 116 | +from ansys.geometry.core import Modeler |
| 117 | +modeler = Modeler() |
| 118 | +print(modeler) |
| 119 | +``` |
| 120 | + |
| 121 | +## Create a design |
| 122 | + |
| 123 | +```{python} |
| 124 | +design = modeler.create_design("MyDesign") |
| 125 | +print(design) |
| 126 | +``` |
| 127 | + |
| 128 | +## Create a body by extruding a sketch |
| 129 | + |
| 130 | +```{python} |
| 131 | +body = design.extrude_sketch("MyBody", sketch, 2) |
| 132 | +print(body) |
| 133 | +``` |
| 134 | + |
| 135 | +## Plot the design |
| 136 | + |
| 137 | +```{python} |
| 138 | +#| output: false |
| 139 | +design.plot() |
| 140 | +``` |
| 141 | + |
| 142 | +## Export the design to a file |
| 143 | + |
| 144 | +```{python} |
| 145 | +scdocx_path = design.export_to_scdocx() |
| 146 | +pmdb_path = design.export_to_pmdb() |
| 147 | +para_txt_path = design.export_to_parasolid_text() |
| 148 | +para_bin_path = design.export_to_parasolid_bin() |
| 149 | +fmd_path = design.export_to_fmd() |
| 150 | +step_path = design.export_to_step() |
| 151 | +iges_path = design.export_to_iges() |
| 152 | +``` |
| 153 | + |
| 154 | +# Extra: Product scripting |
| 155 | + |
| 156 | +Ansys SpaceClaim and Ansys Discovery support product scripting, and |
| 157 | +so does the Ansys Geometry service. If you have a product script you |
| 158 | +want to run, you can use the `run_discovery_script_file` method available |
| 159 | +on the `Modeler` object. The ``script_args`` parameter is optional and they |
| 160 | +will be made available to the script inside a dictionary called ``argsDict``. |
| 161 | + |
| 162 | +```{python} |
| 163 | +#| eval: false |
| 164 | +result = modeler.run_discovery_script_file( |
| 165 | + file_path="path/to/script.py", |
| 166 | + script_args={"arg1": "value1", "arg2": "value2"}, |
| 167 | +) |
| 168 | +``` |
0 commit comments