Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5793

Custom function to use ColorPicker with alpha

$
0
0

In response to another post here, I made a small definition to be able to call up the V7 color picker with the alpha sliders enabled - which rs.GetColor() doesn’t do yet. I ran into one interesting situation with the CMYK settings - which I have never used before to be honest. The definition is this:

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))
    
oc=GetColorAlpha()
print oc

This works fine with any of the RGB or HSL/HSV panels. However if I have the CMYK panel up, the fact that the alpha is specified as 255 by default gives me full black - even if I pick somewhere arbitrary on the color wheel.

image

Note that Alpha is at 255, but Black is also at 255 - i.e. full black.

If I set the default to [0,0,0,0] then in CMYK I get the black value set to 0 (to get a fully saturated color), but then the Alpha is also set to 0, so it is fully transparent, which doesn’t help me at all. In either case I have to manually set either the Alpha slider or the black slider.

image

How do I get this definition to work correctly for both RGB/HSV and CMYK ?

5 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5793

Trending Articles