Personal tools
You are here: Home Forum How to use Salome? interactive Python Console ?

interactive Python Console ?

Up to How to use Salome?

interactive Python Console ?

Posted by givlio at April 13. 2012

Hello,

I have a quite good knowledge on grafical commands of salome but I m not able to understand how the Python Console works.

Is it interactive?

For example , could I get a vertex coordinates typing the command directly in the console when the study is yet loaded or not?

I ask this because sometime we need to perform some simple math calculation with geometrical coordinates that could be implemented directly launching the script when the model is yet loaded.

 

Is otherwise possible to implement some new graphical commands directly in GEOM module defining the related math geometric formulas ?

 

Best Regards

Giulio

Re: interactive Python Console ?

Posted by Saint Michael at April 13. 2012

Hello

> could I get a vertex coordinates typing the command directly in the console when the study is yet loaded or not?

Yes:

>>> import salome, geompy
>>> studyObject = salome.myStudy.FindObjectID('0:1:1:1')
>>> vertex = studyObject.GetObject()
>>> geompy.PointCoordinates( vertex )

St.Michael

Re: interactive Python Console ?

Posted by givlio at May 02. 2012

Thanks for fast reply,

I had to study a bit Python to make it work properly,  I made in this way:

#####START CODE###

import salome,geompy

# Define myStudy (the current one if I am working in the GUI)
study = salome.myStudy

#a  is what I am searching for 
a = 'Vertex_1' is what I was looking for

sobject = study.FindObject( a )

# Transform the 'sobject' in 'object' (a geometrical instance I suppose)
vert = sobject.GetObject()

# Now I get the Point Coordinates from 'vert1' and put values in a Tuple
v_coord = geompy.PointCoordinates(vert)

print v_coord

 

### END CODE##

 

Now I would like to ask an input from the user to pass the script the value to search.

I thought tha raw_input() command could fit for this task but I receive an EOF Error , when the raw_input() works fine out from Salome (in a standard interactive Python shell):

is there a known bug for it? and is there any workaround to get a value from the user (maybe with the graphical interface directly)?

 

Best Regards

Giulio

Re: interactive Python Console ?

Posted by Saint Michael at May 02. 2012

A cheap solution is to use Notebook where the user can enter named variables. A 'nice' solution is to add a plug-in to SALOME (for docs see  http://docs.salome-platform.org/salome_6_4_0/gui/GUI/using_pluginsmanager.html, for demo see GUI_SRC/src/SalomeApp/pluginsdemo)

 

St.Michael

Re: interactive Python Console ?

Posted by givlio at May 02. 2012

1° question

Notebook?? I didnt find anything about it

2° question

Thanks for links, I tryed to implement my own script and it works directly from Tools->Plugin... but In the example there is not the code for a minimal graphical interface to pass some values to the python module (I see is written in PyQT), any hint about  writing it or when I could find the other module called 'Tube Mesh from parameters' shown in

  http://docs.salome-platform.org/salome_6_4_0/gui/GUI/using_pluginsmanager.html

?

3° question

>>> for demo see GUI_SRC/src/SalomeApp/pluginsdemo)

I didnt find anything named in this way , is it a web link or a link to the internal path of Salome installation.

 

Best Regards

Giulio

Re: interactive Python Console ?

Posted by Saint Michael at May 03. 2012

The user gets access to Notebook via menu File / Notebook...

GUI_SRC/src/SalomeApp/pluginsdemo is a path within SALOME sources, you can find same files in GUI/share/salome/plugins/gui/demo/ of SALOME installation

St.Michael

 

 

Re: interactive Python Console ?

Posted by givlio at May 03. 2012

Thanks a lot ,

It works fine with the GUI also passing strings and not only values and boolean values as in Notebook.

Another thing, is there any example implementing the direct mouse selection of an item? any documentation ?

Thanks a lot for your support

 

Best Regards

Giulio

Re: interactive Python Console ?

Posted by Saint Michael at May 04. 2012

See sample module ATOMGEN. Look for "selection" in ATOMGEN_SRC/src/ATOMGENGUI/ATOMGENGUI.py which is within SALOME sources.

St.Michael

Powered by Ploneboard
Document Actions