Getting unexpected result when setting material color
-
When I run this script I get a range of blue colors applied to the components. I'm trying to get a range of red colors. I've checked and double checked my colors to make sure I have the right hex code for them.
mod=Sketchup.active_model ents=mod.entities sel=mod.selection my_colors=[0xFF3300,0xFF4719,0xFF5C33,0xFF704D,0xFF8566,0xFF9980] i=0 ents.each do |e| if e.is_a? Sketchup;;ComponentInstance e.material = my_colors[i] i+=1 end end
What am I missing?
Thanks,
Mark -
Sketchup uses RGBA color integers (which are read from right to left, least significant first.)
ie:
0xAABBGGRR
Here's an old post with some code snippets I haven't done much with in a long while:
[Ruby Extension] for Sketchup color integers -
Your codes are hex for 'blues' ?
Get some 'red' ones
http://www.rgbhex.com/index.php -
Thanks,
I was using what I thought was normal notation for colors i.e. 0xFF9900. Sketchup expects 0x0099FF. Who'd a thunk.Mark
-
@dan rathbun said:
Sketchup uses RGBA color integers (which are read from right to left, least significant first.)
ie:
0xAABBGGRR
I get errors in
0xAABBGGRR
Error: #<RangeError: (eval):155:in
material=': bignum too big to convert intolong'>
I can only get
0xBBGGRR
to be accepted. -
Yes well we all know there is much room for improvement in the API.
As I recall, only materials took (or used to take,) alpha. Colors did not.
But I remember a change in alpha during the v8 beta cycle. (Have to refer to the release notes.)
An alternative for colors (since they also take an Array argument,) is to set them like:
mycolor = Sketchup::Color.new( [0xFF,0x33,0x00] )
or
my_matl.color = [0xFF,0x33,0x00]
... which is read as
[red,green,blue]
-
@dan rathbun said:
As I recall, only materials took (or used to take,) alpha. Colors did not.
They do, and did. It's just that they wheren't used until SU let you draw to the viewport with transparency.
Advertisement