Ruby script for selecting color
-
Well done TT - I didn't spot the mismatch between 6.feet length and "6'" string.
If you are making a dropdown list it needs to be text, that you convert to a length later... -
Not
require 'Sketchup.rb' class Testbox def testbox1
...
Try
require 'Sketchup.rb' class Testbox def **initialize**()
...
Then useTestbox.new()
which will run the initialize... -
Thanks you for you help. it's works
-
Hi I want to add texture for this box I want to see this box look like glass box any Idea?
thanks -
If you have a glass texture already existing use that by 'Name'.
If you have added a 'color' material you can get a reference to that after you have made it/added it to a face:
mat=base.material
and then usemat.alpha=0.5
to add opacity < 1... aka transparency -
Hi TIG it's working. but I want to see both way. I mean from outside to inside the box see through fine but inside to outside not see through how do I can do both way? or where do I can find clear glass texture
Thanks -
When you give the first face ['base' ?] its material you need to also apply it to the back face thus:
base.material = 'xxxx' base.**back_material** = 'xxxx'
where 'xxxx' is the material... -
Hi TIG how do I can add glass texture to only one wall of box out of four walls.above method applying whole box. I like to try only one wall glass.thanks
-
Well... you need to work out how to 'find' the face first, then once you have it give it a [preexisting] material - let's assume it's name is 'Glass'...
A face has a 'normal' - which the vector that tells us which way a face is looking...
So let's say the collection of faces [along with edges etc] is in ` - then you need to filter that to find just the faces and then from that exact face with a particular 'normal'...
Let's also assume it is a box so only one matching face.normal will be found...group.entities.grep(Sketchup;;Face).each{|face| if face.normal==Z_AXIS ### == faces 'UP'... BUT you can use any vector to compare face.material='Glass' face.back_material='Glass' break ### stop looking end }
group.entities.grep(Sketchup;;Face).each{|face|
if face.normal==Z_AXIS ### == faces 'UP'... BUT you can use any vector to compare
face.material='Glass'
face.back_material='Glass'
break ### stop looking
end
}[/code:ngl1vctf] -
Hi TIG how do I find preexisting material on my box? is not 'Glass' thx
-
Your materials have names.
I used 'Glass' as an example.
The material must already exist in the model.
[I am skipping explaining how to create a material if it doesn't already exist, change its RGB and opacity etc... that wasn't your original question!]So use any existing material you want - just pass its 'name'...
-
Hi TIG What I am trying to do above creating box one side of box look like see through glass and rest solid coloured any idea???
-
An image of what you expect might help us help you, we are not mind-readers.
I have given you a general framework for code that finds "any face" by its direction and gives it a material.
The example I gave was forface.normal==Z_AXIS
which means it faces directly upwards,
BUT you can compare it to any axis
X_AXIS
Y_AXIS
and for the 'opposite direction'...
X_AXIS.reverse
Y_AXIS.reverse
Z_AXIS.reverseYou need to find and read code examples more....
-
Hi TIG could you recommend any good book specific for sketchup with code example. I have a book called "Automatic Sketchup" by Matthew Scarpino. It's not enough detail for me.
-
@nithi09 said:
Hi TIG could you recommend any good book specific for sketchup with code example. I have a book called "Automatic Sketchup" by Matthew Scarpino. It's not enough detail for me.
That's an excellent start.
Also get examples of others scripts [not too complex to start] and see how others do it... -
Hi TIG It's working thanks.
How do I choose specific one face If I have multiple faces in same direction -
Find something unique about that face - like its bounds.min x/y/z ?
-
The sloping, upward looking face will have a
normal.z>0
BUT ALSOnormal.z<1
, it also has anormal.x<0
- so that finds that kind of face ?
The triangular face hasnormal.x==1
, BUT so does the rectangular one next to it.
You can differentiate them usingface.vertices.length
on each,==3
for the triangle and==4
for the rectangle ?
Or if the difference is that it is below the red axis, testingface.bounds.min.y<0
will find it...Tip on
bb=object.bounds
bb.width
is in X
bb.height
is in Y
bb.depth
is in Z
this is NOT as you might initially assume - 'height' is NOT the Z - the bounds conventions come from the older CAD concept, where width/height are from the screen, when you typically looked at an object in plan, from above; and the 'depth' is the extent it projected 'out-of-the-screen'. 3D modelers likeSketchUp show axes in 3d with Z typically up the screen rather that 'out-of-it'... bb.min
,bb.max
andbb.center
etc should be self-evident ? -
thanks TIG for fast reply I am going to try. I will let you know!!
-
@nithi09: Please use [ code ] ... many lines of Ruby code here ... [ /code ] bbCode tags around large blocks of Ruby code.
Advertisement