sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    About color

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 5 Posters 657 Views 5 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.
    • Z Offline
      zps222
      last edited by

      @thomthom said:

      @zps222 said:

      # Draw a Face and set its material ents = Sketchup.active_model.entities face = ents.add_face [1, -1, 1], [1, 1, 1], [-1, 1, 1], [-1, -1, 1] ents.material = ct_mat

      You are applying material to the entities collection - no such method. That should produce an error.
      face.material = ct_ma should work

      Hard to tell why only one face is blue for you, since your sample code just creates a single face.

      Thank you. I use the pushpull method to draw a cube, so is there any method to paint the other sides?

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

        Are you drawing into an empty context? Or into a context with existing geometry?

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

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

          If you draw into a context where it's only your group, you can do this:

          
          entities.each { |e|
            next unless e.is_a?(Sketchup;;Face)
            e.material = 'blue'
          }
          
          

          If you are drawing into a context with existing geometry:

          
          cache = entities.to_a
          face = entities.add_face( [1, -1, 1], [1, 1, 1], [-1, 1, 1], [-1, -1, 1] )
          face.pushpull(1)
          (entities.to_a - cache).each { |e|
            next unless e.is_a?(Sketchup;;Face)
            e.material = 'blue'
          }
          
          

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

          1 Reply Last reply Reply Quote 0
          • AdamBA Offline
            AdamB
            last edited by

            Nice thomthom, but wouldn't it be simpler to apply color to the face and then pushpull and it will pick up the material of the originating face.

            Developer of LightUp Click for website

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

              @adamb said:

              Nice thomthom, but wouldn't it be simpler to apply color to the face and then pushpull and it will pick up the material of the originating face.

              I did think of that - but when modelling I some times find PushPull to apply the material to the back-side of the extruded faces. Though not always - haven't worked out when it happens. (material is on the front face)

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

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

                Good pragmatic solution. 👍

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

                1 Reply Last reply Reply Quote 0
                • AdamBA Offline
                  AdamB
                  last edited by

                  Whoa there! Hammer to crack a nut there.

                  In a right handed system (like SU), the front of a Face is defined in an anti-clockwise direction. Imagine gripping the face normal with your right hand and your thumb in the direction of the normal - your fingers show the winding of the face.

                  Face#pushpull() takes a distance to move along the face normal. So if you define a Face and paint its front material with something, then apply a negative pushpull, you'll always get a cuboid with that material on the outside.

                  Adam

                  Developer of LightUp Click for website

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @thomthom said:

                    @adamb said:

                    Nice thomthom, but wouldn't it be simpler to apply color to the face and then pushpull and it will pick up the material of the originating face.

                    I did think of that - but when modelling I some times find PushPull to apply the material to the back-side of the extruded faces. Though not always - haven't worked out when it happens. (material is on the front face)

                    But if you applied to both the front and back before push-pulling, then all will have the color afterward.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by

                      The loop 'direction' does indeed force the face.normal except in one important case... If you draw a 'flat' face a z=0 it will always face downwards no matter which 'direction' you might have drawn the loop :!

                      It's a quirk of Sketchup - it thinks you are going to PushPull the face 'up' in that case so it orients it for you to suit. It happens when making flat faces at z=0 both manually AND via the API.

                      Whenever I do this sort of face making I always check for
                      face.nornal.z==-1 and face.vertices[0].position.z==0
                      and if true and if I want to PushPull the face 'up' I add face.reverse! before I face.pushpull(distance). Remember too that you also use a negative distance to make the 'box' above an 'upwards looking' face...

                      Incidentally Adam is right that adding the material before doing the PushPull is the simplest way to make all of the new faces in that material. It is best to leave face-backs in the default 'blue' back-material as it's easier to see what's happening without resorting to Monochrome mode to check faces are correctly oriented...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @adamb said:

                        Whoa there! Hammer to crack a nut there.

                        Well not a hammer (you overreact..) nut..

                        The problem does not occur with the built-in pullpull tool.

                        Does SU automatically reverse the face that is colored differently, using the built-in Tool?

                        EDIT: I guess TIG answered the nitty-gritty there. The API doesn't say that Face.pushpull's second argument defaults to false.

                        I'm not here much anymore.

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

                          @dan rathbun said:

                          @adamb said:

                          Whoa there! Hammer to crack a nut there.

                          Does SU automatically reverse the face that is colored differently, using the built-in Tool?

                          In my experience - yes, sometimes.

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

                          1 Reply Last reply Reply Quote 0
                          • Z Offline
                            zps222
                            last edited by

                            Thank you all guys

                            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