Personal tools
You are here: Home Forum Use Loading existing hdf-files from within a python script

Loading existing hdf-files from within a python script

Up to Use

Loading existing hdf-files from within a python script

Posted by Malleus at January 30. 2019

Hello,

 

I am having troubles with loading existing hdf-files from within a python script.

I am aware that this question has been posted here before a couple of times, but the answers given there do not work for me.

 

Briefly, what I intend to do is the following:

 

I wish to split my Salome workflow into sections that deal with geometry only, and mesh only, respectively. Ideally, I

 

  1. create a python file with geometry specifications;
  2. save the geometry, either manually or programmatically from within the script, as an hdf-file;
  3. load the hdf-file from within another python file that deals with mesh creation only.
 
The idea behind this is to save time when the geometry and/or mesh are so complex as to take up a lot of time when produced from the python script directly; instead, once the geometry is done, I could load it from the hdf-file and subsequently work upon mesh specifications.
 
I have tried the recipes given here in this forum to achieve step 3 above, but have always failed so far. The reason is that, once the hdf-file is loaded from within the second script, geometry objects are no longer recognized by the names they have been given in the first script.
 
As an example, and in order for you to reproduce the error, I am attaching 3 files:
  • test_geom.py , which contains the geometry in terms of python commands;
  • test_geom.hdf , which has been manually saved from within the GUI once test_geom.py has run through;
  • test_mesh.py , which is the file I want to get working.
Within test_geom.py, there are two objects, Glue_1 and Face_1, that are referenced in test_mesh.py for the purpose of mesh/submesh creation. But they are not recognized, instead producing an error
 

NameError: name 'Glue_1' is not defined .

 

Needless to say, the objects and their names are still there, fully contained in the hdf-file, as can be seen when the latter is loaded manually into the GUI via File > Open.

 

So what am I doing wrong?

 

Many thanks for your answer.

p, li { white-space: pre-wrap; }
 

Re: Loading existing hdf-files from within a python script

Posted by Malleus at January 30. 2019

Attached is file nr. 2, test_geom.hdf

Attachments

Re: Loading existing hdf-files from within a python script

Posted by Malleus at January 30. 2019

Attached is file nr. 3, test_mesh.py

Attachments

Re: Loading existing hdf-files from within a python script

Posted by Malleus at January 30. 2019

Attached is file nr. 1, test_geom.py

Attachments

Re: Loading existing hdf-files from within a python script

Posted by Christophe Bourcier at January 30. 2019

Hi,

These objects do not exist in python memory. You can get them from the study with:

Glue_1 = salome.myStudy.FindObjectByPath("/Geometry/Glue_1").GetObject()
Face_1 = salome.myStudy.FindObjectByPath("/Geometry/Glue_1/Face_1").GetObject()

See updated test in attachment.

You could also have exported Glue_1 in XAO format at the end of your GEOM script and import it at the begin of your SMESH script.

Christophe

Attachments

Re: Loading existing hdf-files from within a python script

Posted by Saint Michael at January 30. 2019

Hi

This post explains how to get all geom objects of a study to python variables.

https://www.salome-platform.org/forum/forum_10/182599333/510129037

St.Michael

Re: Loading existing hdf-files from within a python script

Posted by Malleus at January 30. 2019

Hello Christophe,

many thanks for your quick reply.

I am sure that your method via FindObjectByPath will work. I have not tried it (yet), since, in the real-world cases I wish to apply the method to, I will have to deal with literally hundreds of geometry objects that must be recognized in the study. So the idea of including the same number of lines into my mesh scripts does not make me happy.

As for your second method, I didn't find a XAO format to export in my Salome - my version is 8.5.0, contained within Salome_meca 2018.0.

How can export into XAO format be done?

Many thanks,

Hanno

 

Previously Christophe Bourcier wrote:

Hi,

These objects do not exist in python memory. You can get them from the study with:

Glue_1 = salome.myStudy.FindObjectByPath("/Geometry/Glue_1").GetObject()
Face_1 = salome.myStudy.FindObjectByPath("/Geometry/Glue_1/Face_1").GetObject()

See updated test in attachment.

You could also have exported Glue_1 in XAO format at the end of your GEOM script and import it at the begin of your SMESH script.

Christophe

 

Re: Loading existing hdf-files from within a python script

Posted by Malleus at January 30. 2019

Hi,

many thanks for your quick reply. I will try it out asap.

Hanno

 

Previously Saint Michael wrote:

Hi

This post explains how to get all geom objects of a study to python variables.

https://www.salome-platform.org/forum/forum_10/182599333/510129037

St.Michael

 

Powered by Ploneboard
Document Actions