Personal tools
You are here: Home Forum Use GEOM Python data structure

GEOM Python data structure

Up to Use

GEOM Python data structure

Posted by Roman Fratczak at December 21. 2012

Hello,

 

I've rather general question regarding Python Scripting in Salome TUI. Is somewhere described what is the structure of the objects in Salome ?

For my particular example:

I've imported IGS file - Compound. Then I've exploded it on to 50 solids. Then I've added an additional "Plane01" to my study, and some other solids.

How to get the list of the all object with their names? I've already tested given on the forum solution with:

(...)

geom=salome.myStudy.FindComponent('GEOM')
geom_id=geom.GetID()
i=1
obj=salome.IDToObject(geom_id+':'+str(i))
list_obj=geompy.SubShapeAllSorted(obj,geompy.ShapeType["SOLID"])

(...)

But still- I don't know, how to get to my "Plane01"? That is an separate object, and it is only a 1 Face object?

And the most important, - the "geom_id" gives me "0:1:1" - what does it mean? I other words - how to understand the tree structure with the ID's and the "0:1:1" indicators?

Many thanks for any hint.

Regards

Roman

Re: GEOM Python data structure

Posted by Nigirim at December 21. 2012

Previously Roman Fratczak wrote:

I've imported IGS file - Compound. Then I've exploded it on to 50 solids. Then I've added an additional "Plane01" to my study, and some other solids.

geom=salome.myStudy.FindComponent('GEOM')
geom_id=geom.GetID()
i=1
obj=salome.IDToObject(geom_id+':'+str(i))
list_obj=geompy.SubShapeAllSorted(obj,geompy.ShapeType["SOLID"])

(...)

Hello Roman,

 

You can't find the plane because the command geompy.ShapeType["SOLID"] just searches for solids and nothing else.

To search for faces, edges, wires, shells or vertex you need to change the SOLID into one of these.

I can't test it right now but for a plane it should be FACE but im not sure about that

 

Nigirim

Re: GEOM Python data structure

Posted by William Tougeron at December 21. 2012

Hello Roman and Nigirim :)

I confirm :)

The most common types are: VERTEX, EDGE, FACE and SOLID.

The other are: COMPOUND, COMPSOLID (I don't even know what is a compsolid), SHELL, WIRE, SHAPE (a shape is any kind of geometrical object, so maybe if you look for shapes, you will find your solids and your plane).

You can find this information in the Help -> Geometry module -> User's Guide, then in the Search field, type 'ShapeType'.

In the GUI, you can know what kind of object is a geometrical object thanks to Measures -> What is.

For the rest (the "0:1:1" indicators) I don't know.

William

Re: GEOM Python data structure

Posted by Roman Fratczak at December 21. 2012

Thanks for the reply William and Nigirim !

Yes, I know that the FACE should be an "flat" (not solid) option. My question was rather connected to the organization of the data structure, in order to correctly understand usage of th *GetObject*() functions family. That's why the indicator 0:1:1:1 ...etc.

At the moment I've recognized, that this may be some how like:

study_no : geometry_no :  body_no : sub_object_no ...  ( the '0:1:1:1' designation)

So I can access the objects via:

geom=salome.myStudy.FindComponent('GEOM')

then: geom.GetName() gives me 'Geometry' string. Then the command:

geom_id=geom.GetID()

Gives me an "ID" in a form of string '0:1:1'

Then I can conver ID to object by:

obj=salome.IDToObject(geom_id+':1')

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

So the string ID will be '0:1:1:1'. The command obj.GetName() will return the name of the first object - let's say 'Box_1' etc...

But if I will import an compound, then explode it on to solids, then add some additional bodies (Faces, lines, solids, etc..) how to fast the objects on different "level" in the ID's ?

It is better to get the objects IDs or objects names through salome.myStudy.FindObjectByPath("path") or through the "geompy" (if possible). Especially if I want to make an loop to iterate within my solid_x bodies which in fact I know only the name (as this was import from IGES file - for example).

Many thanks

Regards

Roman

 

 

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

Previously William Tougeron wrote:

Hello Roman and Nigirim :)

I confirm :)

The most common types are: VERTEX, EDGE, FACE and SOLID.

