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

    Getting unexpected result when setting material color

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 177 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 Offline
      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 Offline
        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 Offline
          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 Offline
            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 Offline
              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 Offline
                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 Offline
                  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
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement