.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\geometry-mesh\wf_gm_01_geometry.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_geometry-mesh_wf_gm_01_geometry.py: .. _ref_geometry-mesh_01-geometry: Geometry generation ################### This example shows how to generate a CAD file using PyAnsys Geometry via the Ansys Geometry Service. The example demonstrates how to create a sketch, perform modeling operations, and export the file in different formats (in this specific case, FMD). .. GENERATED FROM PYTHON SOURCE LINES 34-46 .. code-block:: Python import os from pathlib import Path from ansys.geometry.core import launch_modeler from ansys.geometry.core.connection import GeometryContainers import ansys.geometry.core.connection.defaults as pygeom_defaults from ansys.geometry.core.designer import DesignFileFormat from ansys.geometry.core.math import Point2D from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Distance from ansys.geometry.core.sketch import Sketch .. GENERATED FROM PYTHON SOURCE LINES 47-53 Preparing the environment ------------------------- This section is only necessary for workflow runs and docs generation. It checks the environment variables to determine which image to use for the geometry service. If you are running this script outside of a workflow, you can ignore this section. .. GENERATED FROM PYTHON SOURCE LINES 53-65 .. code-block:: Python image = None transport_mode = None if "ANSYS_GEOMETRY_RELEASE" in os.environ: image_tag = os.environ["ANSYS_GEOMETRY_RELEASE"] for geom_services in GeometryContainers: if image_tag == f"{pygeom_defaults.GEOMETRY_SERVICE_DOCKER_IMAGE}:{geom_services.value[2]}": print(f"Using {image_tag} image") image = geom_services transport_mode = "insecure" break .. rst-class:: sphx-glr-script-out .. code-block:: none Using ghcr.io/ansys/geometry:windows-25.1 image .. GENERATED FROM PYTHON SOURCE LINES 72-77 Parameters for the script ------------------------- The following parameters are used to control the script execution. You can modify these parameters to suit your needs. .. GENERATED FROM PYTHON SOURCE LINES 77-81 .. code-block:: Python GRAPHICS_BOOL = False # Set to True to display the graphics OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory .. GENERATED FROM PYTHON SOURCE LINES 86-92 Start a modeler session ----------------------- Start a modeler session to interact with the Ansys Geometry Service. The modeler object is used to create designs, sketches, and perform modeling operations. .. GENERATED FROM PYTHON SOURCE LINES 92-95 .. code-block:: Python modeler = launch_modeler(image=image, transport_mode=transport_mode) print(modeler) .. rst-class:: sphx-glr-script-out .. code-block:: none C:\Users\ansys\actions-runner\_work\pyansys-workflows\pyansys-workflows\.venv\Lib\site-packages\ansys\tools\common\cyberchannel.py:188: UserWarning: Starting gRPC client without TLS on localhost:700. This is INSECURE. Consider using a secure connection. warn(f"Starting gRPC client without TLS on {target}. This is INSECURE. Consider using a secure connection.") Ansys Geometry Modeler (0x1734eb20e30) Ansys Geometry Modeler Client (0x1734e870cb0) Target: localhost:700 Connection: Healthy Backend info: Version: 25.1.0 Backend type: WINDOWS_SERVICE Backend number: N/A API server number: N/A .. GENERATED FROM PYTHON SOURCE LINES 96-101 Create a sketch --------------- Create a sketch to define the geometry. The sketch is created in the XY plane and contains a rectangle and four circles. .. GENERATED FROM PYTHON SOURCE LINES 101-125 .. code-block:: Python # Define default length units DEFAULT_UNITS.LENGTH = UNITS.cm # Define the radius of the outer holes outer_hole_radius = Distance(0.5) sketch = Sketch() ( sketch.segment(start=Point2D([-4, 5]), end=Point2D([4, 5])) .segment_to_point(end=Point2D([4, -5])) .segment_to_point(end=Point2D([-4, -5])) .segment_to_point(end=Point2D([-4, 5])) .box( center=Point2D([0, 0]), width=Distance(3), height=Distance(3), ) .circle(center=Point2D([3, 4]), radius=outer_hole_radius) .circle(center=Point2D([-3, -4]), radius=outer_hole_radius) .circle(center=Point2D([-3, 4]), radius=outer_hole_radius) .circle(center=Point2D([3, -4]), radius=outer_hole_radius) ) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 126-132 Modeling operations ------------------- Now that the sketch is ready to be extruded, perform some modeling operations, including creating the design, creating the body directly on the design, and plotting the body. .. GENERATED FROM PYTHON SOURCE LINES 132-143 .. code-block:: Python # Start by creating the design design = modeler.create_design("ModelingDemo") # Create a body directly on the design by extruding the sketch body = design.extrude_sketch(name="Design_Body", sketch=sketch, distance=Distance(1)) # Plot the body if GRAPHICS_BOOL: design.plot() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/geometry-mesh/images/sphx_glr_wf_gm_01_geometry_001.png :alt: wf gm 01 geometry :srcset: /examples/geometry-mesh/images/sphx_glr_wf_gm_01_geometry_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: ./images/sphx_glr_wf_gm_01_geometry_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 144-152 Export the design ----------------- Once modeling operations are finalized, you can export files in different formats. For the formats supported by DMS, see the ``DesignFileFormat`` class in the ``Design`` module documentation. In this example, we will export files in SCDOCX and FMD formats. .. GENERATED FROM PYTHON SOURCE LINES 152-158 .. code-block:: Python # Download the design in FMD format OUTPUT_DIR.mkdir(exist_ok=True) download_file = Path(OUTPUT_DIR, "modeling_demo.fmd") design.download(file_location=download_file, format=DesignFileFormat.FMD) .. GENERATED FROM PYTHON SOURCE LINES 159-165 Close session ------------- When you finish interacting with your modeling service, you should close the active server session. This frees resources wherever the service is running. .. GENERATED FROM PYTHON SOURCE LINES 165-168 .. code-block:: Python # Close the server session. modeler.close() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 53.334 seconds) .. _sphx_glr_download_examples_geometry-mesh_wf_gm_01_geometry.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: wf_gm_01_geometry.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: wf_gm_01_geometry.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: wf_gm_01_geometry.zip `