The other are: COMPOUND, COMPSOLID (I don't even know what is a compsolid), SHELL, WIRE, SHAPE (a shape is any kind of geometrical object, so maybe if you look for shapes, you will find your solids and your plane).

You can find this information in the Help -> Geometry module -> User's Guide, then in the Search field, type 'ShapeType'.

In the GUI, you can know what kind of object is a geometrical object thanks to Measures -> What is.

For the rest (the "0:1:1" indicators) I don't know.

William

 

 

Re: GEOM Python data structure

Posted by Saint Michael at December 21. 2012

Hello all

I try to explain.

Here you speak about the structure of Salome Study. First of all, all this stuff may be optional if you deal with TUI interface. For example you can import an IGES file, explode an imported shape into say solids, etc using Python commands w/o calling geompy.addToStudy(geomObj,name). This way you have all geom objects in hands but there is no notion of name of geom object unless it is published in a Salome Study via geompy.addToStudy(go, NAME).

All data published (which is optional as I said) in the Salome Study is represented in a tree-like structure in the Object Browser. The upper level of the tree is occupied by Components: "Geometry", "Mesh", "Post-Pro" etc. Under Components, there are some data relating to a certain Component. All what we see in the Object Browser are Study Objects (== SObject). The SObject have several attributes, among which ID, Name, Icon, and a Data Object it (optionally) holds.

The ID of SObject (also called Entry) is a mean to address it in a tree structure. You can see IDs of every SObject in the Object Browser if you switch on Entry column. Number of digits in the ID says about a tree level the SObject is on. 3 digits correspond to the level of Components, e.g. "0:0:1" is (usually) an ID of the first Component appeared in a Study. 4 digits correspond to the 1st child level under Components, etc.

Salome Study provides different methods to get SObjects: by ID, by Name, by Path etc. The most important method of SObject is GetObject() which returns a Data Object the SObject holds (if any).

Let's consider the python code mentioned above

  geom=salome.myStudy.FindComponent('GEOM')

Here a Study returns an SObject corresponding to "Geometry" Component.

  geom_id=geom.GetID()

SObject returns its ID (or Entry), most probably "0:0:1".

  i=1
  obj=salome.IDToObject(geom_id+':'+str(i))

This command encapsulates following actions:
1) geom_id+':'+str(i) gives "0:0:1:1" - an Entry of the 1st child SObject under "Geometry" Component.
2) an active Study finds an SObject by "0:0:1:1" Entry
3) obj = SObject.GetObject() - a data object (GEOM Object in this case) held by the found SObject is returned

  list_obj=geompy.SubShapeAllSorted(obj,geompy.ShapeType["SOLID"])

geompy explodes the found GEOM Object into a list of solids


St.Michael

Re: GEOM Python data structure

Posted by Roman Fratczak at December 22. 2012

Dear Michael,

Thank you for the very precise explanation. That helps me a lot of and it is clear for me. I've tried to find the info in the documentation, but the only remark I've found in the developer docs - which in fact is little bit too heavy for me at the moment.

In general I see some potential for improvement to be implemented into Salome (with respect to the functionality). Now I can try to define some simple "add-on buttons" to the GUI.

Once more - many thanks for explanation.

Regards

Roman

 

Previously Saint Michael wrote:

Hello all

I try to explain.

Here you speak about the structure of Salome Study. First of all, all this stuff may be optional if you deal with TUI interface. For example you can import an IGES file, explode an imported shape into say solids, etc using Python commands w/o calling geompy.addToStudy(geomObj,name). This way you have all geom objects in hands but there is no notion of name of geom object unless it is published in a Salome Study via geompy.addToStudy(go, NAME).

All data published (which is optional as I said) in the Salome Study is represented in a tree-like structure in the Object Browser. The upper level of the tree is occupied by Components: "Geometry", "Mesh", "Post-Pro" etc. Under Components, there are some data relating to a certain Component. All what we see in the Object Browser are Study Objects (== SObject). The SObject have several attributes, among which ID, Name, Icon, and a Data Object it (optionally) holds.

The ID of SObject (also called Entry) is a mean to address it in a tree structure. You can see IDs of every SObject in the Object Browser if you switch on Entry column. Number of digits in the ID says about a tree level the SObject is on. 3 digits correspond to the level of Components, e.g. "0:0:1" is (usually) an ID of the first Component appeared in a Study. 4 digits correspond to the 1st child level under Components, etc.

Salome Study provides different methods to get SObjects: by ID, by Name, by Path etc. The most important method of SObject is GetObject() which returns a Data Object the SObject holds (if any).

Let's consider the python code mentioned above

  geom=salome.myStudy.FindComponent('GEOM')

Here a Study returns an SObject corresponding to "Geometry" Component.

  geom_id=geom.GetID()

SObject returns its ID (or Entry), most probably "0:0:1".

  i=1
  obj=salome.IDToObject(geom_id+':'+str(i))

This command encapsulates following actions:
1) geom_id+':'+str(i) gives "0:0:1:1" - an Entry of the 1st child SObject under "Geometry" Component.
2) an active Study finds an SObject by "0:0:1:1" Entry
3) obj = SObject.GetObject() - a data object (GEOM Object in this case) held by the found SObject is returned

  list_obj=geompy.SubShapeAllSorted(obj,geompy.ShapeType["SOLID"])

geompy explodes the found GEOM Object into a list of solids


St.Michael

 

Powered by Ploneboard
Document Actions