Impossible to "really" delete geometrical groups in the GUI when created from script
Impossible to "really" delete geometrical groups in the GUI when created from scriptPosted by William Tougeron at November 02. 2012
Since I am on the forum, I would like to speak of a problem I have which is very specific but important for my work.
It is about group creation and deletion in the Geometry module. Actually, when I create a geometrical group on an object from the GUI and if I delete this group always from the GUI, it really disappears. I mean: if I demand to display the groups of this objects in a Python script, the group is not here anymore.
But if I create a group in a script with the method I saw in the documentation:
- geompy.CreateGroup() # Create the group
- geompy.AddObject() # Add IDs to the group
- geompy.addToStudyInFather() # Add the group to the study tree
And then if I delete the group in the GUI, it disappears from the study tree... but still exists "somewhere" so that if I try to find it in a Python script I will!
This is a problem because I want to develop user-friendly Python functions to be use in the Python console of Salome and dealing with groups... But if a user deletes a group created with one of my functions, then creates another group with the same name and try to use a function on it by giving its name, the function will find the old one being deleted and not the new one...
If someone has an idea...
Enclosed is a Python script to use on a geometrical object called "Box_1". Just create this "Box_1", then create some groups on it in the GUI. Then you can launch the script. It will add a new group with a random name, then will display the groups found in the box. You can launch it, then try to delete some handmade groups and launch it again. You will see that the deleted groups won't appear in the found group list. But if you delete "python-created" groups, you will see that they will always be found by the script during the following launches.
This problem occurs with my 5.1.5 and 6.5.0 versions of Salome.
Re: Impossible to "really" delete geometrical groups in the GUI when created from scriptPosted by Christophe Bourcier at November 05. 2012
You can use deleteShape from GeomStudyTools to completly delete a shape.
See the attached script, and the documentation http://docs.salome-platform.org/salome_6_5_0/tui/GEOM/docutils/docapi.html#salome.geom.geomtools.GeomStudyTools.deleteShape
Re: Impossible to "really" delete geometrical groups in the GUI when created from scriptPosted by William Tougeron at May 29. 2013
My question was actually: "How to create groups in a script which can after be deleted completely using simply the [Delete] key from the GUI (like those which are created directly from the GUI)?"
But I used your solution for another purpose (I needed to delete a group existing in the GUI from a script), so thank you very much
I only had to add try/except lines to avoid an error during the deletion:
import geompy, salome
from salome.geom.geomtools import GeomStudyTools
gst = GeomStudyTools()
group = salome.myStudy.FindObject('Group_1').GetObject()
entry = salome.ObjectToID(group)
Else, the following error appears in the Python console:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/tougeron/myScript.py", line 11, in <module>
File "/opt/salome/6.6.0/appli_V6_6_0/lib/python2.6/site-packages/salome/salome/geom/geomtools.py", line 241, in deleteShape
File "/opt/salome/6.6.0/appli_V6_6_0/lib/python2.6/site-packages/salome/SALOME_GenericObj_idl.py", line 66, in Destroy
return _omnipy.invoke(self, "Destroy", _0_SALOME.GenericObj._d_Destroy, args)
omniORB.CORBA.OBJECT_NOT_EXIST: CORBA.OBJECT_NOT_EXIST(omniORB.OBJECT_NOT_EXIST_NoMatch, CORBA.COMPLETED_NO)
Thank you very much