import multiple files in the same type in sketchup ruby api

1.4k Views Asked by At

I am a beginer with ruby and sketchup.

I need to select and import multiple files at the same time when open a dialog for importing. I used a class, which is inherited from Importer interface of SketchUp . But if i want to import multiple file, it means that i have to open importer dialog many time for doing that. It is inconvenience.

After importing, it is return all the paths of all file i have imported

.

Do you have any idea for implementing that?

Thanks you so much !

1

There are 1 best solutions below

5
On

Unfortunately the Ruby API doesn't implement any API to select multiple files in a file dialog.

Further more, if you use the Importer class you are stuck with the file dialog it displays. It's single select only.

If you know all files in the folder should be read you should let the user pick a single file, then extract the path from that and read all the files from that directory.

If you drop the Importer class you can craft your own alternative. The best would then to create a Ruby C Extension that calls the OS API to display a multi-select dialog.

Alternatively, you can create a WebDialog that display the files and let the user pick multiple files. But that means you'll have to create all the UI from scratch and it'll not lok like the native OS file dialogs. http://www.sketchup.com/intl/en/developer/docs/ourdoc/webdialog.php https://github.com/thomthom/sketchup-webdialogs-the-lost-manual/wiki

If you are making a Windows only plugin you can make use of the drag and drop feature of HTML5. Though this also has drawbacks of requiring the user to have a recent IE version. (OSX hides the WebDialogs when SU isn't active - so you cannot use it as a drop target when you drag files from Finder.) I made a proof of concept a while back: https://github.com/thomthom/DropZone