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

    [Code] Printing color range as grid for preprint checking

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 6 Posters 974 Views 6 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.
    • U Offline
      unearthed
      last edited by

      Hi

      I'm not into rendering yet, just simple output, but when I choose colors in the model I want to see how they'll look before I print - (I usually have a printed test card for this (see example). In the example included (from vectorworks) it can be useful to have a color name or number or RGB etc. Is there a way in Sketchup to at least print out a current color grid, with an option for color info would be great. I've searched hi and low for this and found zilch.

      SU version:8.0.4811
      OS win 7


      color swatch.JPG

      Growplan - People ∩ Plants ∩ Place

      windows 7 64b, 4GB RAM, SU 8.0.16846
      Gimp, QGIS, Vectorworks 12, Bricscad 11

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

        Not entirely clear...
        This is what I think you mean... you want a tool that makes a grid of squares, each with one of the SKP's materials added and some text showing it's details shown [Name, description, RGBA, texture].
        I suppose ideally this would be a group that's on it's own layer that is also only shown on its own scene-tab that is excluded from animations etc, and the view set to 'plan'...
        Correct me if I'm wrong...

        TIG

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

          Copy+paste this code into a file called colorswatch.rb in the Plugins folder.
          Restart Skecthup and type TIG.colorswatch into the Ruby Console... to make a colorswatch group/scene/layer etc.

          module TIG
           def self.colorswatch()
            model=Sketchup.active_model
            ss=model.selection
            defs=model.definitions
            ents=model.entities
            layers=model.layers
            pages=model.pages
            mats=model.materials
            names=[]
            mats.each{|mat|names << mat.name}
            names.sort!
            num=names.length
            return nil if num==0
            ###
            model.start_operation("colorswatch")
            ### erase previous ones
            gps=[]
            defs.each{|d|gps << d.instances if d.group?}
            gps.flatten!
            gps.each{|g|g.erase! if g.valid? and g.name=="colorswatch"}
            ### make new one
            gp=ents.add_group()
            gp.name="colorswatch"
            gents=gp.entities
            ### make tile
            tile=gents.add_group()
            tents=tile.entities
            face=tents.add_face([0,0,0],[200,0,0],[200,200,0],[0,200,0])
            face.reverse!
            trx=Geom;;Transformation.translation([400,0,0])
            try=Geom;;Transformation.translation([0,-400,0])
            dim=Math.sqrt(num).round
            step=dim
            (num).times{|i|
              mat=mats[names[i]]
          	tile.material=mat
          	txt=names[i]
          	rgb="RGB = "+mat.color.red.to_s+", "+mat.color.green.to_s+", "+mat.color.blue.to_s+"\nAlpha = "+mat.alpha.to_s
          	txt=txt+"\n"+rgb
          	if tex=mat.texture
          	  txt=txt+"\n"+"Texture = "+tex.filename
          	end#if
          	###
          	gents.add_text(txt, tile.bounds.min.offset([0,-20,0]))
          	tile=tile.copy
          	tile.transform!(trx)
          	if i==dim-1
          	  tile.transform!(try)
                step.times{tile.transform!(trx.inverse)}
          	  dim=dim*2
              end#if
          	if i==num-1
          	  txt="[<Default>]"
          	  gents.add_text(txt, tile.bounds.min.offset([0,-20,0]))
          	end#if
            }
            ### put on layer
            layer=layers.add("colorswatch")
            layer.page_behavior=LAYER_IS_HIDDEN_ON_NEW_PAGES
            pages.each{|p|p.set_visibility(layer,false)}
            gp.layer=layer
            ### make scene-tab
            pnames=[]
            pages.each{|p|pnames << p.name}
            if not pnames.include?("colorswatch")
              pages.add("colorswatch")
            end#if
            page=nil
            pages.each{|p|page=p if p.name=="colorswatch"}
            pages.selected_page=page
            layers.to_a[1..-1].each{|la|page.set_visibility(la,false)}
            pages.selected_page.set_visibility(layer,true)
            ### zoom extents
            eye=gp.bounds.center.clone
            eye.z=eye.z+1
            tar=gp.bounds.center.clone
            up=[0,1,0]
            model.active_view.camera.perspective=false
            model.active_view.camera.set(eye,tar,up)
            Sketchup.send_action("viewTop;")
            model.active_view.zoom_extents
            Sketchup.send_action("viewZoomExtents;")
            ###
            page.update(127)
            ###
            model.commit_operation
           end
          end
          

          It's not perfect as I threw it together quickly from other code... but will form the basis of what it is I think you want... πŸ€“

          TIG

          1 Reply Last reply Reply Quote 0
          • S Offline
            sergey2402
            last edited by

            Dear TIG. I beg your permission to use your script as a plugin colorswatch.rb


            colorswatch.rb

            1 Reply Last reply Reply Quote 0
            • U Offline
              unearthed
              last edited by

              Hi TIG, that's great, was very surprised you actually coded an answer.
              I had to meddle with the arrangement to print it but it's really useful.

              I hadn't thought as far as having it on its own scene tab, in a group etc, but
              yes that works well. I'll try and meddle with the text part now to select
              just the material name or RGB etc.

              cheers
              Nigel


              colourswatch from TIG's .rb

              Growplan - People ∩ Plants ∩ Place

              windows 7 64b, 4GB RAM, SU 8.0.16846
              Gimp, QGIS, Vectorworks 12, Bricscad 11

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

                This should be marked with [code] - or better yet - made into a new thread with the .rb file for download.

                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

                  Moved to 'developers' and [code] added...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • KrisidiousK Offline
                    Krisidious
                    last edited by

                    AWESOME!

                    By: Kristoff Rand
                    Home DesignerUnique House Plans

                    1 Reply Last reply Reply Quote 0
                    • atelierpaarA Offline
                      atelierpaar
                      last edited by

                      Hello Tig,
                      thanks for your "colorswatch" script.
                      I checked it out and it does pretty much what I had in mind.
                      Unfortunately the script seem to grab just the colors that are already in the Model.
                      It would be of great help, if one could choose a specific library / Folder like for Instance "Colors" or "named colors" or what ever Library there might be.
                      Do you think this would be possible ?

                      Uli

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

                        Unfortunately there is scant access to SKM files through the API...
                        Although my SKM-Tools do add some functions which could allow this...
                        It could get convoluted, since it would have to load all of the external SKM materials into the current model to be able to display them anyway πŸ˜•

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • atelierpaarA Offline
                          atelierpaar
                          last edited by

                          Hello Tig,
                          thanks for looking into it.
                          Just the SU Material file "colors" contains 310 Colors.
                          Each Color has to be selected and applied to some surface in order to get the color into the model.
                          It`s the tedious manual work that discouraged to make a color guide. πŸ‘Š
                          Is there perhaps a another way of mass-loading materials into a model ?
                          Uli

                          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