sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    Getting unexpected result when setting material color

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 485 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.
    • M
      marksolberg
      last edited by

      When I run this script I get a range of blue colors applied to the components. I'm trying to get a range of red colors. I've checked and double checked my colors to make sure I have the right hex code for them.

      mod=Sketchup.active_model
      ents=mod.entities
      sel=mod.selection
      my_colors=[0xFF3300,0xFF4719,0xFF5C33,0xFF704D,0xFF8566,0xFF9980]
      i=0
      ents.each do |e|
        if e.is_a? Sketchup;;ComponentInstance
             e.material = my_colors[i]
              i+=1   
        end
      end
      

      What am I missing?

      Thanks,
      Mark

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

        Sketchup uses RGBA color integers (which are read from right to left, least significant first.)

        ie: 0xAABBGGRR

        Here's an old post with some code snippets I haven't done much with in a long while:
        [Ruby Extension] for Sketchup color integers

        I'm not here much anymore.

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

          Your codes are hex for 'blues' ?
          Get some 'red' ones πŸ˜•
          http://www.rgbhex.com/index.php

          TIG

          1 Reply Last reply
          Reply Quote 0
          • M
            marksolberg
            last edited by

            Thanks,
            I was using what I thought was normal notation for colors i.e. 0xFF9900. Sketchup expects 0x0099FF. Who'd a thunk.

            Mark

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

              @dan rathbun said:

              Sketchup uses RGBA color integers (which are read from right to left, least significant first.)

              ie: 0xAABBGGRR

              I get errors in 0xAABBGGRR
              Error: #<RangeError: (eval):155:inmaterial=': bignum too big to convert into long'>

              I can only get 0xBBGGRR to be accepted.

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

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

                Yes well we all know there is much room for improvement in the API.

                As I recall, only materials took (or used to take,) alpha. Colors did not.

                But I remember a change in alpha during the v8 beta cycle. (Have to refer to the release notes.)

                An alternative for colors (since they also take an Array argument,) is to set them like:
                mycolor = Sketchup::Color.new( [0xFF,0x33,0x00] )
                or
                my_matl.color = [0xFF,0x33,0x00]

                ... which is read as [red,green,blue]

                I'm not here much anymore.

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

                  @dan rathbun said:

                  As I recall, only materials took (or used to take,) alpha. Colors did not.

                  They do, and did. It's just that they wheren't used until SU let you draw to the viewport with transparency.

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

                  1 Reply Last reply
                  Reply Quote 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 Login
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement