def SampleSynchronizeRenderColors(): objects = rs.AllObjects() if objects is None: return for obj in objects: color = rs.ObjectColor(obj) source = rs.ObjectColorSource(obj) material = -1 if source == 0: layer = rs.ObjectLayer(obj) material = rs.LayerMaterialIndex(layer) if material < 0: material = rs.AddMaterialToLayer(layer) elif source == 1: material = rs.ObjectMaterialIndex(obj) if material < 0: material = rs.AddMaterialToObject(obj) if material >= 0: if color != rs.MaterialColor(material): rs.MaterialColor(material, color) rs.Redraw()
def ColorAndMove(object, layer): index = rs.AddMaterialToObject(object) if layer == 1: rs.MaterialColor(index, (255, 0, 0)) if layer == 16: rs.MaterialColor(index, (0, 0, 255)) rs.MoveObject(object, (0, 0, -boardThickness - 0.1))
def PlaceCircle(x, y, radius, layer): if (layer != 1) and (layer != 16): return None object = rs.AddCylinder((x, y, 0), 0.1, radius) index = rs.AddMaterialToObject(object) if layer == 1: rs.MaterialColor(index, (255, 0, 0)) if layer == 16: rs.MaterialColor(index, (0, 0, 255)) rs.MoveObject(object, (0, 0, -boardThickness - 0.1)) return object
def draw(pipe, index): materialIndex = rs.AddMaterialToObject(pipe) rs.MaterialColor( materialIndex, (random.uniform(0, 255), random.uniform(0, 255), 150 + index * 5)) rs.MaterialShine(materialIndex, index * 0.1) rs.MaterialTransparency(materialIndex, random.uniform(0, 0.15 * index))
def NewSphere(center, radius): newsphere = rs.AddSphere(center, radius) newsphere = rs.RebuildSurface(newsphere, pointcount=(6, 6)) rs.n materialIndex = rs.AddMaterialToObject(newsphere) rs.MaterialColor(materialIndex, (random.uniform( 0, 50), random.uniform(0, 50), random.uniform(50, 255)))
def unifyColor(layer): layer_c = rs.LayerColor(layer) layer_m = rs.LayerMaterialIndex(layer) if layer_m == -1: layer_m = rs.AddMaterialToLayer(layer) rs.MaterialColor(layer_m, layer_c) rs.LayerPrintColor(layer, layer_c)
def draw(center, maxrad, minrad, index): torus = rs.AddTorus(center, maxrad, minrad) materialIndex = rs.AddMaterialToObject(torus) rs.MaterialColor( materialIndex, (random.uniform(0, 255), random.uniform(0, 255), 150 + index * 5)) # rs.MaterialShine(materialIndex,index*5 ) rs.MaterialTransparency(materialIndex, random.uniform(0, 0.1 * index))
def PlacePCB(curves): curves = rs.JoinCurves(curves, True) surface = rs.AddPlanarSrf(curves) other = rs.CopyObject(surface, (0, 0, -boardThickness)) surfaces = [surface, other] for curve in curves: surfaces.append( rs.ExtrudeCurveStraight(curve, (0, 0, 0), (0, 0, -boardThickness))) rs.DeleteObjects(curves) surface = rs.JoinSurfaces(surfaces, True) index = rs.AddMaterialToObject(surface) rs.MaterialColor(index, (20, 150, 20)) return surface
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 SplitRecursive(surface, splitValue, direction, generation, index): if generation > 0: domain_u = rs.SurfaceDomain(surface, direction) domainRange = domain_u[1] - domain_u[0] split = domainRange * splitValue + domain_u[0] surface1 = rs.TrimSurface(surface, direction, (split, domain_u[1])) surface2 = rs.TrimSurface(surface, direction, (domain_u[0], split)) rs.DeleteObject(surface) SplitRecursive(surface1, random.uniform(0.4, 0.6), 0, generation - 1, index) SplitRecursive(surface2, random.uniform(0.4, 0.6), 1, generation - 1, index) else: materialIndex = rs.AddMaterialToObject(surface) rs.MaterialColor( materialIndex, (random.uniform(0, 255), random.uniform(0, 255), 150 + index * 5)) rs.MaterialShine(materialIndex, index * 0.1) rs.MaterialTransparency(materialIndex, random.uniform(0, 0.15 * index))
def add_cube_w_material(count): for i in xrange(count): for j in xrange(count): ### define pt, plane tmp_pt = rs.AddPoint(i * 2, j * 2, 0) tmp_pln = rs.PlaneFromPoints(tmp_pt, rs.PointAdd(tmp_pt, (1,0,0)), rs.PointAdd(tmp_pt, (0,1,0))) ### define extrude line line_ex = rs.AddLine((0,0,0), (0,0,1)) ### draw rect tmp_crv = rs.AddRectangle(tmp_pln, 1,1) tmp_surf = rs.AddPlanarSrf(tmp_crv) tmp_box = rs.ExtrudeSurface(tmp_surf, line_ex, True) ### set color rs.AddMaterialToObject(tmp_box) index = rs.ObjectMaterialIndex(tmp_box) rs.MaterialName(index, str(i) + "_" +str(j)) rs.MaterialColor(index, ((255 / count) * i, 255 - ((255 / count) * j), 255 - ((255 / count) * j))) # name = rs.MaterialName(index) # print name ### delete rs.DeleteObject(tmp_pt) rs.DeleteObject(tmp_crv) rs.DeleteObject(tmp_surf) rs.DeleteObject(line_ex)
import rhinoscriptsyntax as rs layer = rs.CurrentLayer() layer_c = rs.LayerColor(layer) layer_m = rs.LayerMaterialIndex(layer) if layer_m == -1: layer_m = rs.AddMaterialToLayer(layer) rs.MaterialColor(layer_m, layer_c) rs.LayerPrintColor(layer, layer_c)
import rhinoscriptsyntax as rs sourceObjects = rs.GetObjects(message="Select Objects to use color", preselect=True, select=False) for obj in sourceObjects: obj_color = rs.ObjectColor(obj) obj_mat = rs.ObjectMaterialIndex(obj) if obj_mat == -1: obj_mat = rs.AddMaterialToObject(obj) rs.MaterialColor(obj_mat, obj_color) rs.ObjectPrintColor(obj, color=rs.ObjectColor(obj))
import rhinoscriptsyntax as rs from System.Drawing import Color import random #assign different materials to layers and change layer colors to correspond with it for export to lumion def randomcolor(): red = int(255*random.random()) green = int(255*random.random()) blue = int(255*random.random()) return Color.FromArgb(red,green,blue) count = rs.LayerCount() layerNames = rs.LayerNames() print(layerNames) print "There are", count, "layers." for i in range(count): rc = randomcolor() rs.LayerColor(layerNames[i], rc) rs.MaterialColor(i,rc) rs.MaterialName( i, str(i)) rs.AddMaterialToLayer(layerNames[i])
point_list = sweep_2D_data(point_list) norm_list = sweep_2D_data(norm_list) """ print( len(string_data), len(string_data[0]) ) print( len(point_list), len(point_list[0]) ) print( len(norm_list), len(norm_list[0]) ) """ for i, team in enumerate(string_data): new_color = random_color() new_layer = rs.AddLayer(name = team[0], color = new_color) mat = rs.AddMaterialToLayer(new_layer) # test = rs.LayerMaterialIndex("base_surf") # rs.MatchMaterial(rs.ObjectMaterialIndex(new_layer), rs.ObjectMaterialIndex(mat) ) rs.MaterialColor(mat, new_color) rs.MaterialShine(mat, 255 * 0.03) for j, value in enumerate(team): if(j == 0): # print("ok") name_dot = rs.AddTextDot(value, point_list[i][j]) rs.ObjectLayer(name_dot, new_layer) else: # convert to string to float value = float(value) if(value > 0): value = value * factor # select vector vec_coord = norm_list[i][j]
def AssignMaterial(object_id, Material): # Adds simple, pre-defined material surface property sets to objects. Note that # these are simply visual properties, they do not make the model suitable for # centre of gravity, etc. calculations. MatInd = rs.AddMaterialToObject(object_id) if Material == "White_composite_external": rs.MaterialColor(MatInd, (255, 255, 255)) rs.MaterialShine(MatInd, 100) rs.MaterialTransparency(MatInd, 0) rs.MaterialReflectiveColor(MatInd, (255, 255, 255)) elif Material == "Plexiglass": rs.MaterialColor(MatInd, (255, 255, 255)) rs.MaterialShine(MatInd, 255) rs.MaterialTransparency(MatInd, 0.8) elif Material == "Skin": rs.MaterialColor(MatInd, (229, 184, 143)) rs.MaterialShine(MatInd, 0) rs.MaterialTransparency(MatInd, 0) elif Material == "Panel": rs.MaterialColor(MatInd, (0, 0, 0)) rs.MaterialShine(MatInd, 0) rs.MaterialTransparency(MatInd, 0) elif Material == "PropDisk": rs.MaterialColor(MatInd, (255, 255, 255)) rs.MaterialShine(MatInd, 0) rs.MaterialTransparency(MatInd, 0.9) elif Material == "Structure": rs.MaterialColor(MatInd, (0, 0, 0)) rs.MaterialShine(MatInd, 0) rs.MaterialTransparency(MatInd, 0) elif Material == "ShinyBABlueMetal": rs.MaterialColor(MatInd, (0, 32, 91)) rs.MaterialShine(MatInd, 150) rs.MaterialTransparency(MatInd, 0) elif Material == "ShinyBARedMetal": rs.MaterialColor(MatInd, (218, 41, 28)) rs.MaterialShine(MatInd, 150) rs.MaterialTransparency(MatInd, 0) elif Material == "UnpaintedMetal": rs.MaterialColor(MatInd, (188, 198, 204)) rs.MaterialShine(MatInd, 30) rs.MaterialTransparency(MatInd, 0) elif Material == "FanDisk": rs.MaterialColor(MatInd, (0, 0, 0)) rs.MaterialShine(MatInd, 30) rs.MaterialTransparency(MatInd, 0.2) elif Material == "ShinyBlack": rs.MaterialColor(MatInd, (0, 0, 0)) rs.MaterialShine(MatInd, 120) rs.MaterialTransparency(MatInd, 0)
### define extrude line line_ex = rs.AddLine((0, 0, 0), (0, 0, 1)) ### draw rect tmp_crv = rs.AddRectangle(tmp_pln, 1, 1) tmp_surf = rs.AddPlanarSrf(tmp_crv) tmp_box = rs.ExtrudeSurface(tmp_surf, line_ex, True) ### set color rs.AddMaterialToObject(tmp_box) index = rs.ObjectMaterialIndex(tmp_box) rs.MaterialName(index, str(i) + "_" + str(j)) rs.MaterialColor(index, ((255 / count) * i, 255 - ((255 / count) * j), 255 - ((255 / count) * j))) name = rs.MaterialName(index) # print name ### delete rs.DeleteObject(tmp_pt) rs.DeleteObject(tmp_crv) rs.DeleteObject(tmp_surf) rs.DeleteObject(line_ex) ### export fbx export_toggle = rs.GetString("Export FBX? y/n") if export_toggle == "y":