Personal tools
You are here: Home Forum Use Get all meshes of a study via python

Get all meshes of a study via python

Up to Use

Get all meshes of a study via python

Posted by Daniel at April 24. 2016

I can get a mesh for example by path and name in python:

salome.myStudy.FindObjectByPath("/Mesh/mymeshname").GetObject()

 

But how can I get all meshes and/or meshnames of a study?

Re: Get all meshes of a study via python

Posted by Saint Michael at April 25. 2016

Hi

smeshComp = salome.myStudy.FindComponent("SMESH")
if smeshComp:
    iterator = salome.myStudy.NewChildIterator( smeshComp )
    while iterator.More():
        sobj = iterator.Value()
        iterator.Next()
        if not hasattr( sobj.GetObject(), "NbNodes" ): continue
        mesh = smesh.Mesh( sobj.GetObject() )
        print sobj.GetName(), mesh.NbNodes()
       
St.Michael

Re: Get all meshes of a study via python

Posted by Daniel at April 25. 2016

thank you!

Re: Get all meshes of a study via python

Posted by Daniel at April 25. 2016

this only works inside salome console but not when my python script is added via ./salome start myscript.py?

Re: Get all meshes of a study via python

Posted by Saint Michael at April 25. 2016

What happens?

St.Michael

Re: Get all meshes of a study via python

Posted by Daniel at April 25. 2016

I think the problem is somewhere else. Does

salome.salome_init(filenameHDF)

open an existing study or only create a new one?

Re: Get all meshes of a study via python

Posted by Saint Michael at April 25. 2016

open an existing study

Re: Get all meshes of a study via python

Posted by Daniel at April 25. 2016

ok some questions to savemed:

It only works with 2 Arguments for me:

mymesh.ExportMED(medfilename, 0)

 

Documentation says 4? Python dump from salome and salome-meca GUI gives:

mymesh.ExportMED(r'/mymed.med', 0, SMESH.MED_V2_2, 1, None, 1)

this does not work via python script.

Also why is SMESH.MED_V2_2 a parameter in the dump? GUI says Med 3.1 in Salome and Med 3.0 in Salome-Meca.

 

Re: Get all meshes of a study via python

Posted by Saint Michael at April 25. 2016

mymesh.ExportMED(r'/mymed.med', 0, SMESH.MED_V2_2, 1, None, 1)

This must work as all parameters except a file name are default.

St.Michael

Re: Get all meshes of a study via python

Posted by Daniel at April 25. 2016

I get:

 

mymesh.ExportMED( r'/home/daniel/mymedmanuellaster2.med', 0, SMESH.MED_V2_2, 1, None ,1)

Traceback (most recent call last):

  File "<input>", line 1, in <module>

  File "/home/daniel/salome_mecab/appli_V2015_2/lib/python2.7/site-packages/salome/SMESH_Mesh_idl.py", line 903, in ExportMED

    return _omnipy.invoke(self, "ExportMED", _0_SMESH.SMESH_Mesh._d_ExportMED, args)

TypeError: Operation requires 2 arguments; 6 given

Re: Get all meshes of a study via python

Posted by Daniel at April 25. 2016

mymesh = salome.myStudy.FindObjectByPath("/Mesh/mymesh").GetObject()

 

Re: Get all meshes of a study via python

Posted by Saint Michael at April 26. 2016

mymesh = salome.myStudy.FindObjectByPath("/Mesh/mymesh").GetObject()

This is a reason of the error. To fix it add this:

mymesh = smesh.Mesh( mymesh )

Powered by Ploneboard
Document Actions