Get Neighbors of an arbitrary Element

I wrote a python-script, which choose randomly elements of a region and in a second steps their neighbors in this region a determined via a for loop (see python-code below, second for-loop). Unfortunately, for high element-number, this algorithm is extremely slow and inefficient.

Thus my question is:
Is there a way to get the neighbor-elements of an element directly without iterating over the region?

Best regards

    design_domain_faces = cubit.parse_cubit_list('face', 'in volume 2')
    design_domain = [cubit.get_quad_global_element_id(face_id) for face_id in design_domain_faces]
    design_ind = [random.choice(design_domain)]

    for i in range(random.choice(range(1, len(design_domain)))):
        feasible_elements = []
        node_ind = self.get_nodes(random.choice(design_ind))

        for element in set(design_domain).difference(set(design_ind)):
            node_design = self.get_nodes(element)
            if len(node_design.intersection(node_ind)) == 2:

        if len(feasible_elements) != 0:

    design_air = list(set(design_domain).difference(set(design_ind)))

From the command line try

draw face in node in face 1

This draws all the faces neighboring face 1.

From python you would do

face_id = 1
cubit.parse_cubit_list('face', f'in node in face {face_id}')

Hey karl,

exactly what I was looking for.
Thank you very much.

May can I ask you another question:
Is it possible to get the area/volume of an element or the area/volume of a set of elements?

This one was not very obvious. Look in the CubitInterface documentation for get_elem_quality_stats().
Cubit User Documentation (
For example,

cubit.get_elem_quality_stats("face", [74], "Element Area", 0.0, False, 0.0, 0.0, False)

Note that you can give a list of ids. The return is a tuple with much about the list of ids. The first value would be the minimum area of the list of ids. If you are only giving one id, this will be the area you want.

Use Element Volume to get the volume. You can use any of the quality types shown in the GUI.

Once again, thanks for your help.