I think the aggregate time of switching a layer’s print color back to black ( ) might net me an extra year of life
I’ve tried using modifier keys, but no such luck. Anybody have the cheat code?
Thx
Alan
I think the aggregate time of switching a layer’s print color back to black ( ) might net me an extra year of life
I’ve tried using modifier keys, but no such luck. Anybody have the cheat code?
Thx
Alan
#! python3
import System
import Rhino
import scriptcontext as sc
layers=sc.doc.Layers
rc,sel_idxs=layers.GetSelected()
if rc:
s_layer_names=[]
for idx in sel_idxs:
layi = layers.FindIndex(idx)
if layi:
#layi.Color = System.Drawing.Color.Green
layi.PlotColor = System.Drawing.Color.Black
#layi.PlotColor = System.Drawing.Color.Blue
print(layi.Name)
save above as .py file
and
Thanks @Tom_P and love that you added the fair warning post
I do some scripting, though I’m no master. This exception popped-up, so I took a grab of it, along with the VSCode window for the py file:
Originally, I was just looking for a way to click the display color in the properties panel and have it somehow not affect the print color, but I assume that’s not possible, or you wouldn’t have written a script for it. I appreciate you sending it my way!
Looks like it goes through a selection of layers and sets the print color to black, which is nice so whenever I want, I can just change a bunch with just a few clicks. But how is that different than selecting the layers I want to change and just clicking the print color square and choosing black?
Seems maybe the problem is line 2 where it reads as “rc,” I don’t recognize that way of defining something – using the comma, I mean. Can you explain that?
Thanks again,
Alan
I don’t recognize that way of defining something – using the comma, I mean
if a function returns multiple values, you can unpack the values that way.
In this case, layers.GetSelected() returns a boolean and a list of layer indices. The boolean gets assigned to rc, the list of layers gets assigned to sel_idxs
As for the error message, to me it looks like you are trying to run the PythonScript as a RhinoScript (rvb)?
Use -_ScriptEditor Run instead for running scripts from the commandline
ifferent than selecting the layers
Dear @Alan_Farkas your initial post was not 100% clear to me - what are you after.
you can also ask for a color by script:
rgb = rs.GetColor(color)
so you might set the Layer Color via script - that should not change the Print/PlotColor
that s why i left this line as comment:
layi.Color = System.Drawing.Color.Green
the script was more seen as a starting point - for you to customize it as you need.
the error shows
“VB-Script compilation error”
so it is not recognised as python script
… see Gijs’s Posts above
kind regards
tom
Thanks for the info
Basically, when you click on a new layer’s display color swatch in the properties panel, and give it a color (red) and click OK, you’re left with both the display color and the print color as red. I was just wondering if there was a way to click that swatch and have it only affect the layer’s display color.
Sorry if I wasn’t super clear in my explanation. I’m assuming now it is not possible
Use -_ScriptEditor Run instead for running scripts from the commandline
Weird, because I’m calling on the script from the button, as normal.
got it.
even setting the color by script Color will set PlotColor as well.
so you have to remember the plotColor and reset it afterwards.
use this script to set the display-Color only:
#! python3
import System
import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs
layers=sc.doc.Layers
rc,sel_idxs=layers.GetSelected()
if rc:
color = rs.GetColor(color=[255,0,0])
if color:
for idx in sel_idxs:
layi = layers.FindIndex(idx)
if layi:
plotColor = layi.PlotColor
layi.Color = System.Drawing.Color.FromArgb(color[0],color[1],color[2])
layi.PlotColor = plotColor
does this do your trick ?
kind regards - tom
Weird, because I’m calling on the script from the button, as normal.
What I mean is, if you run python 3 code:
-_ScriptEditor _Run "path/to/scriptname.py"
or if you want to run python 2 code, you can also use the old RunPythonScript command:
-_RunPythonScript "path/to/scriptname.py"
and you are clearly using something like:
-_RunScript "path/to/scriptname.py"
which fails, because it thinks it gets a .vrb for lunch
Yes, I think that will do the trick script-wise, thank you so much.
Alan
Ah, so it is a Python 2 vs 3 thing. I noted the #! in the script but didn’t realize it changes the way I’d call the script. Thanks.