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

    Color components

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 5 Posters 251 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.
    • B Offline
      blue_orchid
      last edited by

      ents = Sketchup.active_model.entities[0]
      ents.entityID
      
      Result-2345
      

      Now, I need to assign the color 'red' to this particular component whose entityID is 2345. How should I do it?

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        You already have a reference to the entity, so it is as simple as:

        ents.material = "Red"

        If you need to search for that entity again, then the following may work (unless you need to dig into sub-components:)

        Sketchup.active_model.entities.each {|entity|
          if entity.entityID == 2345
             entity.material = "Red"
             break
          end
        }
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          The previous example takes advantage of a feature of the .material= method which can accept a color name as an argument. You can view the available color names by entering Sketchup::Color.names in the Ruby Console window.

          If you want to use a custom color or texture, you need to add a new material, then assign it a color or texture.

          mat = Sketchup.active_model.materials.add("New Material") mat.color = Sketchup::Color.new(red, green, blue, alpha) ents.material = mat

          Note all parameters to the Color.new method are optional.

          Hi

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

            What are you using entityID for? Note that it's not a reference that last across sessions.

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

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

              Another minor point on 'idiom' - to make it easier for us to help debug your code please use logical names.
              If you get ALL of the entities in a selection as an array use
              ent**s**=model.selection.to_a
              The 's' on its name helps us/you realize/remember that it's an array of several objects...
              Then use
              ents.each{|ent| ent.material='Red' if ent.class==Sketchup::Face and e.normal.z==0 }
              To process each one in turn... Where logically ent is one of the things in the collection called ents

              To get the first thing selected therefore use a 'single' name like
              ent=model.selection[0]
              NOT a plural 'ents' which suggests to many that it's a collection...

              TIG

              1 Reply Last reply Reply Quote 0
              • B Offline
                blue_orchid
                last edited by

                Thanks to everyone!!!

                What should be the script If I have to add the new parameter like width=='1'? This parameter 'width' is a category from MySQl database.

                Sketchup.active_model.entities.each {|entity|
                if entity.entityID == 2345 and width=='1'
                entity.material = "Blue"
                break
                end
                }

                end
                

                end

                1 Reply Last reply Reply Quote 0
                • Chris FullmerC Offline
                  Chris Fullmer
                  last edited by

                  well, that depends. Do you just want to assign an attribute called "width" to an object? Or do you actually want to make that object be a specified width? I suppose the same also hold true for the color. Now I remember you're doing the database interaction.

                  Lately you've been tan, suspicious for the winter.
                  All my Plugins I've written

                  1 Reply Last reply Reply Quote 0
                  • B Offline
                    blue_orchid
                    last edited by

                    It's kind of both.

                    The component is assigned 'width' attribute and, also parameter 'width' is pulled out from database.

                    I am doing process by process. Right now, i am taking the parameter 'width' from db and coloring each component different colors. Like assigning Component1 with ID 2345 and width 10" a 'red' color, Component2 with ID 2343 and width 12" a 'blue' color and so on......

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

                      You're storing entityID in a database?

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

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

                        IDs do not subsist across sessions as they are re set every time the SKP opens.
                        You must give entities attributes which will be carried across sessions to find them successfully...

                        TIG

                        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