I’m trying to do some manipulations on colors with Skp 2017 and Ruby.
I need to assign different colors and opacity to different surfaces.
I saw there are two ways to change a face opacity:
- first : use a 4 channel color, ex : (255,255,255,255)
- second : use a 3 channel color and set an opacity to the material
I need to use the second solution.
So I have a float number for the alpha value I want to use and a color. I’m trying to assign them to a face by creating a new material. This is important because I don’t want faces with same color to change their opacity value as I change another face value.
So here is a simplification of my code:
mod = Sketchup.active_model ent = mod.entities.first alphaToSet = 0.589 colorToSet = Sketchup::Color.new(124,124,124) materialToSet = Sketchup::Material.new materialToSet.color = colorToSet materialToSet.alpha = alphaToSet ent.material = materialToSet
So the two unexpected error are the following :
materialToSet.color = colorToSetretruns “wrong argument type (expected Sketchup::Material)”. But you can find here in the API that the expected argument is a color !
ent.material = materialToSetretruns “no implicit conversion to Color”. But you can find here in the API that the expected argument is a material
One thing I cannot do (so please don’t propose it without testing) is :
- assign the colorToSet in the ent.material
- then assign an alpha value to the entity with : ent.material.alpha = alphaToSet
- This would make all the surfaces with the same color having the same opacity.
I would be very glad to learn how to do this basic operation of color assignment as it is the last part of a much more complex program I’d like to finish.
I repeat myself but this is important : I need that every surface has a different material ! Otherwise all faces would synchronize their opacity value.