Quick color selection toolbar

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.

I’m in Rhino 7 by the way.

Hope you can help.

Best, Jose

In a quick check here, it seems that the command line object color setting via

-_Properties _Pause _Object _Color _Object <r,g,b>

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]))

HI, Thanks, I’ll give it a shot. I’m not an expert on coding… I’ll let you know.

Thanks for the quick replay.

B, Jose

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.

HI,

You are a life saver… the second time around worked like a charm… and I can see the custom back-face color too… it is so cool…

I found out that Rhino uses 0 to 255 for transparency too, some time ago. not the standard, o to 1.

Thanks so much.

I didn’t find an entry for this in the bugtracker, so I added a new one:
https://mcneel.myjetbrains.com/youtrack/issue/RH-63188

would you mind sharing your toolbar when you are done? perhaps these tips in trade? :wink:

here’s two things that might help you:

  1. Pixelformer - free as in beer, no nags or crap. awesome icon editor with a lot more tools, layers, text etc,

http://www.qualibyte.com/pixelformer/

  1. 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):
UNTITLED UNTITLED

Component.ttf.zip (12.3 KB)

thanks for the info… we’ll publish my color bars when I finish them…

b, jose

HI,
I got another question…

when I run this script…

_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.

Thanks, Jose

and also,

Could you recommend a good source for me to learn RhinoScript… B, Jose

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.

What it uses:


What it should use:


image

@dale, @Alain

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.

I would start with Python and maybe here: Rhino - Rhino.Python 101

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.

Hi,

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 is just the script.

J

thanks for your help… and your quick response…

let’s talk tomorrow. B, Jose

Hope everything is OK, saw you were having problems with your Rhino update… i wont update myself…

J

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)
1 Like

hi,

thanks, just tried it… it works great…

B, Jose

RH-63581 is fixed in the latest Rhino 7 Service Release Candidate