Yes it is. All you need is a Python script. Here is a starting point:
import Eto
import System
import Rhino
import scriptcontext as sc
def test_modify_layer_colors():
# Process each layer
for layer in sc.doc.Layers:
# Get layer color as System.Drawing.Color
color = layer.Color
# The .NET Framework does not support other color spaces.
# But Eto does...
# Convert color to Eto.Drawing.Color
color_eto = Eto.Drawing.Color.FromArgb(color.ToArgb())
# Convert Eto color to Eto HSB color
color_hsb = color_eto.ToHSB()
# Get HSB values
h = color_hsb.H # [0.0, 360.0]
s = color_hsb.S # [0.0, 1.0]
b = color_hsb.B # [0.0, 1.0]
print('[H={0}, S={1}, B={2}]'.format(h, s, b))
#
# TODO: do something with HSB values here
#
# Reconstruct Eto HSB color
color_hsb.H = h
color_hsb.S = s
color_hsb.B = b
# Convert Eto HSB color to Eto color
color_eto = color_hsb.ToColor()
# Convert Eto color to System.Drawing.Color
color = System.Drawing.Color.FromArgb(color_eto.ToArgb())
# Set layer color
layer.Color = color
# Call the function defined above
if __name__ == "__main__":
test_modify_layer_colors()
If I understand correctly, you’re trying to help me learn basic python scripting to advance my Rhino game. If this is the case, I’m a blank slate. I have no experience in the nuance, hierarchies of programming. If you can direct me on how to approach this/learn, it would be appreciated.
However, to get to the stage of creating a neat functioning script might take time for abstract learning, trial and error - longer than I currently have at my disposal.
For learning Python, this is as good as any place to start:
As for the script, the code retrieves the hue (h), saturation (s), and brightness (b) components for every layer color. All you need to do is “tweak” these values to your liking - the code will do the rest.
@jdelavaulx
Here’s my attempt using the colorsys module in Python.
Below is just one for selected layers to test, if that works for you I can easily make one for selected objects. I hope I got the clamping right (i.e. the H value is circular from 0-360-0 again).
Edit - fixed one typo… sorry.
Edit 2 - fixed the S, V command prompts LayerColorHSVShift.py (2.6 KB)
Both scripts working a charm. Thank you so much Mitch!
In combination with randomise layer colours, this is also a very quick way to get unique colours for a large amount of layers.
If the objects are already existing, they have a color, I think I can write a script to just adjust the transparency and keep the same color. Let me look.
Does this work for you? Edit: please use revised version further down SetObjTransparency.py (1.1 KB)
The question on practicality I have here is what to set the minimum percentage value at. Right now, I have it set to not quite zero. But is that practical? Should I limit it to some higher minimum percentage like 1%?
TBH, I don’t really do anything in GH that changes the value of existing objects in the Rhino document. I am sure it’s possible with some plug-ins like Elefront, and probably in GH2 natively…
The scripts above are for “shifting” the color - not setting it with fixed values. Is shifting the existing transparency what you want? Or something that simply sets it?
Also, as per my question above, is allowing 100% transparency (alpha=0) useful?
I was literally just thinking about the fact that a shift is desired; instead of an absolute value; just before jumping on here to see your post commenting the same.
responding to your question; I think that 100% transparency would not be a bad thing, because the object or hatch can still exist without being seen; but can be changed back to full opacity if desired.
Do you think that -100 to +100 shift for transparency would be good? Or do you think that -255 to + 255 as a change in hex could also be valuable?