sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Ruby code: Random colored faces ?

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 836 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      tomot
      last edited by

      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.


      faces.png

      [my plugins](http://thingsvirtual.blogspot.ca/)
      tomot

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        face.material= Sketchup::Color.new( rand(255), rand(255), rand(255))

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • T Offline
          tomot
          last edited by

          @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?

          [my plugins](http://thingsvirtual.blogspot.ca/)
          tomot

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            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.

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • T Offline
              tomot
              last edited by

              My error, I picked the order of the faces anticlockwise 😳

              [my plugins](http://thingsvirtual.blogspot.ca/)
              tomot

              1 Reply Last reply Reply Quote 0
              • pilouP Offline
                pilou
                last edited by

                Maybe Chris Fullmer can help you πŸ˜‰

                Frenchy Pilou
                Is beautiful that please without concept!
                My Little site :)

                1 Reply Last reply Reply Quote 0
                • Didier BurD Offline
                  Didier Bur
                  last edited by

                  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
                  

                  πŸ’­

                  DB

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement