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

Retrieve Color Layer assigned by Sketchup

Scheduled Pinned Locked Moved Developers' Forum
16 Posts 4 Posters 1.3k 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.
  • C Offline
    c.plassais
    last edited by 19 Jun 2010, 08:59

    Hello everyone,

    Is there a method to retrieve the color assigned by Sketchup to each layer ?

    Thanks

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 19 Jun 2010, 10:00

      Not via the Ruby API - think it might be possible using the SDK.

      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 19 Jun 2010, 10:26

        Not in the current API, sorry.

        The other half of your "wish" (being able to set the color,) has already been requested in the API Wishlist forum.
        ie: http://forums.sketchucation.com/viewtopic.php?f=180&t=13666&p=165527&hilit=Layer#p165527

        That wishlist topic was created by Scott from Google, so it's the place to have your 'wishes' be known to the GSU Team. (I encourage you to post your wish for the "attribute getter" side of the Layer color issue.)

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • C Offline
          c.plassais
          last edited by 19 Jun 2010, 17:15

          Thank you to you for informations
          Damage
          I look at

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 20 Jun 2010, 21:19

            I wrote the layer.color=() .rb [do a search] that let's you set a layer's color using Ruby.
            Also getting a the layers' colors would be possible by exporting a temporary DXF and then getting the colors from that BUT there's nothing available direct from the API 😞

            TIG

            1 Reply Last reply Reply Quote 0
            • C Offline
              c.plassais
              last edited by 21 Jun 2010, 07:51

              thank you TIG

              I downloaded your plugin and I looked
              It's for my little plugin ➑ http://forums.sketchucation.com/viewtopic.php?f=323&t=28957#p251619
              I try to add a tool to draw lines with the color of the active layer

              Probably the best solution is with the API SDK C + +, as indicated Thomthom.
              I found in SDK, this method

              OLE_COLOR ISkpLayer::Color [get] Returns the color associated with this layer.

              but it is too complicated, Ruby and English is already a lot of work for me πŸ˜†

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 21 Jun 2010, 10:07

                @dan rathbun said:

                I found [url][Plugin] List Layer Colors.rb[/url] (the topic title is a bit mis-spelled BTW.)
                It creates a CSV file of Layers and their Colors. But I don't see it setting colors.
                [Any further comments on the above plugin, I'll post in that topic.]
                EDIT [ Maybe I missed the plugin you were refering to? ]
                Nevermind.. I found it, it is a [Code] not a [Plugin].
                It's here: [Code] layer-color= v1.2 ...

                That's my code to 'set' a layer's color - it does NOT 'get' it - hence the layer.color**=** method.
                There are several ways of using it layer.color="red" etc. It is terribly clunky, only works for colors [not textures] and would be much better as a built-in method...
                There was talk of another layer.material method to get the layer's material [I recall it was AdamB's ?] but it hasn't arrived as far as I know... http://forums.sketchucation.com/viewtopic.php?f=180&t=25697&p=224534&hilit=layer#p224534

                TIG

                1 Reply Last reply Reply Quote 0
                • C Offline
                  c.plassais
                  last edited by 21 Jun 2010, 10:11

                  Thank you Dan

                  For your help and your time

                  even a csv list of color layers, it's good for me

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    c.plassais
                    last edited by 21 Jun 2010, 10:23

                    and thank also TIG

                    for your plugin and your time πŸ‘
                    I use only color, no materials
                    layer.color one method is perfect for me
                    Not to change the color layer, just retrieve and use

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      TIG Moderator
                      last edited by 21 Jun 2010, 10:28

                      This is the 'layer color' csv listing tool http://forums.sketchucation.com/viewtopic.php?p=11924#p11924
                      It needs Pro though... πŸ˜•

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        Dan Rathbun
                        last edited by 21 Jun 2010, 10:51

                        I found [Plugin] List Layer Colors.rb (the topic title is a bit mis-spelled BTW.)
                        It creates a CSV file of Layers and their Colors. But I don't see it setting colors.
                        [Any further comments on the above plugin, I'll post in that topic.]

                        EDIT [ Maybe I missed the plugin you were refering to? ]
                        Nevermind.. I found it, it is a [Code] not a [Plugin].
                        It's here: [Code] layer-color= v1.2

                        Jim's new indexes are great!!

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          Dan Rathbun
                          last edited by 21 Jun 2010, 10:53

                          Woops! Messed up the url... updated my previous post.

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • C Offline
                            c.plassais
                            last edited by 21 Jun 2010, 11:22

                            ListLayerColors is perfect for me
                            must be an object layer to export the layer color

                            Thx TIG

                            Is it possible to use it in my plugin ?

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              TIG Moderator
                              last edited by 21 Jun 2010, 14:47

                              @c.plassais said:

                              ListLayerColors is perfect for me
                              must be an object layer to export the layer color
                              Thx TIG
                              Is it possible to use it in my plugin ?

                              A layer needs to have been used [i.e. have at least one face on it] to export as an OBJ and thereby get the color listed, BUT you could simply make a grouped triangular face and give that face a layer - iterate through the model.layers adding the grouped faces until all layers are all done, then run your version of the tool and you have ALL layer colors including unused ones listed in the csv...
                              You can keep a tally of the temporary face-groups as you make them and then erase them as the OBJ export completes...
                              Feel free to use my code as you like: a brief mention of my original code/ideas would be kind; if you are to use it commercially then a small donation would be even kinder [if so, PM me about that]... πŸ€“

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                c.plassais
                                last edited by 21 Jun 2010, 15:25

                                TIG,
                                I understand the tip to export all layers
                                My plugin is not commercial, freeware only on SCF and my French forum
                                A thousand times thank you πŸ‘

                                1 Reply Last reply Reply Quote 0
                                • C Offline
                                  c.plassais
                                  last edited by 22 Jun 2010, 18:33

                                  Hy,
                                  TIG plugin ListLayerColors after some modifications, can create new colors in the pallet with layer's colors

                                  require 'sketchup.rb'
                                  ###
                                  class CreateLayerColors
                                  def CreateLayerColors ;;get()
                                    model=Sketchup.active_model
                                    entities = model.active_entities    
                                    materials=model.materials
                                    layers=model.layers
                                    
                                    if model.rendering_options["DisplayColorByLayer"]==false
                                      model.rendering_options["DisplayColorByLayer"]=true
                                  	already_on=false
                                    else
                                      already_on=true
                                    end#if
                                    # create temporary entities for exporting layers
                                    vecteur = Geom;;Vector3d.new 0,0,1
                                    centre = Geom;;Point3d.new 0,0,0
                                    group_temp=entities.add_group()
                                    entities = group_temp.entities
                                    x =0
                                    layers.each {|layer|
                                    model.active_layer = layer
                                    centre = [centre[0], centre[1], centre[2] + x]
                                    edges = entities.add_circle centre, vecteur, 0.01
                                    cercle = entities.add_face(edges)
                                    x= x + 0.01
                                    }
                                     
                                    model.save "temp"
                                    mpath = Sketchup.find_support_file "temp", "Plugins/"
                                    model.export(mpath +".obj",false)
                                    mtl=mpath+".mtl"
                                    text=IO.readlines(mtl)
                                   0.upto(text.length-1) do |i|
                                    if text[i]=~/^newmtl */
                                      name=text[i].slice(7..-2)### layer name only
                                      rgbR=((text[i+2].slice(3..11).to_f)*255).to_i.to_s### color rgb values	
                                      rgbG=((text[i+2].slice(12..20).to_f)*255).to_i.to_s### color rgb values	
                                      rgbB=((text[i+2].slice(21..29).to_f)*255).to_i.to_s### color rgb values
                                      
                                    	couleur_calque = Sketchup;;Color.new(rgbR.to_i, rgbG.to_i, rgbB.to_i)
                                          unless materials[name]
                                  	    new_matiere = materials.add name
                                  	    new_matiere.color = couleur_calque
                                  	    new_matiere = new_matiere.name
                                  	else
                                  	    materials[name].color = couleur_calque
                                  	end
                                    end#if
                                   end#upto
                                  
                                    File.delete(mpath+".obj")
                                    File.delete(mtl)
                                    File.delete(mpath)
                                    group_temp.erase!
                                    ###
                                    model.rendering_options["DisplayColorByLayer"]=false if already_on==false
                                    ###
                                  end#def
                                  end#class
                                  ### menu
                                  # add menu items
                                  if(not file_loaded?("CreateLayerColors.rb"))
                                    UI.menu("Plugins").add_item("Create Layer Colors"){CreateLayerColors;;get}
                                  end#if
                                  file_loaded("CreateLayerColors.rb")
                                  ###
                                  

                                  CreateColorLayer

                                  Christophe

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  1 / 1
                                  • First post
                                    1/16
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement