Set alpha of a face without material
-
When I draw a face, the material of this face is nil.
But how can I set an alpha value without setting a material?
Following situation:
- one large face and something behind that face
- by clicking on a "show / hide" button, this large face should get semi transparent, to see, what's behind
- by clicking it again, the face should get the same color as before.
I would like to avoid, to set at first a material, so set an alpha value. And reverse it again...
Do you have an idea, how I can handle this problem?
Thank you very much for your help!
-
You can't.
A new face has a default front material and back material, and they are both a plain color.
If you want to make a face transparent then you need to assign it a material that is itself transparent; OR place the face inside a group or component-instance that has a transparent material, and thereby it will appear in the container's material provided that it and the default material...
Swapping the material on a button click is quite easy to do.
Alternatively your button click could simply hide/show the face, or move the face onto an OFF layer temporarily.
BUT to give a lone face transparency you need to use a material...
Why are you so set against this obvious [and only practicable] solution? -
@tig said:
Why are you so set against this obvious [and only practicable] solution?
Thanks TIG for your help! No, I'm not completely against this solution. I just thought, if it is possible to set alpha without any material, it would be great. However, then I have to set a material
I don't like to hide this faces completely, because, I would like to compare this large face and the face behind that...
-
So remember the
omat=face.material
Make a new translucent material [OR reuse it if it exists]
mats=Sketchup.active_model.materials name='Tranz' unless nmat=mats[name] nmat=mats.add(name) nmat.color="White" nmat.alpha=0.5 end#unless face.material=nmat
Then face is reset later...
face.material=omat
Adjust the color and alpha of 'nmat' as desired...
-
Now, it works alomost perfectly... I'm able to show / hide the right faces. But I have problems to the save the original material (in case of TIGs idea: "omat").
How I can save the material for ever - means, one should be able to reopen Sketchup and show the faces again...I tried it with "Entity.set_attribute" => but there, I can save just strings... do you have an idea, how I can save the material itself? Or can I save the ID of the material and to show the faces, call the material by its ID again?
Thanks for your help!
-
In your 'Tool' code make a class variable
@facesmats=[]
, 'push'[face, material]
, then with the methodsonCancel()
ordeactivate()
reset the face with its material, thus:
@facesmats.each{|a|a[0].material=a[1]}
To always exit as you started ?
OR use amodel.start_operation('xxx')
and then if there are no real changes in subsequent the code usemodel.abort_operation
to undo all changes, including the material swap[s]... -
Oh, okay, this is a nice trick...
I think, I will get a lot of problems, when Sketchup crashes...
What do you think about this idea:
I will create for every face, which has a material != nil a new material => name: face.to_s
To show the faces again, I will remove the materials again...
Advertisement