def AddThisLayer(thisLayerData, counter): ########################## isRoot = False try: counter += 1 if counter > 4: print "Loooop detected" return int(thisLayerData[parentColumn]) parentLayData = layerData[thisLayerData[parentColumn]] parentLay = AddThisLayer(parentLayData, counter) except: isRoot = True parentLay = None ########################## if rs.IsLayer(thisLayerData[fullLayerNameColumn]): rootLayers.append(thisLayerData[fullLayerNameColumn]) return thisLayerData[fullLayerNameColumn] newLayer = rs.AddLayer(thisLayerData[fullLayerNameColumn], thisLayerData[colorColumn]) rs.LayerLinetype(newLayer, thisLayerData[linetypeColumn]) rs.LayerPrintColor(newLayer, thisLayerData[printcolorColumn]) rs.LayerPrintWidth(newLayer, thisLayerData[printwidthColumn]) try: MaterialToLayer(newLayer, thisLayerData[materialColumn]) except: print "Material failed" #pass if isRoot: rootLayers.append(newLayer) return newLayer
def set_layer_properties(layer, properties): """Set Rhino layer properties.""" rs.LayerVisible(layer, properties.get("LayerVisible")) rs.LayerLocked(layer, properties.get("LayerLocked")) rs.LayerColor(layer, hex_to_rbg(properties.get("LayerColor"))) rs.LayerMaterialIndex(layer, properties.get("LayerMaterialIndex")) rs.LayerLinetype(layer, properties.get("LayerLinetype")) rs.LayerPrintColor(layer, hex_to_rbg(properties.get("LayerPrintColor"))) rs.LayerPrintWidth(layer, properties.get("LayerPrintWidth"))
def get_layer_properties(layer): """Get Rhino layer properties.""" return { "LayerVisible": rs.LayerVisible(layer), "LayerLocked": rs.LayerLocked(layer), "LayerColor": rgb_to_hex(rs.LayerColor(layer)), "LayerMaterialIndex": rs.LayerMaterialIndex(layer), "LayerLinetype": rs.LayerLinetype(layer), "LayerPrintColor": rgb_to_hex(rs.LayerPrintColor(layer)), "LayerPrintWidth": rs.LayerPrintWidth(layer) }
def get_layer_config(layer_name, defaults): conf = {} print_color = rs.LayerPrintColor(layer_name) color = get_color(print_color) if color != get_color(defaults.get('color')): conf['color'] = color print_width = rs.LayerPrintWidth(layer_name) if print_width != defaults.get('lineWeight'): conf['lineWeight'] = print_width line_type = rs.LayerLinetype(layer_name).lower() if line_type != defaults.get('lineType'): conf['lineType'] = line_type return conf
def setup_layer(name, options): parent = options.get('parent', None) locked = options.get('locked', False) if not rs.IsLayer(name): layer = rs.AddLayer(name=name, parent=parent, locked=locked) else: rs.ParentLayer(name, parent) layer = rs.LayerName(name) color = options.get('color', (0, 0, 0)) print_width = options.get('lineWeight', 0) linetype = options.get('lineType', 'Continuous') rs.LayerColor(name, color) rs.LayerPrintWidth(name, print_width) rs.LayerLinetype(name, linetype) return layer
def get_pattern_view_config(layer_name, defaults): conf = {} print_color = rs.LayerPrintColor(layer_name) pattern_color = get_color(print_color) if pattern_color != get_color(defaults.get('color')): conf['patternColor'] = pattern_color print_width = rs.LayerPrintWidth(layer_name) if print_width != defaults.get('lineWeight'): conf['patternLineWeight'] = print_width hs = get_hatches(layer_name) if len(hs) > 0: h = hs[0] pattern = rs.HatchPattern(h.Id) if pattern != defaults.get('pattern'): conf['pattern'] = pattern scale = rs.HatchScale(h.Id) if scale != defaults.get('scale'): conf['patternScale'] = scale return conf
import rhinoscriptsyntax as rs import re layers = rs.LayerNames() rs.EnableRedraw(enable=False) for layer in layers: if re.search("A-WALL", layer): rs.LayerPrintWidth(layer, 0.3) rs.EnableRedraw(enable=True)
import Rhino layerDict = {} layerNames = list(filter(lambda x: not rs.IsLayerReference(x), rs.LayerNames())) print(layerNames) rs.EnableRedraw(enable=False) layerDict["A-WALL"] = {"LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.6} layerDict["A-BLDG-SHAFT"] = {"LayerLinetype" : "dashed", "LayerPrintWidth" : 0.3cl } layerDict["S-COL"] = {"LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.3} layerDict["S-COLS"] = layerDict["S-COL"] layerDict["A-WALL-INTR"] = {"LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.3} layerDict["I-WALL"] = layerDict["A-WALL-INTR"] layerDict["A-GLAZ"] = {"LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.6} layerDict["A-HATCH-STORAGE"] = {"LayerLinetype" : "Continuous", "LayerPrintWidth" : 0.3} layerDict["A-BLDG-OTLN-ABOV"] = {"LayerLinetype" : "HIDDEN2", "LayerPrintWidth" : 0.3} layerDict["A-BLDG-OTLN-BLOW"] = {"LayerLinetype" : "Dashed", "LayerPrintWidth" : 0.3} layerDict["A-FLOR"] = {"LayerLinetype" : "Continuous2", "LayerPrintWidth" : 0.3} layerDict["A-ANNO-NOTE"] = {"LayerLinetype" : "Continuous2", "LayerPrintWidth" : 0.1} print(layerNames) for layer in layerNames: for entry in layerDict: if re.search(entry+"$", layer): rs.LayerLinetype(layer, layerDict[entry]['LayerLinetype']) rs.LayerPrintWidth(layer, layerDict[entry]['LayerPrintWidth']) rs.EnableRedraw(enable=True)
def matchLayer(name, source): rs.LayerLinetype(name, linetype = rs.LayerLinetype(source)) rs.LayerPrintColor(name, color = rs.LayerPrintColor(source)) rs.LayerPrintWidth(name, width = rs.LayerPrintWidth(source))
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) rs.EnableRedraw(enable=True)
def translateLayer(layer): """ translates from Rhino Name to CAD Name input: one layer returns: new layer name """ rhinoLayerFilePath = "C:\\Users\\Tim\\Desktop\\temp\\RhinoLayersV2.csv" #Read the CSV file = open(rhinoLayerFilePath, "r") contents = file.readlines() file.close() #Variables CategoryCol = 1 RhinoLayerCol = 2 CADNameCol = 9 CADColorCol = 10 CADLineweightCol = 11 found = False layerShort = rs.LayerName(layer, False) newLayerName = "" #Check the CSV for row in contents: rowParts = row.split(",") if row.split(",")[RhinoLayerCol] == str( layerShort): #if layer name exists in CSV CADName = row.split(",")[CADNameCol] CADColor = translateColor(layer, row.split(",")[CADColorCol]) CADLineweight = row.split(",")[CADLineweightCol] #if Rhino name found but no CAD name associated with it if not CADName: CADName = "A-RHINO-" + layerShort newLayerName = CADName if len(CADLineweight) < 2: CADLineweight = 0 #Check if layer already exists. parent = rs.ParentLayer(layer) existLayers = rs.LayerChildren(parent) isExisting = False for existLayer in existLayers: #if new name already exists as a layer if rs.LayerName(existLayer, False) == CADName: layersObjs = rs.ObjectsByLayer(layer) for layersObj in layersObjs: rs.ObjectLayer(layersObj, existLayer) rs.DeleteLayer(layer) newLayerName = rs.LayerName(existLayer, False) print "Layer {} merged with existing layer {}.".format( layerShort, rs.LayerName(layer, False)) isExisting = True break #if layer does not already exist if isExisting == False: rs.LayerColor(layer, CADColor) rs.LayerPrintWidth(layer, float(CADLineweight)) newLayerName = CADName rs.RenameLayer(layer, CADName) print "Layer {} changed to layer {}.".format( layerShort, CADName) found = True break if not found: layerShort = rs.LayerName(layer, False) CADName = "A-RHINO-" + layerShort newLayerName = CADName rs.RenameLayer(layer, CADName) print "Layer {} has no matching CAD layer.".format(layerShort) return newLayerName return newLayerName
def get_lineweight(layer): lineweight = rs.LayerPrintWidth(layer) return format(float(lineweight), '.2f')
def addLayerFromCSV(layNumList): """ Adds a layer from a CSV file Input: int - list of Layer numbers, associated with CSV layer number Returns: None """ rhinoLayerFilePath = "Q:\\Staff Postbox\\Tim Williams\\10 DESIGN LAYERS\\dev\\LAYERS\\RhinoLayersV3.csv" #Read the CSV file = open(rhinoLayerFilePath, "r") contents = file.readlines() file.close() #Variables RhinoLayerCol = 1 ColorCol = 3 MaterialCol = 4 LinetypeCol = 5 PrintColorCol = 6 PrintWidthCol = 7 found = False allLayerInfo = [] #Find layer info for row in contents: rowParts = row.split(",") for item in layNumList: #if layNum matches the CSV: if row.split(",")[0] == str(item): thisLayInfo = [] nameCol = row.split(",")[RhinoLayerCol] if len(nameCol) < 1: break thisLayInfo.append(row.split(",")[RhinoLayerCol]) #Linetype LinetypeRaw = row.split(",")[LinetypeCol] if len(LinetypeRaw) > 1: Linetype = LinetypeRaw else: Linetype = "Continuous" #Layer Color LayColorRaw = row.split(",")[ColorCol] if len(LayColorRaw) > 1: LayColor = (int(LayColorRaw.split("-")[0]), int(LayColorRaw.split("-")[1]), int(LayColorRaw.split("-")[2])) else: LayColor = (0, 0, 0) #Print Color PrintColorRaw = row.split(",")[PrintColorCol] if len(PrintColorRaw) > 1: PrintColor = (int(PrintColorRaw.split("-")[0]), int(PrintColorRaw.split("-")[1]), int(PrintColorRaw.split("-")[2])) else: PrintColor = (0, 0, 0) #Print Width PrintWidthRaw = row.split(",")[PrintWidthCol] if len(PrintWidthRaw) > 1: PrintWidth = float(PrintWidthRaw) else: PrintWidth = float(0) thisLayInfo.append(LayColor) thisLayInfo.append(PrintColor) thisLayInfo.append(Linetype) thisLayInfo.append(PrintWidth) allLayerInfo.append(thisLayInfo) found = True break if not found: return None #Find root layer root = rs.LayerName(rs.CurrentLayer()).split("::")[0] #print root #Add Layer parent = None for eachItem in allLayerInfo: parent = rs.AddLayer(eachItem[0], color=eachItem[1], parent=parent) rs.LayerPrintColor(parent, eachItem[2]) rs.LayerLinetype(parent, eachItem[3]) rs.LayerPrintWidth(parent, eachItem[4]) return parent
import rhinoscriptsyntax as rs import re from System.Drawing import Color layernames = rs.LayerNames() for layer in layernames: if re.search("L01::", layer): layername = layer.split("::")[2] print( 'layerDict["'+layername+'"] = {'+ '"LayerColor" : '+ str(Color.ToArgb(rs.LayerColor(layer))) + ', "LayerPrintColor" : '+ str(Color.ToArgb(rs.LayerPrintColor(layer))) + ', "LayerLinetype" : "'+ str(rs.LayerLinetype(layer)) + '", "LayerPrintWidth" : '+ str(rs.LayerPrintWidth(layer)) + '}')