Retrieve Color Layer assigned by Sketchup
-
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 -
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 layerProbably the best solution is with the API SDK C + +, as indicated Thomthom.
I found in SDK, this methodOLE_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
-
@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 itlayer.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 anotherlayer.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 -
Thank you Dan
For your help and your time
even a csv list of color layers, it's good for me
-
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 -
This is the 'layer color' csv listing tool http://forums.sketchucation.com/viewtopic.php?p=11924#p11924
It needs Pro though... -
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.2Jim's new indexes are great!!
-
Woops! Messed up the url... updated my previous post.
-
ListLayerColors is perfect for me
must be an object layer to export the layer colorThx TIG
Is it possible to use it in my plugin ?
-
@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,
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 -
Hy,
TIG plugin ListLayerColors after some modifications, can create new colors in the pallet with layer's colorsrequire '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") ###
Christophe
Advertisement