Salome HOME
Fix MinDistance for node-group (SALOME_TESTS/Grids/smesh/imps_09/K0)
[modules/smesh.git] / doc / salome / gui / SMESH / input / smeshpy_interface.rst
1 .. _smeshpy_interface_page:
2
3 ****************
4 Python interface
5 ****************
6
7 Python API of SALOME Mesh module defines several classes that can
8 be used for easy mesh creation and edition.
9
10 Documentation of SALOME Mesh module Python API is available in two forms:
11
12 - :doc:`Structured documentation <modules>`, where all methods and classes are grouped by their functionality.
13
14 - :ref:`Linear documentation <modindex>` grouped only by classes, declared in the :mod:`smeshBuilder` Python module.
15
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`.
19
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.
22
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.
25
26 Class :class:`smeshstudytools.SMeshStudyTools` provides several methods to manipulate mesh objects in Salome study. 
27
28 A usual workflow to generate a mesh on geometry is following:
29
30 #. Create an instance of :class:`smeshBuilder.smeshBuilder`:
31         .. code-block:: python
32
33                 from salome.smesh import smeshBuilder
34                 smesh = smeshBuilder.New()
35
36 #. Create a :class:`smeshBuilder.Mesh` object:
37
38         .. code-block:: python
39
40                 mesh = smesh.Mesh( geometry )
41
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
44
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 )
49
50 #. Create and assign :ref:`hypotheses <about_hypo_page>` by calling corresponding methods of algorithms:
51         .. code-block:: python
52
53                 segLen10 = regular1D.LocalLength( 10. )
54                 maxArea  = mefisto.LocalLength( 100. )
55                 netgen.SetMaxSize( 20. )
56                 netgen.SetFineness( smeshBuilder.VeryCoarse )
57   
58 #. :ref:`Compute the mesh <compute_anchor>` (generate mesh nodes and elements):
59         .. code-block:: python
60
61                 mesh.Compute()
62
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.
68
69 All methods of the :class:`Mesh Group <SMESH.SMESH_GroupBase>` can be found in :ref:`tui_create_standalone_group` sample script.
70
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.
73
74 .. _example_3d_mesh:
75
76 Example of 3d mesh generation:
77 ##############################
78
79 .. literalinclude:: ../../../examples/3dmesh.py
80     :language: python
81
82 :download:`Download this script <../../../examples/3dmesh.py>`
83
84 Examples of Python scripts for Mesh operations are available by
85 the following links:
86
87 .. toctree::
88    :titlesonly:
89
90    tui_creating_meshes
91    tui_defining_hypotheses
92    tui_grouping_elements
93    tui_filters
94    tui_modifying_meshes
95    tui_transforming_meshes
96    tui_viewing_meshes
97    tui_quality_controls
98    tui_measurements
99    tui_work_on_objects_from_gui
100    tui_notebook_smesh
101
102 .. toctree::
103    :hidden:
104
105    smesh_migration.rst
106    smeshBuilder.rst
107    StdMeshersBuilder.rst
108    smeshstudytools.rst
109    modules.rst
110    smesh_module.rst