.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery_examples/gallery/12_import_from_pygeometry.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_gallery_examples_gallery_12_import_from_pygeometry.py: .. _ref_pygeometry_import: ================================= Import a geometry from PyGeometry ================================= **Summary**: This example demonstrates how to create a simple geometry using PyGeometry and import it into PyPrimeMesh. Procedure ~~~~~~~~~ #. Launch the Geometry service and create a simple geometry. #. Launch Ansys Prime Server. #. Create a CAD geometry with PyGeometry. #. Import the geometry into PyPrimeMesh. #. Mesh and display the imported geometry. #. Exit the PyPrimeMesh and PyGeometry sessions. Create the geometry ~~~~~~~~~~~~~~~~~~~ First we create a simple geometry using PyGeometry. The geometry is a plate with a hole in the center: .. code-block:: python from pint import Quantity from ansys.geometry.core import launch_modeler from ansys.geometry.core.math import Point2D from ansys.geometry.core.misc import UNITS from ansys.geometry.core.sketch import Sketch from ansys.geometry.core.math import Point2D modeler = launch_modeler(hidden=True) sketch = Sketch() ( sketch.segment(Point2D([-4, 5], unit=UNITS.mm), Point2D([4, 5], unit=UNITS.mm)) .segment_to_point(Point2D([4, -5], unit=UNITS.mm)) .segment_to_point(Point2D([-4, -5], unit=UNITS.mm)) .segment_to_point(Point2D([-4, 5], unit=UNITS.mm)) .box(Point2D([0, 0], unit=UNITS.mm), Quantity(3, UNITS.mm), Quantity(3, UNITS.mm)) ) design = modeler.create_design("ExtrudedPlateNoHoles") body = design.extrude_sketch(f"PlateLayer", sketch, Quantity(2, UNITS.mm)) sketch_hole = Sketch() sketch_hole.circle(Point2D([0, 0], unit=UNITS.mm), Quantity(0.5, UNITS.mm)) hole_centers = [ Plane(Point3D([3, 4, 0], unit=UNITS.mm)), Plane(Point3D([-3, 4, 0], unit=UNITS.mm)), Plane(Point3D([-3, -4, 0], unit=UNITS.mm)), Plane(Point3D([3, -4, 0], unit=UNITS.mm)), ] for center in hole_centers: sketch_hole.plane = center design.extrude_sketch( name=f"H_{center.origin.x}_{center.origin.y}", sketch=sketch_hole, distance=Quantity(2, UNITS.mm), cut=True, ) Import the geometry into PyPrimeMesh ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Once the geometry is created, we can pass the Design object to PyPrimeMesh to create a mesh: .. code-block:: python import ansys.meshing.prime as prime from ansys.meshing.prime.graphics.plotter import PrimePlotter prime_client = prime.launch_prime() model = prime_client.model mesh_util = prime.lucid.Mesh(model=model) mesh_util.from_geometry(design) Mesh the geometry and display it ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ With the geometry imported, we can now mesh it and display the mesh: .. code-block:: python model.set_global_sizing_params( prime.GlobalSizingParams(model, min=0.2, max=10.0, growth_rate=1.2) ) mesh_util.surface_mesh(min_size=0.2) mesh_util.volume_mesh() # Print the results model.parts[0].print_mesh = True print(model) display = PrimePlotter() display.plot(model) display.show() modeler.close() prime_client.exit() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.000 seconds) .. _sphx_glr_download_examples_gallery_examples_gallery_12_import_from_pygeometry.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 12_import_from_pygeometry.ipynb <12_import_from_pygeometry.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 12_import_from_pygeometry.py <12_import_from_pygeometry.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 12_import_from_pygeometry.zip <12_import_from_pygeometry.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_