1 .. _smeshpy_interface_page:
7 Python API of SALOME Mesh module defines several classes that can
8 be used for easy mesh creation and edition.
10 Documentation of SALOME Mesh module Python API is available in two forms:
12 - :doc:`Structured documentation <modules>`, where all methods and classes are grouped by their functionality.
14 - :ref:`Linear documentation <modindex>` grouped only by classes, declared in the :mod:`smeshBuilder` Python module.
16 With SALOME 7.2, the Python interface for Mesh has been slightly modified to offer new functionality.
17 You may have to modify your scripts generated with SALOME 6 or older versions.
18 Please see :ref:`smesh_migration_page`.
20 Class :class:`smeshBuilder.smeshBuilder` provides an interface to create and handle
21 meshes. It can be used to create an empty mesh or to import mesh from the data file.
23 As soon as a mesh is created, it is possible to manage it via its own
24 methods, described in class :class:`smeshBuilder.Mesh` documentation.
26 Class :class:`smeshstudytools.SMeshStudyTools` provides several methods to manipulate mesh objects in Salome study.
28 A usual workflow to generate a mesh on geometry is following:
30 #. Create an instance of :class:`smeshBuilder.smeshBuilder`:
31 .. code-block:: python
34 from salome.smesh import smeshBuilder
35 smesh = smeshBuilder.New()
37 #. Create a :class:`smeshBuilder.Mesh` object:
39 .. code-block:: python
42 mesh = smesh.Mesh( geometry )
44 #. Create and assign :ref:`algorithms <basic_meshing_algos_page>` by calling corresponding methods of the mesh. If a sub-shape is provided as an argument, a :ref:`sub-mesh <constructing_submeshes_page>` is implicitly created on this sub-shape:
45 .. code-block:: python
48 regular1D = mesh.Segment()
49 mefisto = mesh.Triangle( smeshBuilder.MEFISTO )
50 # use other triangle algorithm on a face -- a sub-mesh appears in the mesh
51 netgen = mesh.Triangle( smeshBuilder.NETGEN_1D2D, face )
53 #. Create and assign :ref:`hypotheses <about_hypo_page>` by calling corresponding methods of algorithms:
54 .. code-block:: python
57 segLen10 = regular1D.LocalLength( 10. )
58 maxArea = mefisto.LocalLength( 100. )
59 netgen.SetMaxSize( 20. )
60 netgen.SetFineness( smeshBuilder.VeryCoarse )
62 #. :ref:`compute_anchor` the mesh (generate mesh nodes and elements):
63 .. code-block:: python
68 An easiest way to start with Python scripting is to do something in
69 GUI and then to get a corresponding Python script via
70 **File > Dump Study** menu item. Don't forget that you can get
71 all methods of any object in hand (e.g. a mesh group or a hypothesis)
72 by calling *dir()* Python built-in function.
74 All methods of the Mesh Group can be found in :ref:`tui_create_standalone_group` sample script.
76 An example below demonstrates usage of the Python API for 3D mesh
77 generation and for retrieving information on mesh nodes and elements.
81 Example of 3d mesh generation:
82 ##############################
84 .. literalinclude:: ../../../examples/3dmesh.py
88 :download:`Download this script <../../../examples/3dmesh.py>`
90 Examples of Python scripts for Mesh operations are available by
97 tui_defining_hypotheses
101 tui_transforming_meshes
105 tui_work_on_objects_from_gui
108 tui_use_existing_faces
110 tui_generate_flat_elements
117 StdMeshersBuilder.rst