import rhinoscriptsyntax as rs
import Rhino
def clashtest():
mesh_ids1 = rs.GetObjects("First set of meshes", rs.filter.mesh)
if not mesh_ids1: return
mesh_ids2 = rs.GetObjects("Second set of meshes", rs.filter.mesh)
if not mesh_ids2: return
# convert the Guids into actual RhinoCommon mesh objects
meshes1 = [rs.coercemesh(m) for m in mesh_ids1]
meshes2 = [rs.coercemesh(m) for m in mesh_ids2]
distance = rs.GetReal("Distance to consider a clash", 0, 0)
if distance is None: return
clashes = Rhino.Geometry.Intersect.MeshClash.Search(meshes1, meshes2, distance, 0)
if not clashes:
print "no clashes"
else:
print len(clashes), "clashes detected"
for clash in clashes:
point = clash.ClashPoint
rs.AddPoint(point)
# How to assign the ID of MeshB as user text/dictionary to MeshA ??????
for i, mesh in enumerate(meshes2):
if clash.MeshB == mesh:
s = clash.MeshA.GetUserString("clash")
if len(s)>0: s = s + ", "
s = s + str(mesh_ids2[i])
clash.MeshA.SetUserString("clash", s)
break
if __name__=="__main__":
clashtest()