From CAELinuxWiki
Revision as of 03:41, 23 October 2010 by JMB (Talk | contribs)

Jump to: navigation, search

Salome Python Coding: Where to Start?

Under Construction !!!

By Reading

1. Look at some code that is already out there on your PC! Click on the Help button of Salome's specific module (say Help -> Geometry Module -> User's Guide) and then in the browser (after enabling scripts, if they are disabled) Click on the little "+" beside "Introduction to Geometry" then the little "+" beside "Python Interface"; then the little "+" beside "Examples, generated from GEOM_SWIG test scripts" and finally "" or

2. Use the GUI to create a study: Geometry and Mesh using available tutorials on the Salome, CAELinux websites.


Then dump the study so that a *.py, a * and a * are created, which you can become the basis of your python code.

Learn how to take these python scripts and covert them to your own running scripts. There are YouTube videos that teach you how to do that. Search words "Salome Tutorial".

3. Read the docs at

The docs in your PC are under:

GEOM Module

 galeon file:///opt/salome_5.1.4/DOCUMENTATION_SRC_5.1.4/GEOM/tui/GEOM/index.html
 galeon file:///opt/salome_5.1.4/DOCUMENTATION_SRC_5.1.4/GEOM/gui/GEOM/index.html

MESH Module:

 galeon file:///opt/salome_5.1.4/DOCUMENTATION_SRC_5.1.4/SMESH/tui/SMESH/index.html
 galeon file:///opt/salome_5.1.4/DOCUMENTATION_SRC_5.1.4/SMESH/gui/SMESH/index.html


By Probing

As a shotgun approach to having all the modules available to you, in the Salome command console type the following:

import GEOM, geompy
import salome, SALOMEDS
import sys, math, time, os
import VISU, visu_gui

Then type:


You will get a long list such as the one below. The objects shown here will differ from your list, because it is specific to the study I captured it from. But some objects will be common such as GEOM, geompy, salome, SALOMEDS, sys, math, time, os, VISU and visu_gui, since you imported them earlier. Many others such as Compound_1_Faces, DefParabola, Depth, ... Z-Axis, Z_Master, etc. came from the script file that I used in my study.

['Box_1', 'Compound_1', 'Compound_1_Faces', 'DefParabola', 'Depth', 'Extrusion_1', 'Face_1', 'FileName', 'GEOM', 'Height', 'Help',
'Length', 'Line', 'LineList', 'MEFISTO_2D_1', 'Max_Size_1', 'Mesh_1', 'NMax', 'Origin', 'PT_Fixed', 'PT_Load', 'PathName', 
'PlaneDim', 'Regular_1D_1', 'SALOMEDS', 'SMESH', 'SalomeDoc', 'SaveStudy', 'Start', 'StdMeshers', 'Tetrahedron_Netgen', 'VISU', 
'Vertex1', 'Vertex2', 'Vertex_Final', 'Vertex_Initial', 'Width', 'Wire_1', 'X_Axis', 'Y_Axis', 'Z_Axis', 'Z_Fixed', 'Z_Load', 
'Z_Master', '__builtins__', '__doc__', '__name__', 'aColor', 'aCriterion', 'aFace', 'aPoint', 'geompy', 'i', 'index', 'math', 
'myCellEntity', 'myMeshName', 'myNodeEntity', 'myView', 'myViewManager', 'myVisu', 'name', 'os', 'salome', 'smesh', 'smeshDC',
'sys', 'time', 'visu_gui', 'x']

Since the list above shows 'Compound_1', 'Mesh_1', etc. (along with all other modules and objects in the study) ,let us try getting information about some the objects/methods available in a couple of them. If you did not create a compound geometry object you may not have an object called 'Compound_1'; just try it with any other geometric object that you did create (say 'Box_1', 'Sphere_1', etc.)

Since 'Compound_1' is one of the GEOM objects type:


This list will be more like what you will get, because the GEOM module's compound object has inherited much of its properties from other objects defined in the various Salome modules you imported earlier.

['Destroy', 'GetAutoColor', 'GetColor', 'GetDependency', 'GetEntry', 'GetLastDependency', 'GetMainShape', 'GetMarkerSize',
'GetMarkerTexture', 'GetMarkerType', 'GetName', 'GetParameters', 'GetShapeStream', 'GetShapeType', 'GetStudyEntry', 'GetStudyID',
'GetSubShapeIndices', 'GetType', 'IsMainShape', 'IsShape', 'Register', 'SetAutoColor', 'SetColor', 'SetMarkerStd', 'SetMarkerTexture',
'SetName', 'SetParameters', 'SetStudyEntry', '_NP_RepositoryId', '_Object__release', '__del__', '__doc__', '__getstate__', '__init__',
'__methods__', '__module__', '__omni_obj', '__setstate__', '_duplicate', '_get_interface', '_hash', '_is_a', '_is_equivalent', '_narrow',
'_nil', '_non_existent', '_release', '_unchecked_narrow', 'getShape']

Since 'Mesh_1' is one of the MESH module's object type: