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

    Ruby script for selecting color

    Scheduled Pinned Locked Moved Developers' Forum
    62 Posts 4 Posters 1.9k 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      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...

      TIG

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

        Not
        require 'Sketchup.rb' class Testbox def testbox1
        ...
        Try
        require 'Sketchup.rb' class Testbox def **initialize**()
        ...
        Then use Testbox.new() which will run the initialize...

        TIG

        1 Reply Last reply Reply Quote 0
        • nithi09N Offline
          nithi09
          last edited by

          Thanks you for you help. it's works

          1 Reply Last reply Reply Quote 0
          • nithi09N Offline
            nithi09
            last edited by

            Hi I want to add texture for this box I want to see this box look like glass box any Idea?
            thanks

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

              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 use mat.alpha=0.5 to add opacity < 1... aka transparency

              TIG

              1 Reply Last reply Reply Quote 0
              • nithi09N Offline
                nithi09
                last edited by

                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

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

                  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...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • nithi09N Offline
                    nithi09
                    last edited by

                    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

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

                      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]

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • nithi09N Offline
                        nithi09
                        last edited by

                        Hi TIG how do I find preexisting material on my box? is not 'Glass' thx

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

                          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'... 😕

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • nithi09N Offline
                            nithi09
                            last edited by

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

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

                              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 for face.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.reverse

                              You need to find and read code examples more....

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • nithi09N Offline
                                nithi09
                                last edited by

                                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.

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

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

                                  TIG

                                  1 Reply Last reply Reply Quote 0
                                  • nithi09N Offline
                                    nithi09
                                    last edited by

                                    Hi TIG It's working thanks.
                                    How do I choose specific one face If I have multiple faces in same direction

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

                                      Find something unique about that face - like its bounds.min x/y/z ?

                                      TIG

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

                                        The sloping, upward looking face will have a normal.z>0 BUT ALSO normal.z<1, it also has a normal.x<0 - so that finds that kind of face ?
                                        The triangular face has normal.x==1, BUT so does the rectangular one next to it.
                                        You can differentiate them using face.vertices.lengthon each, ==3 for the triangle and ==4 for the rectangle ?
                                        Or if the difference is that it is below the red axis, testing face.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 like SketchUp show axes in 3d with Z typically up the screen rather that 'out-of-it'... bb.min, bb.max and bb.center etc should be self-evident ?

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • nithi09N Offline
                                          nithi09
                                          last edited by

                                          thanks TIG for fast reply I am going to try. I will let you know!!

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

                                            @nithi09: Please use [ code ] ... many lines of Ruby code here ... [ /code ] bbCode tags around large blocks of Ruby code.

                                            🤓

                                            I'm not here much anymore.

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

                                            Advertisement