Copy print color to layer color? (python)


#1

Does anyone happen to have a python script that will copy the print color to the layer color by chance? thank you in advance.


#2

@kleerkoat, do you want the script to assign the objects print color to the layer the object is on or to the layer the user picks ? Below does the latter:

import rhinoscriptsyntax as rs
    
def DoSomething():
    id = rs.GetObject("Object to get print color from", 0, True, False)
    if not id: return
    
    print_color = rs.ObjectPrintColor(id)
    if not print_color: return
    
    layer = rs.GetLayer("Layer to apply color to", None, False, False)
    if not layer: return
    
    rs.LayerColor(layer, print_color)
    
DoSomething()

c.


#3

i’d like to just do it for every layer. it doesn’t even need to be interactive. each layer’s print color to to it’s layer color. i’m having an issue importing it into autocad and i don’t want to figure out how to get autocad to use the print color i’ve assigned in Rhino. does that make sense?

the script you did post will be of use though. thank you. :slight_smile:


#4

Below is an example. I’ve kept the dialog to let the user choose one or more layers, to have the abillity to exclude some. To select multiple layers, just use Shift-Key:

import rhinoscriptsyntax as rs
    
def DoSomething():
    layers = rs.GetLayers("Select Layers", False)
    if not layers: return
    
    for layer in layers:
        print_color = rs.LayerPrintColor(layer)
        if print_color: 
            rs.LayerColor(layer, print_color)
    
DoSomething()

c.


#5

clement you are awesome, this saved me a ton of work, thank you sooooo much!