Salome HOME
Merge branch 'V8_4_BR'
[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 - :ref:`Structured documentation <modules_page>`, where all methods and classes are grouped by their functionality.
13
14 - :ref:`Linear documentation <genindex>` grouped only by classes, declared in the :mod:`smeshBuilder` and :mod:`StdMeshersBuilder` Python packages.
15
16 With SALOME 7.2, the Python interface for Mesh has been slightly modified to offer new functionality.
17
18 You may have to modify your scripts generated with SALOME 6 or older versions.
19
20 Please see :ref:`smesh_migration_page`.
21
22 Class :class:`smeshBuilder.smeshBuilder` provides an interface to create and handle
23 meshes. It can be used to create an empty mesh or to import mesh from the data file.
24
25 As soon as a mesh is created, it is possible to manage it via its own
26 methods, described in class :class:`smeshBuilder.Mesh` documentation.
27
28 Class :class:`smeshstudytools.SMeshStudyTools` provides several methods to manipulate mesh objects in Salome study. 
29
30 A usual workflow to generate a mesh on geometry is following:
31
32 #. Create an instance of :class:`smeshBuilder.smeshBuilder`:
33         .. code-block:: python
34                 :linenos:
35
36                 from salome.smesh import smeshBuilder
37                 smesh = smeshBuilder.New( salome.myStudy )
38
39 #. Create a :class:`smeshBuilder.Mesh` object:
40
41         .. code-block:: python
42                 :linenos:
43
44                 mesh = smesh.Mesh( geometry )
45
46 #. Create and assign :ref:`basic_meshing_algos_page` by calling corresponding methods of the mesh. If a sub-shape is provided as an argument, a :ref:`constructing_submeshes_page` is implicitly created on this sub-shape:
47         .. code-block:: python
48                 :linenos:
49
50                 regular1D = smeshBuilder.Mesh.Segment()
51                 mefisto   = smeshBuilder.Mesh.Triangle( smeshBuilder.MEFISTO )
52                 # use other triangle algorithm on a face -- a sub-mesh appears in the mesh
53                 netgen    = smeshBuilder.Mesh.Triangle( smeshBuilder.NETGEN_1D2D, face )
54
55 #. Create and assign :ref:`about_hypo_page` by calling corresponding methods of algorithms:
56         .. code-block:: python
57                 :linenos:
58
59                 segLen10 = StdMeshersBuilder.StdMeshersBuilder_Segment.LocalLength( 10. )
60                 maxArea  = StdMeshersBuilder.StdMeshersBuilder_Segment.LocalLength( 100. )
61                 netgen.SetMaxSize( 20. )
62                 netgen.SetFineness( smeshBuilder.VeryCoarse )
63   
64 #. :ref:`compute_anchor` the mesh (generate mesh nodes and elements):
65         .. code-block:: python
66                 :linenos:
67
68                 Mesh.Compute()
69
70 An easiest way to start with Python scripting is to do something in
71 GUI and then to get a corresponding Python script via 
72 **File > Dump Study** menu item. Don't forget that you can get
73 all methods of any object in hand (e.g. a mesh group or a hypothesis)
74 by calling *dir()* Python built-in function.
75
76 All methods of the Mesh Group can be found in :ref:`tui_create_standalone_group` sample script.
77
78 An example below demonstrates usage of the Python API for 3d mesh
79 generation and for retrieving information on mesh nodes and elements.
80
81 .. _example_3d_mesh:
82
83 Example of 3d mesh generation:
84 ##############################
85
86 .. _3dmesh.py:
87
88 ``3dmesh.py`` 
89
90
91 .. literalinclude:: ../../../examples/3dmesh.py
92     :linenos:
93     :language: python
94
95 :download:`../../../examples/3dmesh.py`
96
97 Examples of Python scripts for Mesh operations are available by
98 the following links:
99
100 - :ref:`tui_creating_meshes_page`
101 - :ref:`tui_defining_hypotheses_page`
102 - :ref:`tui_grouping_elements_page`
103 - :ref:`tui_filters_page`
104 - :ref:`tui_modifying_meshes_page`
105 - :ref:`tui_transforming_meshes_page`
106 - :ref:`tui_viewing_meshes_page`
107 - :ref:`tui_quality_controls_page`
108 - :ref:`tui_measurements_page`
109 - :ref:`tui_work_on_objects_from_gui`
110 - :ref:`tui_notebook_smesh_page`
111 - :ref:`tui_cartesian_algo`
112 - :ref:`tui_use_existing_faces`
113 - :ref:`tui_prism_3d_algo`
114 - :ref:`tui_generate_flat_elements_page`
115
116
117
118 .. toctree::
119         :maxdepth: 2
120
121         smesh_migration.rst