Rename the group name in python

I was trying to rename the group using set_entity_name(“group”, 3, “watever2”) in python script instead of cubit command. But it seemed to work on other entity types than groups. I did see though the new names were added to the group name as an alias, if I “list group 3” as shown below. Is there a way in python script to change the group name instead of using cubit commands?
thanks.

Wei

CUBIT> list group 3
Group Entity ‘watever’, ‘watever2’ (Id = 3)
It owns/encloses 1 entity: 1 volume.

Owned Entities:                     Mesh Scheme   Interval:      Edge
______Name______  Type________Id     +is meshed   Count     Size Length
        Volume 5  Volume       5           map-     1 S  77.9429 

Journaled Command: list group 3

The general philosophy of CubitInterface is that it is read only. The only way to change state via the interface should be vis cubit.cmd() or cubit.silient_cmd(). Unfortunately, set_entity_name() creeped in for a use case in the GUI where the command line did not behave as needed.

The right way to set the group name would be as follows.

old_name = "MyGroup"
new_name = "YourGroup"
cubit.cmd( f"group {old_name} rename '{new_name}' ")

Thanks. I am fine with using cubit.cmd but ideally it would be better if everything is dealt through the python interface if writing a python script.

You can write your own wrapper around existing API to simplify most frequent actions.

1 Like