UI openpanel - path issue?
-
The sketchup-ruby-api shows Arguments: title, directory, filename
There is no example of how to change the directory to a user path:
Can UI openpanel be used to point to a path as below ?c:\Program flies (x86)\Goggle\Google SketchUp 8\Plugins\my dir
-
Yes, of course.
BUT you will need to enclose the path as a string in '', OR if you use "" you must escape every \ as \, OR you can use / instead. The \ only works on PC, but both PC and MAC use / OK.
If you have a Plugin with a folder in the same folder - then use
folder=File.join(File.dirname(__FILE__), 'my dir')
and pass 'folder' to the method [for UI.openpanel as the 2nd argument]...
It will find the path to the folder 'my dir' inside the Plugins folder automatically OR wherever the script is located. -
If you are asking, "Can
UI.openpanelreturn a path?"
yes... by hotwiring it...baseDir = Sketchup.find_support_file('Plugins') relDir = "examples" title = "Choose a Dir..." openpath = File.join(baseDir,relDir) my_path = UI.openpanel( title, openpath, "*." ) if my_path.nil? # the user cancelled the dialog else my_path = File.expand_path( File.dirname(my_path) ) end(Edited for clarity, added openpath local.)
The filetype filter does not work on PC. (Windows itself is overriding the parameters, using MRU settings in the Registry for the File Open dialog.)
Now if you are wondering if you can first set the working dir, and will the UI.openpanel go there?
Not really,.. you must make the call with the wd:Dir.chdir('C;/') my_path = UI.openpanel( "Choose Dir...", Dir.getwd, "*." ) if my_path.nil? # the user cancelled the dialog else my_path = File.expand_path( File.dirname(my_path) ) end
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement