Created
August 25, 2012 13:09
-
-
Save cmur2/3465426 to your computer and use it in GitHub Desktop.
Sketchup MaterialRenamer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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