Using SALOME GUI python interface

The extended salome.py Python module provides sg variable, which gives access to some GUI functions.

Note, that this variable is not available if you use salome.py Python module outside of the GUI desktop, i.e. without the embedded Python console (since SWIG library is linked directly to the GUI library).

The example of usage:

 1     # update Object browser contents
 2     salome.sg.updateObjBrowser(True)
 3
 4     # get the active study ID
 5     studyId = salome.sg.getActiveStudyId()
 6
 7     # get the active study name
 8     studyName = salome.sg.getActiveStudyName()
 9
10     # get the selected objects
11     selCount = salome.sg.SelectedCount() # the number of selected items
12     for i in range(selCount):
13         print salome.sg.getSelected(i) # print the entry ID of i-th selected item
 1     # get the list of IDs of all selected objects
 2     selected = salome.sg.getAllSelected()
 3
 4     # add an object to the selection
 5     salome.sg.AddIObject("0:1:1:1") # "0:1:1:1" is an object ID
 6
 7     # remove an object from the selection (make it unselected)
 8     salome.sg.RemoveIObject("0:1:1:1") # "0:1:1:1" is an object ID
 9
10     # clear the selection (set all objects unselected)
11     salome.sg.ClearIObjects()
12
13     # display an object in the current view (if possible)
14     salome.sg.Display("0:1:1:1") # "0:1:1:1" is an object ID
15     salome.sg.UpdateView() # update view
16
17     # erase an object from the current view
18     salome.sg.Erase("0:1:1:1") # "0:1:1:1" is an object ID
19     salome.sg.UpdateView() # update view
20
21     # display all objects in the current view (if possible)
22     salome.sg.DisplayAll()
23     salome.sg.UpdateView() # update view
24
25     # erase all objects from the current view
26     salome.sg.EraseAll()
27     salome.sg.UpdateView() # update view
28
29     # set top, bottom, front, rear, left, right view
30     salome.sg.ViewTop() # top view
31     salome.sg.ViewBottom() # bottom view
32     salome.sg.ViewFront() # front view
33     salome.sg.ViewTop() #  back view
34     salome.sg.ViewLeft() # left view
35     salome.sg.ViewRight() # right view
36
37     # reset the current view
38     salome.sg.ResetView()
39
40     # get the component symbolic name by its user name
41     compName = salome.sg.getComponentName("Geometry") # compoName = "GEOM"
42
43     # get the component user name by its symbolic name
44     compName = salome.sg.getComponentUserName("SMESH") # compoName = "Mesh"
45
46     # ...