Ruby code: Random colored faces ?
-
Does anyone know if its possible to use the Rand function, or some other way to distribute random colors to a number of pushpull faces ?
the present code below, defines a single color, I would like to add a random color routine
face = entities.add_face $xp0, $p1 ,$p4, $p0 face.material= Sketchup;;Color.new(255, 255, 255) face.pushpull -($tthick+rand(20))
The random color selection would paint faces similar to the pic, whose faces presently were individually painted.
-
face.material= Sketchup::Color.new( rand(255), rand(255), rand(255))
-
@thomthom said:
face.material= Sketchup::Color.new( rand(255), rand(255), rand(255))
thanks thomthom for the quick reply;
It works with the pushpull code below: however the faces are extruded below grade.face.pushpull $tthick
Here the pushpull code extrudes the faces above grade, but the colors get trapped inside the extrusion.
face.pushpull -$tthick
is there a reverse statement I can use?
-
It sounds like the direction of your face isn't what it needs to be for you to get your expected result. Normally the direction of a face is controlled by the order of the vertices used to create the face - clockwise vs counter-clockwise. The exception is when the face is on the group plane, then SketchUp will force it face down.
What you can try is, before you push-pull:
face.reverse!
- this will flip the face normal. -
My error, I picked the order of the faces anticlockwise
-
Maybe Chris Fullmer can help you
-
Hi
@unknownuser said:
I picked the order of the faces anticlockwise
You just have to reverse the order of points when creating the face, or to check the normal after creating it:
myface=Sketchup.active_model.entities.add_face(p1,p2,...pn) # Default normal to blue (up) face.reverse! if face.normal.z<0
Advertisement