Thanks Dan for the pointer to UI.openpanel, that all works fine.
Not sure if it is because I need to learn about chunking my array, but my routine stops every time after processing 33 or 34 files (it is always after 33 or 34 files) and then SU8 crashes. Given that such a small number of files are processed before the hang/crash, I am not sure the array size is the problem? When the script stops running, I am left with the last loaded component in the component list. If I try and and check its 'Face-Me' status, SU crashes.
def setcompfm
model = Sketchup.active_model
# set folder and get array of filenames
folder = UI.openpanel("Choose a skp file to set folder","*.skp")
if folder && folder = File.dirname(folder)
skpFiles = Dir[File.join(folder, "*.skp")]
end
length = skpFiles.length
result = UI.messagebox "Process " + length.to_s + " files?", MB_YESNO
if result == 6 # Yes
# Returns a DefinitionList
definitions = model.definitions
# iterate through files
begin
skpFiles.each do |compFile|
compDefinition = definitions.load compFile
behavior = compDefinition.behavior
behavior.always_face_camera = true
behavior.shadows_face_sun = true
compDefinition.save_as compFile
definitions.purge_unused
end #end do
rescue
puts compFile
end #end begin
end #end if
end #end def