Personal tools
You are here: Home Forum Use Deleting objects from the study using TUI [UnRegister?]

Deleting objects from the study using TUI [UnRegister?]

Up to Use

Deleting objects from the study using TUI [UnRegister?]

Posted by ppeetteerr at March 21. 2012

I am running a loop inside of Salome and would like to free up the memory by destroying the objects before starting the next loop. However, I don't seam to be able to get UnRegister to work. I create the geometry add it to study and then attempt to remove it but it is still there. Any suggetions? Also how do I do this with a mesh?

 

import geompy

Vertex_1 = geompy.MakeVertex(0, 0, 0)

geompy.addToStudy( Vertex_1, 'Vertex_1' )

Vertex_2 = geompy.MakeVertex(0, 2, 0)

geompy.addToStudy( Vertex_2, 'Vertex_2' )

Vertex_1.UnRegister()

 

 

Attachments

Re: Deleting objects from the study using TUI [UnRegister?]

Posted by Saint Michael at March 22. 2012

You can remove a GEOM object this way:

    so = salome.ObjectToSObject(shape)
    sb = salome.myStudy.NewBuilder()
    sb.RemoveObjectWithChildren( so )
    geompy.GEOM._objref_GEOM_Gen.RemoveObject(geompy.geom, shape)

The last command is so complex because in GEOM there are two functions
RemoveObject(), one removes a sub-object from a group, the other
removes an object from the current study. The first function overrides the
latter and is thus unreachable in a normal way, and the last of the 4 commands above reaches that hidden function.

In SMESH:

    meshSO = salome.ObjectToSObject(mesh.GetMesh())
    sb = salome.myStudy.NewBuilder()
    sb.RemoveObjectWithChildren( meshSO )
    mesh.Clear() # just in case
    mesh.mesh.UnRegister()

Re: Deleting objects from the study using TUI [UnRegister?]

Posted by millim at November 15. 2013

Hi,

I am stuck in the same problem:

By using Salome 7.2.0 and importing geompy with:

>import gempy

===============================================================================

WARNING:

Usage of geompy.py is deprecated after SALOME V7.2!

geompy.py will be removed in a future version!

TODO:

The following changes in your scripts are required to avoid this message:

 

replace

-------

 

import geompy

geompy.init_geom(theStudy)

 

with

----

 

from salome.geom import geomBuilder

geompy = geomBuilder.New(salome.myStudy)

 

See also GEOM User's Guide for more details

 

===============================================================================

 

geompy.GEOM._objref_GEOM_Gen.RemoveObject(geompy.geom, shape) works as expected.

 

But: with:

 

>from salome.geom import geomBuilder

>geompy = geomBuilder.New(salome.myStudy)

 


geompy.GEOM._objref_GEOM_Gen.RemoveObject(geompy.geom, shape)

 

Traceback (most recent call last):

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

AttributeError: 'geomBuilder' object has no attribute 'GEOM'

 

 

Looks like that this method does not work in future versions?

Or does it need an other calling?

 

Re: Deleting objects from the study using TUI [UnRegister?]

Posted by millim at November 15. 2013

for the SMESH: when using 

  Mesh_Problem.Clear() # just in case
  Mesh_Problem.mesh.UnRegister()

as the last methods in my sub-def, when calling the next time, the SALOME_container.exe (7.2.0) crashes in Mesh_Problem.Compute()?

see my code below:

# do the mesh
    print "Meshing ....."   
    Mesh_Problem = smesh.Mesh(Problem)
   
    NETGEN_2D3D = Mesh_Problem.Tetrahedron(algo=smeshBuilder.NETGEN_1D2D3D)
    NETGEN_3D_Parameters = NETGEN_2D3D.Parameters()
    NETGEN_3D_Parameters.SetMaxSize( 50.0/mm_unit )
    NETGEN_3D_Parameters.SetMinSize( 0.3/mm_unit) #should be size dependent!!
    NETGEN_3D_Parameters.SetSecondOrder( 0 )
    NETGEN_3D_Parameters.SetOptimize( 1 )
    NETGEN_3D_Parameters.SetFineness( 5 )
    NETGEN_3D_Parameters.SetGrowthRate( 0.7 )
    NETGEN_3D_Parameters.SetNbSegPerEdge( 1 )
    NETGEN_3D_Parameters.SetNbSegPerRadius( 1 )

    Mesh_Problem.Clear()
    isDone = Mesh_Problem.Compute()

    # map geometries
    SolidIDs=[]
    for j in range(len(group_list)):
        SolidIDs.append(Mesh_Problem.GroupOnGeom(group_list[j],group_name[j],SMESH.VOLUME))

    FaceIDs=[]
    for j in range(len(face_list)):
        FaceIDs.append(Mesh_Problem.GroupOnGeom(face_list[j],face_name[j],SMESH.FACE))

    ## set object names
    smesh.SetName(Mesh_Problem.GetMesh(), 'Mesh_Problem')
    smesh.SetName(NETGEN_2D3D.GetAlgorithm(), 'NETGEN_2D3D')
    smesh.SetName(NETGEN_3D_Parameters, 'NETGEN 3D Parameters')
    for j in range(len(group_name)):
        smesh.SetName(SolidIDs[j], group_name[j])
    for j in range(len(face_name)):
        smesh.SetName(FaceIDs[j], face_name[j])
       
    if GUI_mode:
        if salome.sg.hasDesktop():
            salome.sg.updateObjBrowser(1)

    #rescal befor saving
    Mesh_Problem.Scale(Mesh_Problem,SMESH.PointStruct(0,0,0),[mm_scale,mm_scale,mm_scale],False)

    print "exporting to UNV ....."
    mesh_file=os.path.join(tool_dict["model_path"],"mesh_" + str(c_sim) + ".unv")
    Mesh_Problem.ExportUNV(mesh_file)
   
       
    studyObject = salome.myStudy.FindObjectIOR( salome.myStudy.ConvertObjectToIOR( Mesh_Problem.GetMesh() ))
    aStudyBuilder = salome.myStudy.NewBuilder()
    if studyObject: aStudyBuilder.RemoveObjectWithChildren( studyObject )
    #Mesh_Problem.Clear() # just in case
  #Mesh_Problem.mesh.UnRegister()
    return

 

 

Previously Saint Michael wrote:

You can remove a GEOM object this way:

    so = salome.ObjectToSObject(shape)
    sb = salome.myStudy.NewBuilder()
    sb.RemoveObjectWithChildren( so )
    geompy.GEOM._objref_GEOM_Gen.RemoveObject(geompy.geom, shape)

The last command is so complex because in GEOM there are two functions
RemoveObject(), one removes a sub-object from a group, the other
removes an object from the current study. The first function overrides the
latter and the last command reaches the hidden function.

In SMESH:

    meshSO = salome.ObjectToSObject(mesh.GetMesh())
    sb = salome.myStudy.NewBuilder()
    sb.RemoveObjectWithChildren( meshSO )
    mesh.Clear() # just in case
    mesh.mesh.UnRegister()

 

 

Powered by Ploneboard
Document Actions