1

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 !
Beginner
  • 59
  • 2
  • 10

1 Answers1

2

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

thomthom
  • 2,854
  • 1
  • 23
  • 53
  • ya, i will try creating a ruby C Extension that calls the OS API to display multi-select dialog. I found the way to create a ruby C Extension. But i don't know which OS API to display multi-select dialog. Depend on the OS (Window or MAC) I think this OS API of each OS is different from the other. Do you have any example or link for demonstrating how to customize Sketchup UI Element behaviour by developing Ruby C extension ( I have no exprience about API C programming) Thanks for you help – Beginner Jan 10 '14 at 07:56
  • Afraid that I don't have anything that specific. We are working on Visual Studio and Xcode examples of setting up Ruby C Extensions for SketchUp using C++. Eventually those can probably be expanded, but that doesn't help you right now. – thomthom Jan 10 '14 at 15:27
  • I have updated one more question. Can you answer them for me ? Hope you help me! – Beginner Jan 10 '14 at 15:36
  • It's probably better you create a separate question for that. Keep thing orderly. Otherwise the mods might close it. – thomthom Jan 10 '14 at 15:59
  • Thanks, i will add seperate question. – Beginner Jan 10 '14 at 16:20