[Code] Printing color range as grid for preprint checking
-
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... -
Copy+paste this code into a file called
colorswatch.rb
in the Plugins folder.
Restart Skecthup and typeTIG.colorswatch
into the Ruby Console... to make acolorswatch
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...
-
-
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
-
This should be marked with [code] - or better yet - made into a new thread with the .rb file for download.
-
Moved to 'developers' and [code] added...
-
AWESOME!
-
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
-
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 -
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
Advertisement