def draw_mesh(self, compas_mesh, color=None): mesh = Rhino.Geometry.Mesh() # TODO: check mesh_draw from rhino vertices = compas_mesh.get_vertices_attributes('xyz') faces = [ compas_mesh.face_vertices(fkey) for fkey in compas_mesh.faces() ] for v in vertices: mesh.Vertices.Add(*v) for f in faces: mesh.Faces.AddFace(*f) mesh.Normals.ComputeNormals() mesh.Compact() if color: color = rgb_to_rgb(color[0], color[1], color[2]) count = len(vertices) colors = CreateInstance(Color, count) for i in range(count): colors[i] = rs.coercecolor(color) mesh.VertexColors.SetColors(colors) return mesh
def draw_mesh(vertices, faces, color=None, vertex_normals=None, texture_coordinates=None): """Draw mesh in Grasshopper. """ mesh = Mesh() for a, b, c in vertices: mesh.Vertices.Add(a, b, c) for face in faces: if len(face) < 4: mesh.Faces.AddFace(face[0], face[1], face[2]) else: mesh.Faces.AddFace(face[0], face[1], face[2], face[3]) if vertex_normals: count = len(vertex_normals) normals = CreateInstance(Vector3f, count) for i, normal in enumerate(vertex_normals): normals[i] = Vector3f(normal[0], normal[1], normal[2]) mesh.Normals.SetNormals(normals) if texture_coordinates: count = len(texture_coordinates) tcs = CreateInstance(Point2f, count) for i, tc in enumerate(texture_coordinates): tcs[i] = Point2f(tc[0], tc[1]) mesh.TextureCoordinates.SetTextureCoordinates(tcs) if color: count = len(vertices) colors = CreateInstance(Color, count) for i in range(count): colors[i] = rs.coercecolor(color) mesh.VertexColors.SetColors(colors) return mesh
def draw_mesh(vertices, faces, color=None, vertex_normals=None, texture_coordinates=None): """Draw mesh in Grasshopper. Parameters ---------- vertices : list of point List of vertex locations. faces : list of list of int List of faces defined as lists of indices into the list of vertices. Other Parameters ---------------- color : tuple, list or :class:`System.Drawing.Color`, optional vertex_normals : bool, optional texture_coordinates Returns ------- list of :class:`Rhino.Geometry.Mesh` """ mesh = Mesh() for a, b, c in vertices: mesh.Vertices.Add(a, b, c) for face in faces: if len(face) < 4: mesh.Faces.AddFace(face[0], face[1], face[2]) else: mesh.Faces.AddFace(face[0], face[1], face[2], face[3]) if vertex_normals: count = len(vertex_normals) normals = CreateInstance(Vector3f, count) for i, normal in enumerate(vertex_normals): normals[i] = Vector3f(normal[0], normal[1], normal[2]) mesh.Normals.SetNormals(normals) if texture_coordinates: count = len(texture_coordinates) tcs = CreateInstance(Point2f, count) for i, tc in enumerate(texture_coordinates): tcs[i] = Point2f(tc[0], tc[1]) mesh.TextureCoordinates.SetTextureCoordinates(tcs) if color: count = len(vertices) colors = CreateInstance(Color, count) for i in range(count): colors[i] = rs.coercecolor(color) mesh.VertexColors.SetColors(colors) return mesh
def changeColors(childLayers): print(childLayers) for childLayer in childLayers: for name, color in colorDict.items(): color = rs.coercecolor(color) if re.search('HATCH-' + name + '$', childLayer): print(childLayer) rs.LayerPrintColor(childLayer, color) rs.LayerColor(childLayer, color) layer_c = rs.LayerColor(childLayer) layer_m = rs.LayerMaterialIndex(childLayer) if layer_m == -1: layer_m = rs.AddMaterialToLayer(childLayer) rs.MaterialColor(layer_m, layer_c)
def main(): # Configure options and place in a dictionary. # Set the key as a string, this will be used as the option Name. # Note that the option Name can not contain any space options = {} options["Toggle"] = Rhino.Input.Custom.OptionToggle(True, "No", "Yes") options["Float"] = Rhino.Input.Custom.OptionDouble(0.01) options["Integer"] = Rhino.Input.Custom.OptionInteger(5) options["Color"] = Rhino.Input.Custom.OptionColor(rs.coercecolor((255,0,0), False)) options["Operation"] = Hello options["String"] = None options["String2"] = "Proper String Value" options["List"] = ["A","B","C"] object_ids = armacode.GetObjectsWithOptions(custom_options=options) print "Selected GUIDs : {}".format(object_ids) if object_ids: for name in options: print "{} : {}".format(name, options[name])
def xdraw_mesh(vertices, faces, vertex_normals=None, texture_coordinates=None, vertex_colors=None): """Draw mesh. """ # TODO: This should move to compas/compas_grasshoper/utilities/drawing.py. # TODO: This function is mainly a copy of rhinoscriptsyntax.AddMesh, just without scriptcontext adding. mesh = Mesh() for a, b, c in vertices: mesh.Vertices.Add(a, b, c) for face in faces: if len(face) < 4: mesh.Faces.AddFace(face[0], face[1], face[2]) else: mesh.Faces.AddFace(face[0], face[1], face[2], face[3]) if vertex_normals: count = len(vertex_normals) normals = CreateInstance(Vector3f, count) for i, normal in enumerate(vertex_normals): normals[i] = Vector3f(normal[0], normal[1], normal[2]) mesh.Normals.SetNormals(normals) if texture_coordinates: count = len(texture_coordinates) tcs = CreateInstance(Point2f, count) for i, tc in enumerate(texture_coordinates): tcs[i] = Point2f(tc[0], tc[1]) mesh.TextureCoordinates.SetTextureCoordinates(tcs) if vertex_colors: for i, color in vertex_colors.iteritems(): color = rs.coercecolor(color) mesh.VertexColors.SetColor(i, color) return mesh
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)
"LayerPrintColor" : line_data[2]} if line_data[0] == "RESIDENTIAL": line_data[0] = "RES" layerDict[prefix+line_data[0]+"_LOBBY"] = {"LayerColor" : line_data[1], "LayerPrintColor" : line_data[1]} layerDict[prefix+line_data[0]+"_BOH"] = {"LayerColor" : line_data[3], "LayerPrintColor" : line_data[3]} else: layerDict[prefix+line_data[0]] = {"LayerColor" : line_data[1], "LayerPrintColor" : line_data[1]} rs.EnableRedraw(False) layers = cleanLayerList(rs.LayerNames()) # #print(layers) #print(layerDict) for layer in layers: for key, val in layerDict.items(): if layer+"::"+key in rs.LayerChildren(layer): rs.LayerColor(layer+"::"+key, rs.coercecolor(ToList(val["LayerColor"]))) rs.LayerPrintColor(layer+"::"+key, rs.coercecolor(ToList(val["LayerPrintColor"]))) rs.EnableRedraw(True)
layerDict["A-HATCH-HOTEL"] = {"LayerColor" : (214, 232, 168), "LayerPrintColor" : (214, 232, 168), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} layerDict["A-HATCH-HOTEL_BOH"] = {"LayerColor" : (209, 222, 178), "LayerPrintColor" : (209, 222, 178), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} layerDict["A-HATCH-OFFICE_LOBBY"] = {"LayerColor" : (251, 235, 229), "LayerPrintColor" : (251, 235, 229), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} layerDict["A-HATCH-OFFICE"] = {"LayerColor" : (241, 211, 199), "LayerPrintColor" : (241, 211, 199), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} layerDict["A-HATCH-OFFICE_BOH"] = {"LayerColor" : (222, 191, 178), "LayerPrintColor" : (222, 191, 178), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} currentLayer = rs.CurrentLayer() for entry in layerDict: cLayerName = currentLayer + "::" + entry if cLayerName not in rs.LayerNames(): rs.AddLayer(entry, rs.coercecolor(layerDict[entry]['LayerColor']), parent=currentLayer) elif rs.LayerLinetype(cLayerName) is not (layerDict[entry]['LayerLinetype']): rs.LayerLinetype(cLayerName, layerDict[entry]['LayerLinetype']) rs.LayerColor(cLayerName, rs.coercecolor(layerDict[entry]['LayerColor'])) rs.LayerLinetype(cLayerName, layerDict[entry]['LayerLinetype']) rs.LayerPrintWidth(cLayerName, layerDict[entry]['LayerPrintWidth']) rs.LayerPrintColor(cLayerName, rs.coercecolor(layerDict[entry]['LayerPrintColor'])) if re.search("-HATCH-", cLayerName): layer_c = rs.coercecolor(rs.LayerColor(cLayerName)) layer_m = rs.LayerMaterialIndex(cLayerName) if layer_m == -1: layer_m = rs.AddMaterialToLayer(cLayerName) rs.MaterialColor(layer_m, layer_c) rs.LayerPrintColor(cLayerName, layer_c)
def draw_mesh(vertices, faces, color=None, vertex_normals=None, texture_coordinates=None): """Draw mesh in Grasshopper. Parameters ---------- vertices : list of point List of vertex locations. faces : list of list of int List of faces defined as lists of indices into the list of vertices. Other Parameters ---------------- color : tuple, list or :class:`System.Drawing.Color`, optional vertex_normals : bool, optional texture_coordinates Returns ------- list of :class:`Rhino.Geometry.Mesh` """ mesh = Mesh() for a, b, c in vertices: mesh.Vertices.Add(a, b, c) for face in faces: f = len(face) if f < 3: continue if f == 3: mesh.Faces.AddFace(*face) elif f == 4: mesh.Faces.AddFace(*face) else: if MeshNgon: centroid = centroid_points([vertices[index] for index in face]) c = mesh.Vertices.Add(*centroid) facets = [] for i, j in pairwise(face + face[:1]): facets.append(mesh.Faces.AddFace(i, j, c)) ngon = MeshNgon.Create(face, facets) mesh.Ngons.AddNgon(ngon) if vertex_normals: count = len(vertex_normals) normals = CreateInstance(Vector3f, count) for i, normal in enumerate(vertex_normals): normals[i] = Vector3f(normal[0], normal[1], normal[2]) mesh.Normals.SetNormals(normals) if texture_coordinates: count = len(texture_coordinates) tcs = CreateInstance(Point2f, count) for i, tc in enumerate(texture_coordinates): tcs[i] = Point2f(tc[0], tc[1]) mesh.TextureCoordinates.SetTextureCoordinates(tcs) if color: count = len(mesh.Vertices) colors = CreateInstance(Color, count) for i in range(count): colors[i] = rs.coercecolor(color) mesh.VertexColors.SetColors(colors) return mesh
layerDict["A-HATCH-OFFICE_BOH"] = { "LayerColor": (222, 191, 178), "LayerPrintColor": (222, 191, 178), "LayerLinetype": "Continuous", "LayerPrintWidth": 0.0 } currentLayer = rs.CurrentLayer() for entry in layerDict: cLayerName = currentLayer + "::" + entry if cLayerName not in rs.LayerNames(): rs.AddLayer(entry, rs.coercecolor(layerDict[entry]['LayerColor']), parent=currentLayer) elif rs.LayerLinetype(cLayerName) is not ( layerDict[entry]['LayerLinetype']): rs.LayerLinetype(cLayerName, layerDict[entry]['LayerLinetype']) rs.LayerColor(cLayerName, rs.coercecolor(layerDict[entry]['LayerColor'])) rs.LayerLinetype(cLayerName, layerDict[entry]['LayerLinetype']) rs.LayerPrintWidth(cLayerName, layerDict[entry]['LayerPrintWidth']) rs.LayerPrintColor(cLayerName, rs.coercecolor(layerDict[entry]['LayerPrintColor'])) if re.search("-HATCH-", cLayerName): layer_c = rs.coercecolor(rs.LayerColor(cLayerName)) layer_m = rs.LayerMaterialIndex(cLayerName) if layer_m == -1:
#layerDict["A-HATCH-HOTEL"] = {"LayerColor" : (214, 232, 168), "LayerPrintColor" : (214, 232, 168), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} #layerDict["A-HATCH-HOTEL_BOH"] = {"LayerColor" : (209, 222, 178), "LayerPrintColor" : (209, 222, 178), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} #layerDict["A-HATCH-OFFICE_LOBBY"] = {"LayerColor" : (251, 235, 229), "LayerPrintColor" : (251, 235, 229), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} #layerDict["A-HATCH-OFFICE"] = {"LayerColor" : (241, 211, 199), "LayerPrintColor" : (241, 211, 199), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} #layerDict["A-HATCH-OFFICE_BOH"] = {"LayerColor" : (222, 191, 178), "LayerPrintColor" : (222, 191, 178), "LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.0} # currentLayer = rs.CurrentLayer() for entry in layerDict: cLayerName = currentLayer + "::" + entry if cLayerName not in rs.LayerNames(): rs.AddLayer(entry, rs.coercecolor(layerDict[entry]['LayerColor']), parent=currentLayer) elif rs.LayerLinetype(cLayerName) is not (layerDict[entry]['LayerLinetype']): rs.LayerLinetype(cLayerName, layerDict[entry]['LayerLinetype']) rs.LayerColor(cLayerName, rs.coercecolor(layerDict[entry]['LayerColor'])) rs.LayerLinetype(cLayerName, layerDict[entry]['LayerLinetype']) rs.LayerPrintWidth(cLayerName, layerDict[entry]['LayerPrintWidth']) rs.LayerPrintColor(cLayerName, rs.coercecolor(layerDict[entry]['LayerPrintColor'])) if re.search("-HATCH-", cLayerName): layer_c = rs.coercecolor(rs.LayerColor(cLayerName)) layer_m = rs.LayerMaterialIndex(cLayerName) if layer_m == -1: layer_m = rs.AddMaterialToLayer(cLayerName) rs.MaterialColor(layer_m, layer_c) rs.LayerPrintColor(cLayerName, layer_c)
"LayerPrintColor": line_data[1] } layerDict[prefix + line_data[0] + "_BOH"] = { "LayerColor": line_data[3], "LayerPrintColor": line_data[3] } else: layerDict[prefix + line_data[0]] = { "LayerColor": line_data[1], "LayerPrintColor": line_data[1] } rs.EnableRedraw(False) layers = cleanLayerList(rs.LayerNames()) # #print(layers) #print(layerDict) for layer in layers: for key, val in layerDict.items(): if layer + "::" + key in rs.LayerChildren(layer): rs.LayerColor(layer + "::" + key, rs.coercecolor(ToList(val["LayerColor"]))) rs.LayerPrintColor(layer + "::" + key, rs.coercecolor(ToList(val["LayerPrintColor"]))) rs.EnableRedraw(True)