Continuing on this example, below is a script that will find all the nodes that fall inside an interior, unmeshed volume within a larger, encompassing external volume and group the nodes as a Node Set. Similarly, the script will group all elements that fall inside or intersect with the internal volume into a Block.
[code]#!python
cubit.cmd(“reset”)
cubit.cmd(“bri x 10”)
cubit.cmd(“bri x 5”)
cubit.cmd(“volume 1 scheme Tetmesh”)
cubit.cmd(“volume 1 size auto factor 5”)
cubit.cmd(“mesh vol 1”) # Note that only the volume 1 is meshed, not volume 2
for tet_id in vol1_elements:
interior_tet = False
tet_nodes = cubit.parse_cubit_list(“node”, "in tet "+str(tet_id))
Loop over the four nodes of the tet
for node_id in tet_nodes:
node_coord = cubit.get_nodal_coordinates(node_id)
result = int_body.point_containment(node_coord)
# 1: inside; 2: on the boudary
if result == 1 or result == 2:
interior_tet = True
if node_id not in nodes_in_body:
nodes_in_body.append(node_id)
if interior_tet:
elements_in_body.append(tet_id)
print “Nodes in Internal Body: {}”.format(nodes_in_body)
print “Elements in Internal Body: {}”.format(elements_in_body)
cubit.cmd("nodeset 1 add node " + " ".join(str(e) for e in nodes_in_body))
cubit.cmd("block 1 add tet " + " ".join(str(e) for e in elements_in_body))
[/code]