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
33 from salome.smesh import smeshBuilder
34 smesh = smeshBuilder.New()
36 #. Create a :class:`smeshBuilder.Mesh` object:
38 .. code-block:: python
40 mesh = smesh.Mesh( geometry )
42 #. 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:
43 .. code-block:: python
45 regular1D = mesh.Segment()
46 mefisto = mesh.Triangle( smeshBuilder.MEFISTO )
47 # use other triangle algorithm on a face -- a sub-mesh appears in the mesh
48 netgen = mesh.Triangle( smeshBuilder.NETGEN_1D2D, face )
50 #. Create and assign :ref:`hypotheses <about_hypo_page>` by calling corresponding methods of algorithms:
51 .. code-block:: python
53 segLen10 = regular1D.LocalLength( 10. )
54 maxArea = mefisto.LocalLength( 100. )
55 netgen.SetMaxSize( 20. )
56 netgen.SetFineness( smeshBuilder.VeryCoarse )
58 #. :ref:`Compute the mesh <compute_anchor>` (generate mesh nodes and elements):
59 .. code-block:: python
63 An easiest way to start with Python scripting is to do something in
64 GUI and then to get a corresponding Python script via
65 **File > Dump Study** menu item. Don't forget that you can get
66 all methods of any object in hand (e.g. a mesh group or a hypothesis)
67 by calling *dir()* Python built-in function.
69 All methods of the :class:`Mesh Group <SMESH.SMESH_GroupBase>` can be found in :ref:`tui_create_standalone_group` sample script.
71 An example below demonstrates usage of the Python API for 3D mesh
72 generation and for retrieving basic information on mesh nodes, elements and groups.
76 Example of 3d mesh generation:
77 ##############################
79 .. literalinclude:: ../../../examples/3dmesh.py
82 :download:`Download this script <../../../examples/3dmesh.py>`
84 Examples of Python scripts for Mesh operations are available by
91 tui_defining_hypotheses
95 tui_transforming_meshes
100 tui_work_on_objects_from_gui
108 StdMeshersBuilder.rst