Skip to content

Instantly share code, notes, and snippets.

@cmur2
Created August 25, 2012 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmur2/3465426 to your computer and use it in GitHub Desktop.
Save cmur2/3465426 to your computer and use it in GitHub Desktop.
Sketchup MaterialRenamer
# License: 2-clause BSD
require 'sketchup.rb'
class MaterialRenamer
def initialize
am = Sketchup.active_model
sel_faces = am.selection.select { |e| e.typename == 'Face' }
sel_materials = sel_faces.collect { |f| f.material }.uniq
(UI.messagebox 'No face selected, unable to rename!'; return) if sel_materials.size < 1
(UI.messagebox 'Found different materials on the selected faces, unable to rename!'; return) if sel_materials.size > 1
mat = sel_materials.first
old_name = mat.name
input = UI.inputbox ['New name:'], [mat.name], "Rename material #{old_name}"
if input
mat.name = input[0]
UI.messagebox "Renamed material #{old_name} to #{mat.name}"
end
end
end
if not file_loaded?(__FILE__)
cmd = UI::Command.new('Rename Material...') do
MaterialRenamer.new
end
cmd.tooltip = 'Allows renaming the material of the currently selected face'
UI.menu("Plugins").add_item cmd
UI.toolbar("Plugins").add_item cmd
end
file_loaded(__FILE__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment