import multiple files in the same type in sketchup ruby api - ruby

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 !

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

Related

Alternative to Windows Alternate Data Streams

I have the following need to implement on Windows: file with files.
Originally I was thinking to use directory with extension. Something like "folderA.myappext", so when user clicks on it in Explorer, my app is launched instead of folder being opened. Unfortunately, I was unable to find a way to do that. Then I tried to use Alternate Data Streams. This works just fine, but several problems with it:
It works only in NTFS, so no way to send it via email or FTP as is;
Only WinRAR can properly archive it, and you still have to do extra clicks in the UI for that;
The real file size (with all streams in it) is not shown in Explorer and does not participate in showing free/used space, which can very quickly lead to big problems for the user.
No, I can't use zip or any other way to combine files into one - this is high-performance app that also requires write streaming (i.e. it changes data all the time).
Any idea how else to achieve my need on Windows? I know on MacOS you can use 'package', but there is nothing like that on Windows. Any idea?
Something like "folderA.myappext", so when user clicks on it in Explorer, my app is launched instead of folder being opened.
You can't do it based on the extension because folders don't have extensions but you can do it with desktop.ini. Windows 7 and later supports custom verbs on folders.
A working example can be found here.

How can I associate a file with my app?

I have a Cocoa app "PDFHistory" on Mac OS X that uses the NSDocument architecture to save and load PDF files that are internally formatted specially for my app. I want to make it so whenever I save a file (e.g., "mydoc.pdf") from PDFHistory, then subsequently double-clicking on mydoc.pdf will automatically open it in PDFHistory.app. However, I don't want to make it so all .pdf files are automatically opened in PDFHistory, but rather use the system default (probably Preview.app). The .pdf suffix is a requirement, though, since I need the user to be able to e-mail the files to other users who can view the file in their default PDF viewer.
The problem is that if I set the LSHandlerRank to "Owner", then all .pdf files will be opened with PDFHistory, which is bad (since I only understand the internals of the .pdf file that PDFHistory wrote out). But if I set LSHandlerRank to "Alternate", then all .pdf files will be opened to the system default app (Preview.app), which is confusing for the user who had just created the file using my app.
Once upon a time, "creator codes" could be used to implement this sort of capability, but launch services started ignoring them back in Snow Leopard (see http://tidbits.com/article/10537). UTIs are not a substitute that provide this capability (see http://boredzo.org/blog/archives/2009-09-22/how-not-to-use-utis).
Using Finder to get info on the file allows the user to specify a specific app to use to open the specific file. This supposedly works by setting a "usro" property in a the file's resource. There is some open-source code to mimic this behavior (https://github.com/AlanQuatermain/SetAppAffinity), but is uses deprecated functions, and so would cause Apple to reject the app from the App Store. Similarly, people have posted AppleScript to set this property (https://discussions.apple.com/thread/2597365), but sandboxing would prevent me from invoking it.
Although the .pdf suffix is a requirement in order to be able to send the files to users on other systems/platforms, I considered trying to have the suffix registered with two extensions as ".phistory.pdf", which would allow "file.phistory.pdf" to be opened in PDFHistory, but "file.pdf" would be opened in the default PDF viewer. However, this simply didn't work: it appears that the final suffix is the only one used by launch services, and everything before that is ignored.
So is there any way to have my app be the default app for opening files that it created itself?

File extension icon on Mac

My application uses new proprietary file formats with extensions never been used before. I would like to associate specific icons to display my files in finder with nice iconography. As far as I know LaunchService is responsible to handle all these data, however I'm confused where, when and how shall I create associations.
Which entries I have to add to plist?
Where I need to actually register this extension - during installation? Is there any script for this?
Add a CFBundleDocumentTypes key to your plist, see
Storing Document Types Information in the Application's Property List

How to drive Interface Builder with AppleScript?

I want to programmatically create NIB (or XIB) resource files - like resource import tool. Making XIB file manually is not impossible, it is XML-based file, but there are too many unspecified items.
So, I'd like to use AppleScript to drive IB itself and create the resources with it, but I fail to do so - I can't create any new items and it keeps reporting that it cannot add this object to that container. Does anybody have any experience with that, or some good example that I can use as a starting point?
Thanks.
I don't think Interface Builder is scriptable, but perhaps you could have an script which writes a file with the generic IBFile contents and then just change around some vars.

Replacing the explorer pane in windows?

When a user puts in a CD and autoruns, I want to "browse" the CD but I want to do some extra processing of the disk contents. If I wanted to replace the ListView in windows explorer with one of my own, how would I start? What terms should I search for to find out how to do this. I want to get the treeview part that explorer provides, and all the shell interaction, I just want to hide the extra extension on the end of the file names (.pgp) and show the icons for the files as if they weren't encrypted.
I think your best option is use a Shell Namespace extension like the GMail Drive shell
see this links
An almost complete Namespace Extension Sample
Create Namespace Extensions for Windows Explorer with the .NET Framework
Tips in Writing Namespace Extensions (I) - Implements Subfolder
Tips in Writing Namespace Extensions (II) - Implement Create and Delete Object Operations
Bye.

Resources