def extrude_srf(srf): bb = rs.coerceboundingbox(rs.BoundingBox(srf)) normal = rs.SurfaceNormal(srf, rs.SurfaceClosestPoint(srf, bb.Center)) cmd = "_ExtrudeSrf _SelID %s _Enter Direction %s %s 0.1 _Enter" % (srf, point2str(normal), point2str(bb.Center)) serial = get_serial() rs.Command(cmd) return get_command_objects(serial)
def project_text0(vase): size = Rhino.Geometry.Surface.GetSurfaceSize(rs.coercesurface(vase)) boundary = rs.AddRectangle(rs.WorldXYPlane(), size[1], size[2]) curves = create_text_curves("naama") new_curves = apply_crv(vase, boundary, curves) # rs.DeleteObjects(text_obj) # rs.DeleteObjects(boundary) id = rs.coerceguid(new_curves[2], True) new_srf = split_srf(vase, [id]) strid = new_srf[1].Id.ToString() rs.FlipSurface(new_srf[1].Id, flip=True) bb = rs.coerceboundingbox(rs.BoundingBox(strid)) normal = rs.SurfaceNormal(strid, rs.SurfaceClosestPoint(strid, bb.Center)) cmd = "_ExtrudeSrf _SelID %s _Enter Direction %s %s 0.1 _Enter" % (strid, point2str(normal), point2str(bb.Center)) print cmd rs.Command(cmd) return True
def ColorMesh(MeshID, BlockID): MeshObj = rs.coercemesh(MeshID) MeshObj.EnsurePrivateCopy() Brep = rs.coercegeometry(BlockID) Brep.EnsurePrivateCopy() BB = rs.BoundingBox(BlockID) bb = rs.coerceboundingbox(BB).ToBrep() bb.EnsurePrivateCopy() time1a = time.time() #Start Timer tol = scriptcontext.doc.ModelAbsoluteTolerance Red = rs.coercecolor(System.Drawing.Color.Red) ## Too Low ## Orange = rs.coercecolor(System.Drawing.Color.Orange) Yellow = rs.coercecolor(System.Drawing.Color.Yellow) Green = rs.coercecolor(System.Drawing.Color.Green) ## Within Tol ## LtBlue = rs.coercecolor(System.Drawing.Color.LightBlue) Blue = rs.coercecolor(System.Drawing.Color.Blue) Purple = rs.coercecolor(System.Drawing.Color.Purple) ## Too High ## White = rs.coercecolor(System.Drawing.Color.White) Colors = [Purple, Blue, LtBlue, Green, Yellow, Orange, Red] ## \/ Set Tolerances Here \/ ## Range = [1 / 32, 1 / 16, 1 / 8] Build_Key(BB[5], Colors, Range) Rhino.RhinoApp.Wait() ColorList = range(MeshObj.Vertices.Count) def CalculateColor(i): Vertex = MeshObj.Vertices[i] Point = rs.coerce3dpoint(Vertex) if bb.IsPointInside(Point, tol, True) == False: Color = White else: CP = Brep.ClosestPoint(Point) Distance = Point.DistanceTo(CP) Color = None if Distance < Range[0]: Color = Colors[3] # Green # elif Distance < Range[1]: if Brep.IsPointInside(Point, tol, True) == True: Color = Colors[4] #Too Low else: Color = Colors[2] #Too High elif Distance < Range[2]: if Brep.IsPointInside(Point, tol, True) == True: Color = Colors[5] #Too Low else: Color = Colors[1] #Too High # Outside Range # else: if Brep.IsPointInside(Point, tol, True) == True: Color = Colors[6] #Too Low else: Color = Colors[0] #Too High ColorList[i] = Color print MeshObj.Vertices.Count ghpythonlib.parallel.run(CalculateColor, range(MeshObj.Vertices.Count)) for Color in ColorList: MeshObj.VertexColors.Add(Color) scriptcontext.doc.Objects.Replace(MeshID, MeshObj) scriptcontext.doc.Views.Redraw() ## Add Scale ## time1b = time.time() #End Timer print round(time1b - time1a, 3)