Personal tools
You are here: Home Forum Use Select nodes/Elements by location using a script?

Select nodes/Elements by location using a script?

Up to Use

Select nodes/Elements by location using a script?

Posted by pete Halverson at February 08. 2010 20:40:57

Is it possible to select nodes/elements by location using a script? for example let's say there is a node at (100,0,0). Or an element that contains nodes 1,2,3 at locations (100,0,0) (100,1,0) (101,1,0).  I've been looking through the documentation off and on for the last couple of weeks but can't seem to sort out the TUI stuff.

 

Thanks,

 

Peter

Re: Select nodes/Elements by location using a script?

Posted by Christophe Bourcier at February 09. 2010 10:22:04

To select a node you can use:

id_node = Mesh.FindNodeClosestTo(x, y, z)

To select elements by a point coordinates:

l_id_elements = Mesh.FindElementsByPoint(x, y, z)

You can open the file SMESH/bin/salome/smeshDC.py to browse all the smesh methods. In my opinion, it's much more convenient than browsing the online help ;)

Christophe

Re: Select nodes/Elements by location using a script?

Posted by pete Halverson at February 09. 2010 16:18:42

Previously Christophe Bourcier wrote:

You can open the file SMESH/bin/salome/smeshDC.py to browse all the smesh methods. In my opinion, it's much more convenient than browsing the online help ;)


Brilliant! Absolutely brilliant!

Re: Select nodes/Elements by location using a script?

Posted by JMB at July 30. 2010 19:54:12

Previously Christophe Bourcier wrote:

To select a node you can use:

id_node = Mesh.FindNodeClosestTo(x, y, z)

To select elements by a point coordinates:

l_id_elements = Mesh.FindElementsByPoint(x, y, z)

You can open the file SMESH/bin/salome/smeshDC.py to browse all the smesh methods. In my opinion, it's much more convenient than browsing the online help ;)

Christophe

Hello,

 

I am new to programming in Python and in Salome TUI, so I need some low level help!  I am trying what you suggested above but have not succeeded so far.  I have tried:

 

import MESH

ImportError: No module named MESH

dir(MESH) : .... long list ... but no FindElementsByPoint

 

import Mesh:

ImportError: No module named Mesh

 

import(smesh)

dir(smesh) : .... long list ... but no FindElementsByPoint

 

import SMESH

dir(SMESH) : .... long list ... but no FindElementsByPoint

 

import smeshDC

elem = smeshDC.FindElementsByPoint(x,y,z, SMESH.ALL)

AttributeError: 'module' object has no attribute 'FindElementsByPoint'

dir(smeshDC) : .... long list ... but no FindElementsByPoint

 

I see a 'def FindElementByPoint()' in .../bin/salome/smeshDC.py so why doesn't it work?!  How should even begin...?  Thanks for any help.

 

Regards,

JMB


Re: Select nodes/Elements by location using a script?

Posted by pete Halverson at July 31. 2010 01:53:03

Are you trying it in the python code window inside Salome or are you opening python. You need to source the environment to be able to use python. When I get time I'll upload an example here.

Re: Select nodes/Elements by location using a script?

Posted by JMB at July 31. 2010 02:12:18

Previously pete Halverson wrote:

Are you trying it in the python code window inside Salome or are you opening python. You need to source the environment to be able to use python. When I get time I'll upload an example here.

Hello Pete,

I am trying it inside Salome (in its command window), which is why I am puzzled.  Do I specifically need to be viewing a VTK window, because that is one thing I did not try.   Meshing TUIs I have written work quite well regardless of which viewer is open (OCC / VTK).  Yes an example would be very useful, thank you!

Regards,

JMB

Re: Select nodes/Elements by location using a script?

Posted by DAVID Gilles at July 31. 2010 17:57:45

The variable Mesh is not a module but the instance of a Mesh:

Mesh = smesh.Mesh(myGeom)

Re: Select nodes/Elements by location using a script?

Posted by JMB at August 01. 2010 02:47:39

Previously DAVID Gilles wrote:

The variable Mesh is not a module but the instance of a Mesh:

Mesh = smesh.Mesh(myGeom)

Aaah!  Thank you!  It just proves I can stare long enough my own code and actually become more stupid... :)

JMB

Powered by Ploneboard
Document Actions