# Name : Layer by Material # Description : move faces to layers based on assigned material # Author : Tim Bertschinger # Web: http://www.architimmy.net # Date : 09.Nov.2oo5 # Type : menu item # History: 0.5 (11-09-05) first version # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. require 'sketchup.rb' #----------------------------------------------------------------------------- def lbm_moveFaces(e,total_items) model=Sketchup.active_model defs=model.definitions count = 0 def_count = defs.count tellPctComplete(count,def_count) UI.messagebox("layering faces from " << (def_count.to_s) << " component definitions") defs.each do |d| comp_ent = d.entities lbm_selectFaces(comp_ent) count+=1 tellPctComplete(count,def_count) end count = 0 totalCount = total_items UI.messagebox("layering faces from " << (total_items.to_s) << " remaining faces and top level groups")############# tellPctComplete(count,totalCount) e.each do |ent| lbm_moveFace(ent) count+=1 tellPctComplete(count,totalCount) end end #----------------------------------------------------------------------------- def lbm_moveFace(e) if e.class == Sketchup::Face if e.material e.layer = e.material.name else e.layer = "default" end end if e.class == Sketchup::Group g_ent = e.entities lbm_selectFaces(g_ent) end end #----------------------------------------------------------------------------- def lbm_selectFaces(e) e.each do |ent| if ent.class == Sketchup::Face if ent.material ent.layer = ent.material.name else ent.layer = "default" end end if ent.class == Sketchup::Group g_ent = ent.entities lbm_selectFaces(g_ent) end end end #----------------------------------------------------------------------------- def lbm_material_layers model=Sketchup.active_model mats=model.materials matNames=[] mats.each {|m| matNames.push(m.name)} defaultLayer = model.layers.add("default") matcount = mats.count UI.messagebox("creating " << (matcount.to_s) << " layers for materials")############# model.start_operation "create material layers" matNames.each do |m| alayer = model.layers.add(m) end model.commit_operation end #----------------------------------------------------------------------------- # Copyright 2004, Todd Burch - Burchwood USA http://www.burchwoodusa.com # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # Name : progress bar method # Description : displays the progress (0-100%) in the status bar for a given method # Author : Todd Burch http://www.burchwoodusa.com # Date : 17.Jul.2004 # Type : method #----------------------------------------------------------------------------- # This tellPctComplete method will display a text-based progress bar in the status bar. # # It is passed two values. The first is the iteration count of your loop. The # second value is the magnitude of your loop. # # Nothing is returned to the caller, but the status bar will have been updated. # # Using the default characters, "-" and ">", the line will look similar to the following: # # --------------->---------------- 50% # #----------------------------------------------------------------------------- def tellPctComplete(iteration,total) linechar = "-" # Set default line building character. progresschar = ">" # Set default moving indicator. pct = (iteration*100)/total # Calculate percentage complete. pct = 1 if pct <= 0 # round up to 1% if anything less than 1%. initial_block = linechar * 100 # Default progress bar line sequence. current_block = initial_block[0,pct-1] << progresschar << initial_block[pct,initial_block.length] Sketchup.set_status_text(current_block << " " << (pct.to_s) << "%." << (name)) return end # tellPctComplete #----------------------------------------------------------------------------- def main model=Sketchup.active_model e=model.entities count = 0 total_items = e.count defs=model.definitions Sketchup.set_status_text Sketchup.set_status_text("Layer by Material - Creating Layers") lbm_material_layers Sketchup.set_status_text("Layer by Material - Layers Created - Moving Faces to Layers") UI.messagebox("Layers Created - Click ok to move faces to layers")############# model.start_operation "move faces" lbm_moveFaces(e,total_items) model.commit_operation Sketchup.set_status_text("faces moved - 100% complete") UI.messagebox("Finished")############# end if( not file_loaded?("layerbymaterial.rb") ) add_separator_to_menu("Plugins") UI.menu("Plugins").add_item("Layer by Material") { main } end #----------------------------------------------------------------------------- file_loaded("layerbymaterial.rb")