Skip to content

Instantly share code, notes, and snippets.

@mkassner
Created November 6, 2015 13:16
Show Gist options
  • Save mkassner/2107564c32950ed0f04c to your computer and use it in GitHub Desktop.
Save mkassner/2107564c32950ed0f04c to your computer and use it in GitHub Desktop.
Rhino Mesh intersection checks
# imports need to be cleaned up
import rhinoscript.userinterface
from rhinoscript import geometry
import rhinoscriptsyntax as rs
import System,Rhino
from time import sleep
import os
from Rhino.DocObjects import *
import scriptcontext
from System import *
from Rhino import *
from Rhino.DocObjects import *
from Rhino.Geometry import *
from Rhino.Input import *
from Rhino.Input.Custom import *
from Rhino.Commands import *
from scriptcontext import doc
def CheckMinDist(min_dist):
result,objects = Rhino.Input.RhinoGet.GetMultipleObjects('Get objects to check',False,ObjectType.Mesh)
meshes = [m.Geometry() for m in objects]
meshes = [ m for m in meshes if type(m) is Mesh]
meshes = [ Rhino.Geometry.Mesh.Offset(m,-min_dist/2.0) for m in meshes if type(m) is Mesh]
intersection_lines = []
while meshes:
mesh = meshes.pop(0)
for other in meshes:
intersections = Rhino.Geometry.Intersect.Intersection.MeshMeshAccurate(mesh,other,0.001)
for i in intersections or []:
scriptcontext.doc.Objects.AddPolyline(i)
sphere = Rhino.Geometry.Sphere(i[0],5)
scriptcontext.doc.Objects.AddSphere(sphere)
intersection_lines.append(i)
scriptcontext.doc.Views.Redraw()
if intersection_lines:
print 'found %s intersections:'%len( intersection_lines)
else:
print 'No intersections'
return 0
CheckMinDist(0.39)
def Get_Empty(min_dist):
result,objects = Rhino.Input.RhinoGet.GetMultipleObjects('Get objects to check',False,ObjectType.Mesh)
result,box = Rhino.Input.RhinoGet.GetOneObject('Get box',False,ObjectType.Mesh)
# box = rs.GetObject('get box')
box = box.Geometry()
meshes = [m.Geometry() for m in objects]
meshes = [ m for m in meshes if type(m) is Mesh]
meshes = [ Rhino.Geometry.Mesh.Offset(m,-min_dist) for m in meshes if type(m) is Mesh]
max_x,max_y,max_z = 180,220,100
for z in range(0,max_z,10):
for y in range(0,max_y,10):
for x in range(0,max_x,10):
box.Transform(Transform.Translation(x,y,z))
ok = True
for r in meshes:
if Rhino.Geometry.Intersect.Intersection.MeshMeshAccurate(box,r,0.001):
ok = False
break
if not ok:
scriptcontext.doc.Objects.AddMesh(box)
box.Transform(Transform.Translation(-x,-y,-z))
scriptcontext.doc.Views.Redraw()
return 0
#Get_Empty(0.4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment