HI, I’ve managed to setup a pretty cool and efficient toolbar to pretty quickly change the display color of parts in Rhino (Windows) with a click of a button… but I have arrived at a possible problem. Now that Rhino 7 seems to support Transparency (Alpha) in colors in Shaded Viewport I was trying to setup a few transparent colors on the bar, but I have not been able to come up with the right awat to code a RGB color with Alpha on the toolbar script area…
Does Rhino support RGB alpha colors and or scripting them ? and if it does, how do I do it ?
I also noted that the Icon creation utility does not support Alpha transparency, are you planing to add Alpha to the Icon creation utility and a couple of extra tools would be good too.
has not been adapted to accept an alpha value yet. I do see that the rhinoscriptsyntax methods such as rs.coercecolor() and rs.ObjectColor() do accept alpha values. So what you want can be done currently via a script such as the following (the alpha value is the 4th number):
"""Changes selected objects' colors to a fixed color (argument)
Script by Mitch Heynick 15.12.18"""
import rhinoscriptsyntax as rs
def MakeColor(color):
block_count=0
selected=rs.GetObjects("Select objects to apply color",preselect=True)
if selected:
objs=[]
for obj in selected:
if rs.IsBlockInstance(obj): block_count+=1
else: objs.append(obj)
if objs:
rs.EnableRedraw(False)
rs.ObjectColor(objs,color)
#rs.UnselectAllObjects()
rs.Redraw()
msg2="{} block instances found - explode before changing color!"
if block_count: rs.MessageBox(msg2.format(block_count))
#change color argument as needed, 4th value is alpha for V7
MakeColor(rs.coercecolor([0,255,0,127]))
The above script is perhaps a bit complicated, I just pulled it out of my library to test. However, all you really need to do is set up a toolbar button that looks like this:
NoEcho ! -_RunPythonScript (
<paste the entire script in here>
)
You can duplicate this button as many times as you want, and then in each button, just change the 4 [r,g,b,a] values in the last line of the script to what you want.
i.e. for a half-transparent cyan it would be [0,255,255,127]
Note also that if you have a custom backface color turned on for a display mode, it will show through the transparency.
David’s grasshopper font - best bitmap font i have found, and i have tried hundreds no lie, it’s optimized for 8px, all caps, 4 chars fit width wise on 24x24
example (one has a transparent background, might be hard to see):
_NoEcho
_-RunScript (
arrObjects = Rhino.GetObjects(“Select objects to change color”, 0, True, True, True)
If IsArray(arrObjects) Then
color = Rhino.GetColor
If Not IsNull(color) Then
Rhino.EnableRedraw False
For Each strObject In arrObjects
Rhino.ObjectColor strObject, color
Next
Rhino.EnableRedraw True
Erase arrObjects
End If
End If
)
and go thru the motions, when I get the colorpicker window, something strange happens… the alpha sliding bar disappears from all the colorpickers that have it… is there a reason for that or just a bug in the system… love to have the bar back, so the user could pick a transparent color it that is what he or she wants.
Could you help ?.. this color picker toolbars are getting way over my head… love to make them as good as possible.
OK, it does look like GetColor() has not implemented the color picker with the transparent sliders - it still calls the RhinoCommon method to pick only an RGB color with no alpha. The other methods are there in RhinoCommon, so it should be possible to fix this one relatively easily.
But, are you saying that once that you run the script once, the color picker loses it’s transparent slider for good? For everything else including non-scripted operations, like selecting an object and going to Properties>Display color and choosing “Other” (which should bring up the color picker)?
Here that doesn’t happen, only when I call GetColor() via a script.
Oh, and I can probably come up with a similar script that uses some RhinoCommon that actually does pull up the color picker dialog with alpha enabled. But it’s late here, maybe tomorrow.
No, it doesn’t loose the alpha bar for anything else… it just disappears for the script, every time… the colorpicker remains OK on the layer’s panel for example…
It’s fixed now. Below is a Python script with a method “GetColorAlpha” that can substitute for rs.GetColor() and return a color with an alpha channel until it is adapted. I cannot do this in VB Rhinoscript unfortunately, as VB Rhinoscript cannot access RhinoCommon, which is what I need to get to to fix the problem.
import rhinoscriptsyntax as rs
import Rhino
def GetColorAlpha(color=[0,0,0,255]):
#returns a tuple (r,g,b,a)
color = rs.coercecolor(color)
if color is None: color = System.Drawing.Color.Black
color=Rhino.Display.Color4f(color)
rc, c = Rhino.UI.Dialogs.ShowColorDialog(color,True)
if rc: return (int(c.R*255),int(c.G*255),int(c.B*255),int(c.A*255))
obj_ids=rs.GetObjects("Select objects to change color",preselect=True)
if obj_ids:
obj_color=GetColorAlpha()
if obj_color:
rs.EnableRedraw(False)
rs.ObjectColor(obj_ids,obj_color)