How to obtain Surface IDs

How can I obtain surface IDs belonging to a certain volume by specifying Volume ID.
Same with curve IDs. I would prefer to implement with the classic journals;
python scripting is also available.

Coreform 2021.5 Windows 10

Depending on what you want to do with the ids, there are multiple ways to do this in either the Cubit-Python module or in the Cubit Command Language (CCL) which is the language that classic journal files are written in.

CCL isn’t able to store values, so if you’re wanting to do some advanced logic or loop through the ids, you won’t be able to use this programmatically in CCL. But you could use CCL to print the information to the prompt and you could visually / manually grab these values. However, you can have CCL perform operations on these surfaces by extended parsing logic. Let’s do an example:

## Create simple model
reset
bri x 1
bri x 1
move vol 2 x 2

CCL

Let’s try meshing only the surfaces in volume 1:

mesh surface in volume 1

Or let’s try meshing the surfaces that we know to be at the max z-value:

mesh surface with z_coord>0.4999

Or maybe surfaces in volume 1 at the max z-value:

mesh surface in volume 1 with z_coord>0.4999

Python

You can use the parse_from_cubit_list() method to return a tuple of every entity id that would be returned by a CCL list command. For example, the three commands above in Python would be:

cubit.parse_cubit_list("surface", "in volume 1")
# Returns (1, 2, 3, 4, 5, 6)
cubit.parse_cubit_list("surface", "with z_coord>0.4999")
# Returns (1, 7)
cubit.parse_cubit_list("surface", "in volume 1 with z_coord>0.4999")
# Returns (1, )

And you could then do some more advanced operations using various other methods in Cubit-Python:

surf_list = cubit.parse_cubit_list("surface", "in volume 1")
adj_surfs = cubit.get_adjacent_surfaces("surface",surf_list[0])
for sid in surf_list:
  surface = cubit.surface(sid)
  surf_norm = surface.normal_at(surface.center_point())
  if cubit.is_meshed("surface",sid) == False:
    mesh_size = cubit.get_mesh_size("surface", sid)
    cubit.cmd(f"surface {sid} size {mesh_size/2}")
    cubit.cmd(f"mesh surf {sid}")

The above script doesn’t do anything particular, but is meant to demonstrate various different things you can do in Python.

1 Like

Thank you, it was very helpful.