示例#1
0
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)
示例#2
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
示例#3
0
def get_solid_view_config(layer_name, defaults):
    conf = {}

    print_color = rs.LayerPrintColor(layer_name)
    solid_color = get_color(print_color)
    if solid_color != get_color(defaults.get('color')):
        conf['solidColor'] = solid_color
    return conf
示例#4
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"))
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 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)
示例#7
0
def Iterate():
    block = rs.GetObject("Select Design Option Block to iterate",
                         rs.filter.instance, True)
    if block is None: return

    try:
        prevBlockName = rs.BlockInstanceName(block)
        prevBlockLayer = rs.ObjectLayer(block)
        prevBlockLayerColor = rs.LayerColor(prevBlockLayer)

        newBlock = ReplicateBlock(block)
        newBlockName = rs.BlockInstanceName(newBlock)

        #Ensure 3_DESIGN OPTIONS already exists
        parentLayer = layers.AddLayerByNumber(3000, False)[0]
        rs.LayerVisible(parentLayer, True)

        #Create new design option layer
        #newBlockLayer = rs.AddLayer(parentLayer + "::" + newBlockName, color = utils.StepColor(prevBlockLayerColor))
        newBlockLayer = rs.AddLayer(parentLayer + "::" + newBlockName,
                                    color=utils.GetRandomColor())
        rs.LayerPrintColor(newBlockLayer, (0, 0, 0))
        rs.ObjectLayer(newBlock, newBlockLayer)

        #Save user text
        try:
            parentsUserTest = rs.GetUserText(block,
                                             'Design Option History') + "<--"
        except:
            parentsUserTest = ''
        rs.SetUserText(newBlock, 'Design Option History',
                       parentsUserTest + newBlockName)

        #Turn off prev blocks layer
        if rs.CurrentLayer() != prevBlockLayer:
            rs.LayerVisible(prevBlockLayer, False)

        result = True
    except:
        result = False
        newBlockName = ''
    utils.SaveFunctionData(
        'Blocks-Iterate',
        [__version__,
         rs.BlockInstanceName(block), newBlockName, result])
    return result
示例#8
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
示例#9
0
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
示例#10
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)) +
            '}')
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)
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
示例#13
0
    "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)
"""
For use with the Feasibility Study Workflow. 
See "F:\Resource\Strategic Initiatives\0702013.20 Research Initiative\Rhino Workflow"

For use with Feasibility Study Assistant Grasshopper Script.
See "F:\Resource\Strategic Initiatives\0702013.20 Research Initiative\Grasshopper\Grasshopper Toolset\Feasibility Drafting and modeling Assistant"

This script is to create a subfolder to a hatch layer that specifies it as an 
open area, as you might label as "OPEN TO BELOW" in floor plans.

Make sure the layer you want to add an OPEN layer to is the currently selected layer
before running.

"""

import rhinoscriptsyntax as rs

currentLayer = rs.CurrentLayer()
layerName = rs.LayerName(currentLayer, fullpath=False)
newLayer = rs.AddLayer(name=layerName+"_OPEN")
rs.ParentLayer(newLayer, currentLayer)


layer_c = rs.LayerColor(currentLayer)
layer_m = rs.LayerMaterialIndex(currentLayer)
if layer_m == -1:
    layer_m = rs.AddMaterialToLayer(newLayer)
rs.MaterialColor(layer_m, layer_c)
rs.LayerPrintColor(newLayer, layer_c)
rs.LayerColor(newLayer, layer_c)
示例#15
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))
示例#16
0
        rs.LayerVisible(lay_lis[i], visible=True)
    else:
        if rs.IsLayerVisible(lay_lis[i]):
            lay_vis.append(lay_lis[i])
        rs.LayerVisible(lay_lis[i], visible=False)

#Create the layers needed to highlight the section views and hide the clipping plane
lay_axo_sec = rs.AddLayer(name='lay_axo_sec',
                          color=(255, 255, 0),
                          visible=True)
lay_axo_pla = rs.AddLayer(name='lay_axo_pla', visible=False)
lay_fro_sec = rs.AddLayer(name='lay_fro_sec', visible=True)
lay_fro_pla = rs.AddLayer(name='lay_fro_pla', visible=False)
#lay_tag = rs.AddLayer(name='lay_tag',visible=True)

rs.LayerPrintColor('lay_axo_sec', color=(255, 255, 0))

#Change the main object name and create a list of the points for the bounding box to be used to align with origin
rs.ObjectName(obj_all, 'obj_all')
obj_cen = rs.BoundingBox(obj_all, view_or_plane='Perspective')

#Move selection to the origin of the working plane
env_org = rs.coerce3dpoint([0, 0, 0])
obj_cor = (obj_cen[0] + obj_cen[6]) / 2
rs.MoveObject(obj_all, env_org - obj_cor)

#Create a proper bounding box now that the part is centered
obj_box = rs.BoundingBox(obj_all, view_or_plane='Perspective')

# #Print coordinades with tags for visualization purposes
# for i, point in enumerate(obj_box):
示例#17
0
            "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)
示例#18
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)

rs.EnableRedraw(enable=True)