I am a Python developer using Rhino to do a few spatial analyses. My case here is that I have to find the inside connection between the extrusions and I have written a function to detect it. Surprisingly it works for one input in layer (L1) and doesn’t work for other in layer (S1), I have checked infos the object type and whether corners are snapped properly. Likewise, verified everything whether both layers has similar properties. Both couldn’t able to find why it is working for one and not for other one.
I will the add script and sample .3dm file which i am checking below:
def check_cubevscube_connection(layer_name):
def check_cube_position(cube1_guid, cube2_guid):
# Get the bounding boxes of the cubes
cube1_bounding_box = rs.BoundingBox(cube1_guid)
cube2_bounding_box = rs.BoundingBox(cube2_guid)
if cube1_bounding_box and cube2_bounding_box:
# Create bounding box objects
cube1_bbox = rg.BoundingBox(cube1_bounding_box)
cube2_bbox = rg.BoundingBox(cube2_bounding_box)
# Get the corner points of the bounding boxes
cube1_corners = cube1_bbox.GetCorners()
cube2_corners = cube2_bbox.GetCorners()
# Check if all cube1 corners are inside cube2
cube1_inside_cube2 = all(cube2_bbox.Contains(point) for point in cube1_corners)
if cube1_inside_cube2:
return "inside"
return "Unable to determine"
layer_id = rs.LayerName(layer_name)
if layer_id is None:
return {"Connection": "Layer not found."}
objects = rs.ObjectsByLayer(layer_id)
polysurface_ids = {}
# Find surface and polysurface IDs based on user attribute text
for obj in objects:
# Check if the object has a user attribute text 'ID'
if rs.GetUserText(obj, 'ID'):
# Get the ID value
object_id = rs.GetUserText(obj, 'ID')
# Check if the object is a polysurface using rs.IsObjectSolid()
if rs.ObjectType(obj) == 1073741824:
polysurface_ids[object_id] = obj
if len(polysurface_ids) < 2:
return {"Connection": "Not enough polysurfaces in the layer."}
connection_info = []
for id1, obj1 in polysurface_ids.items():
for id2, obj2 in polysurface_ids.items():
if id1 != id2:
result = check_cube_position(obj1, obj2)
if result == "inside":
connection = {
"Inside ID": id1,
"Connection Type": "inside",
"Outside ID": id2,
"Description": "ID {} is inside ID {}".format(id1, id2)
}
connection_info.append(connection)
if not connection_info:
return {"Connection": "No connection found between polysurfaces."}
return {"Connections": connection_info}
check_cube_connection.3dm (36.9 KB)
check_cube_connection.py (2.9 KB)
I have been blocked here and i couldn’t find anything suspicious here. Could I get some assist to find the issue here?
Thanks in advance!
Regards,
Rajasirpi