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 $tthickHere the pushpull code extrudes the faces above grade, but the colors get trapped inside the extrusion.
face.pushpull -$tthickis 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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement