## ## Rename Component Instances - Tool to quickly rename component instances (not definition names) ## ## 1) Select the Rename Component Instances tool from the plugins menu. ## 2) double click on a component instance ## 3) Enter the new instance name ## ## I borrowed heavily from TIGs addvertex+ tool, and from Rick Wilson's repaint script ## ## 5/10/07, daiku Tested only on SU6, PC ## require 'sketchup.rb' def getCursorID(filename, hotx, hoty) cursorPath = Sketchup.find_support_file(filename, "Plugins") if cursorPath id = UI.create_cursor(cursorPath, hotx, hoty) else id=0 end return id end class RenameComponentInstances def initialize @status="Double-click a comp inst to rename." @cursor_id=getCursorID("rci.png",0,0) end def reset @ip=Sketchup::InputPoint.new end def activate self.reset @model=Sketchup.active_model Sketchup.set_status_text(@status) end def onSetCursor() cursor = UI::set_cursor(@cursor_id) end def onLButtonDoubleClick(flags,x,y,view) @model.start_operation("Rename components Instances") ph=@model.active_view.pick_helper ph.do_pick(x,y) picked_element=ph.best_picked @ip.pick(view,x,y) if not @ip.valid? picked_element=nil end if(picked_element) return if not picked_element.instance_of? Sketchup::ComponentInstance ci = picked_element else UI.beep Sketchup.set_status_text(@status) return end model = Sketchup.active_model sel = model.selection sel.clear sel.add(ci) prompts = ["New Instance Name:"] defaults = [ci.name] results = inputbox(prompts, defaults, "Rename Component Instance") return if !results ci.name = results[0] Sketchup.set_status_text(@status) @model.commit_operation end end ### menu is_this_file=File.basename(__FILE__) if not file_loaded?(is_this_file) UI.menu("Plugins").add_item("Rename Component Instances"){Sketchup.active_model.select_tool(RenameComponentInstances.new)} file_loaded(is_this_file) end