From: Wilson Bilkovich Date: 2005-12-31T01:29:05+09:00 Subject: Re: Directory and file listing On 12/30/05, adam beazley wrote: > Nevermind, > I figured it out and the script works and it does exactly what I wanted > it to do. Thank you so much everyone, I appreciate the support on this > one. Here is the final code: > > > #----------------------------------------------------------------------------- > > require 'sketchup.rb' > > #----------------------------------------------------------------------------- > > > def materialimporter > > prompt = ["Directory Location"] > value = [] > results = inputbox prompt, value, "Directory" > if (!results) > #failure > return > else > #success: you can extract values from the results array > end > > directory = results.to_s > Dir.chdir directory > images=Dir["*.*"] > [images].to_s > > maxnum = images.length > img_num = 0 > model = Sketchup.active_model > materials = model.materials > > until img_num > maxnum > > m = materials.add images[img_num] > m.texture=images[img_num] > img_num += 1 > end > end > > > > > > if( not file_loaded?("massmaterialimporter.rb") ) > > # This will add a separator to the menu, but only once > add_separator_to_menu("Plugins") > > plugins_menu = UI.menu("Plugins") > > plugins_menu.add_item("Import Materials") { materialimporter } > > end > > #----------------------------------------------------------------------------- > file_loaded("massmaterialimporter.rb") > > > > > So i only have one last question: > I would like it if the name of the material could be brushedsteel > instead of brushedsteel.jpg so how do I take off the file extension? > filename = 'example.jpg' name = File.basename(filename, '*.*') # name now has the value 'example' I'd also like to suggest that you read my last post more carefully.. You're jumping through some unnecessary hoops with the 'images.to_s', and img_num things. 'each' does everything you need, all by itself.