From: adam beazley Date: 2005-12-30T05:53:12+09:00 Subject: Re: Directory and file listing Ok i think you lost me im still very new to ruby and programming in general. I have some experience with C lang but not extensive. So as of now this is where I am at with this program. this first snippet is working: #----------------------------------------------------------------------------- require 'sketchup.rb' #----------------------------------------------------------------------------- def getfilenames prompts = ["Directory Location"] values = [] results = inputbox prompts, values, "dir" if (!results) #failure return else #success: you can extract values from the results array end directory = results.to_s Dir.chdir directory #Dir.chdir "C:\Program Files\@Last Software\SketchUp 5\Materials" images=Dir["*.jpg"] #at this point the script is working #the current directory is set to what the user imput! #also the "images" array has all of the .jpg files inside it. #------------------------------------------------------------------------------- --So thats all working fine and dandy, the images array has all of the names of the jpg files in it and i can make them print one per line. However the images.each do |img| is not working I get a syntax error so im not sure why thats not working. Now im trying to think about how to make this more object oriented because the way this program will have to work. Basically I need the file names of the images to be in some sort of order. The way it works in sketchup is that I have to first create a "material" and name this material so that it is added to the "in-use" browser. Then I add the jpg texture to the already named material with the correct jpg. So im trying to figure out how to do this with ruby, so that the material is named the same as the texture without the .jpg suffix. Im guessing this can be achieved with a while loop and maybe sorting the "images array(alphabetically or by incrimenting the ? what do you think? Here is the correct script for adding a material, then naming it and then adding a texture to it: ------------------------------------------------------------------------- def addMaterial model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Material Name" begin # Returns nil if not successful, path if successful. Should return a texture object m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg" rescue UI.messagebox $!.message end ------------------------------------------------------------------------- So how can I automate this script to loop until every jpg in the directory has been added to the "in-use" material pallet and named the same as its texture file. Thanks for all of the help, I really appreciate it. Adam -- Posted via http://www.ruby-forum.com/.