Plugin name and menu text
PLUGIN_NAME = 'Rename Materials by File Name'.freeze
Plugin class
class RenameMaterials
def self.rename
# Get the active model
model = Sketchup.active_model
# Get the file name and remove the extension
file_name = File.basename(model.path, ".*")
# Get all materials in the model
materials = model.materials
# Iterate through all materials and assign new names based on the file name
materials.each_with_index do |material, index|
new_name = "#{file_name}_#{format('%02d', index + 1)}"
material.name = new_name
end
puts "Materials have been successfully renamed based on the file name."
end
end
Menu item that activates the plugin
UI.menu('Plugins').add_item(PLUGIN_NAME) { RenameMaterials.rename }