예제 #1
0
    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
예제 #2
0
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"))
예제 #3
0
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)
    }
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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)
예제 #7
0
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))
예제 #8
0
    "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)
예제 #9
0
def get_linetype(layer):
    linetype = rs.LayerLinetype(layer)
    return str(linetype)
예제 #10
0
layerDict["A-WALL"] = {
    "LayerColor": -1,
    "LayerPrintColor": -1,
    "LayerLinetype": "Continuous",
    "LayerPrintWidth": 0.6
}

currentLayer = rs.CurrentLayer()
print(currentLayer)

for entry in layerDict:
    cLayerName = currentLayer + "::" + entry
    print(cLayerName)
    if cLayerName not in rs.LayerNames():
        rs.AddLayer(entry,
                    Color.FromArgb(layerDict[entry]['LayerColor']),
                    parent=currentLayer)
        rs.LayerLinetype(cLayerName, layerDict[entry]['LayerLinetype'])
        rs.LayerPrintWidth(cLayerName, layerDict[entry]['LayerPrintWidth'])
    elif rs.LayerLinetype(cLayerName) is not (
            layerDict[entry]['LayerLinetype']):
        print(cLayerName, rs.LayerLinetype(cLayerName))
        print(entry, layerDict[entry]['LayerLinetype'])
        rs.LayerLinetype(cLayerName, layerDict[entry]['LayerLinetype'])
    if re.search("-HATCH-", cLayerName):
        layer_c = 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 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
예제 #12
0
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)) +
            '}')