• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Getting unexpected result when setting material color

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 4 Posters 177 Views
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 6 Jan 2012, 03:04

    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
    • D Offline
      Dan Rathbun
      last edited by 6 Jan 2012, 06:33

      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
      • T Offline
        TIG Moderator
        last edited by 6 Jan 2012, 15:10

        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 6 Jan 2012, 18:45

          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
          • T Offline
            thomthom
            last edited by 2 Feb 2012, 14:44

            @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
            • D Offline
              Dan Rathbun
              last edited by 3 Feb 2012, 01:21

              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
              • T Offline
                thomthom
                last edited by 3 Feb 2012, 08:54

                @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