[plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013
-
@dan rathbun said:
Anyhow.. an ini (or any settings file,) would give you complete freedom.
It doesn't need to be an ini format. It can be simply a ruby script that decalres a Settings Hash wrapped in your plugin namespace. ... that gets loaded by the first (if it exists,) and gets RE-written by the first file, when changes to the settings are made.If Js is more comfy for you, the same technique can be used but in Js. A ruby method can write out a Js script that is a JS object holding settings, or an Array of settings, or global varibales, whatever.
The file just gets loaded with the webpage.. no complex parsing required.
If the user makes settings changes.. you send them to a ruby callback that overwrites the settings .js file.Also if you wish to change CSS dynamically you'll need to assign ID attributes to the stylesheets (whether inline or loaded via LINK tag.)
-
Thanks for the recommendations, guys. I actually went with the easiest version (cookies) for now since I was able to implement this without hassle. I'll look at file storage later.
Didn't know that the registry could actually become too large. I never ran into this problem. And I have several Autodesk products installed (those are huuuge - though mostly by filesize! When will ADSK finally cut down on bloating their own software).
Cheers,
Alex -
Hi,
a possibly naive question from one your target end users,
I'm teaching myself ruby on a mac
I have a very Ruby for SU text book that is in PDF format on my hard-drive, I want to access it through the reference menu on your console, (which does throw up some code errors, but still mostly works)
Is it possible, or could I put it on my website and read it from there (less preferable as the books not published yet)?
john
-
@Dan,
thanks a lot for that, I went round in circles trying to get the pdf file to load using #{ENV['HOME']} but eventually just dragged the file in with out that there and it opens the doc on top of SU, but can I get it to stay on top while I use SU? I want to copy paste bits and bobs straight into ruby console.
john
# # helpmenu.rb # # # Created by Dan Rathbun on 14/02/2010. # Copyright (c) 2010 @SCF. No? rights reserved. # # helpmenu.rb for PLAT=Mac & OS=OSX module SU_User module Menus helpmenu=UI.menu('Help') helpmenu.add_separator # Edit the 'Your TextBook Title' Menu Item Title below # Edit the pathname to your textbook pdf file below helpmenu.add_item('TextBook') { UI.openURL("file;//localhost/Users/johns_iMac/Documents/Learning_rubies/TextBook.pdf") } # #{ENV['HOME']} inside a double-quoted string ##### couldn't get #{ENV['HOME']} to work, but just draging the pdf file into the double quotes works # should return something like; '/Users/John' on the Mac # For PC, the HOME variable must be changed to USERPROFILE end # module Menus end # module SU_User
%(#004000)[So, that just open pdf in preview, but this does what I'm after a modal wd pdf, on a Mac you can work under show_modal
get_dialog = UI;;WebDialog.new get_dialog.show_modal (get_dialog.set_url "file;//localhost/Users/johns_iMac/Documents/Learning_rubies/TextBook.pdf")
what I can't figure is how to get the help item (such a good place to put it) to trigger this??]
-
GOT IT....
# # helpmenu.rb # # # Created by Dan Rathbun on 14/02/2010. # Copyright (c) 2010 @SCF. No? rights reserved. # # helpmenu.rb for PLAT=Mac & OS=OSX module SU_User module Menus helpmenu=UI.menu('Help') helpmenu.add_separator # Edit the 'Your TextBook Title' Menu Item Title below # Edit the pathname to your textbook pdf file below helpmenu.add_item('TextBook') { get_dialog = UI;;WebDialog.new get_dialog.show_modal (get_dialog.set_url "file;//localhost/Users/johns_iMac/Documents/Learning_rubies/TextBook.pdf")} end # module Menus end # module SU_User
Not only does pdf's I can follow Kirill tutorials inside of SU
-
@driven said:
@Dan, thanks a lot for that, I went round in circles trying to get the pdf file to load using #{ENV['HOME']} but eventually just dragged the file in with out that there and it opens the doc on top of SU, but can I get it to stay on top while I use SU? I want to copy paste bits and bobs straight into ruby console.
No problem!
Don't worry about copyright. It's so simple and really just slightly modified version of the code snippet from the API. Assigning a copyright would be like tying to patent the chemical formula H2O.Apparently the UI.openURL argument requires (on the Mac,) the protocol 'file://localhost' before the HOME variable. For a trully generic loadstring (if you were to change your username,) this should work as well (all one line):
UI.openURL("file://localhost#{ENV['HOME']}/Documents/Learning_rubies/TextBook.pdf")
URLs work slightly different on PC and Mac.Anyway... it was a good learning exercise for you.
-
Thanks again Dan,
I'll globalise it, and do you have any objections to me posting this ruby for others, less interested in doing it themselves... I think really handy.
the next thing I've been attempting is to make this RubyCodeEditor to .show_modal.
then I can, read the text, copy paste edit in RCE and see the result in web console, without constantly changing screens.
any ideas where to implement that in nsnSketchupApi.rb
or am I in completely the wrong place EDIT: Yes , it's completely the wrong ruby, I guess that's why that doesn't work, I'm learning a at least now to dig through the right rubies...
john
-
@driven said:
the next thing I've been attempting is to make this RubyCodeEditor to .show_modal.
This is something Alex can do when he gets the User Preferences options part done. He can add an option for Mac users to check a box and then put a conditional statement in the code.
Some thing like:
if RUBY_PLATFORM.include?('darwin') %(#F0F0F0)[__]OPTIONS['MacShowModal'] ? show_modal() : show() else # it's a PC %(#F0F0F0)[__]show() end #if
or you can just change the show to show_modal near he end of the code (for your copy, til Alex gets to releasing his next version.)
-
Except that you can't create modal webdialogs on Mac. A modal form on the Mac only makes it stay on top of SU's window - but not modal.
-
@driven said:
I'll globalise it, and do you have any objections to me posting this ruby for others, less interested in doing it themselves... I think really handy.
Well handy yes, but not all that 'special'. There are numerous plugins around that put help links on the menus. (One by Didier and TBD that will search all folders under Plugins and create links to any help file type, like .pdf, .txt, .chm, .hlp, .htm, etc... automatically.)
There is a problem with your version. You have the new constructor inside the command block without a conditional check to only create a new instance if it has not yet been done. Repeated clicking on the menu would create extra WebDialog objects, wasting space on the stack.
Either move the constructor statement before the 'helpmenu.add_item' line, or add
'get_dialog=false
' before it and change the constructor inside the {} block to:
'get_dialog = UI::WebDialog.new if not get_dialog
'
Probably the 2nd is best, so the WebDialog object doesn't get created unless the menuitem is actually clicked. -
@thomthom said:
Except that you can't create modal webdialogs on Mac. A modal form on the Mac only makes it stay on top of SU's window - but not modal.
He knows, we know. That's really what he wants... it to stay on top.
-
@dan rathbun said:
Apparently the UI.openURL argument requires (on the Mac,) the protocol 'file://localhost' before the HOME variable. For a trully generic loadstring (if you were to change your username,) this should work as well (all one line):
UI.openURL("file://localhost#{ENV['HOME']}/Documents/Learning_rubies/TextBook.pdf")
URLs work slightly different on PC and Mac.FYI: On the PC, Windows ignores 'file://localhost/' and strips it off when it passes the path to whatever application is registered to open the filetype. If it's a .txt it will likely open in Notepad, if a .pdf it will open in Adobe Acrobat Reader, etc.
-
@unknownuser said:
Exactly, the Mac 'flaw' is the best feature
Dan, I got this far last night and I'll have another look, with your new input in mind, but what do think??
# > # _PDF_Viewer.rb > > # seems to only work with adobe pdf format, but that's what safari saves pdfs to, so if it won't open, re-save from safari > # seems to open most image files at full size so you may want smaller copies, export to mail and post to self is cheap and easy, > # batch conversion, or graphics convertor. > > # helpmenue.rb Created by Dan Rathbun on 14/02/2010. > # 2010 @SCF. No? rights reserved. > > # modified for modal Mac usage by john@drivenupthewall.co.uk > # show_modal works differently on PC's > # user selected pdf + image veiwer > # for PLAT=Mac & OS=OSX > > module SU_User > module Menus > > require "sketchup.rb" > # Check to see if the plugin is already loaded > if not file_loaded? "_PDF_Viewer.rb" > > > > > # where to look for it > helpmenu=UI.menu('Help') > helpmenu.add_separator > > # it's name in the Help menu > > helpmenu.add_item('PDF_Viewer') { > file = UI.openpanel; > get_dialog = UI;;WebDialog.new; > get_dialog.show_modal; > get_dialog.set_url(file) > } > > > end > end > > > file_loaded "_PDF_Viewer" > end
If I move get_dialog.set_url(file) to the top will that allow multi-windows? I do get new file, iff I shut the first window
chee
Exactly, the Mac 'flaw' is the best feature
Dan, I got this far last night and I'll have another look, with your new input in mind, but what do think??
# # _PDF_Viewer.rb # seems to only work with adobe pdf format, but that's what safari saves pdfs to, so if it won't open, re-save from safari # seems to open most image files at full size so you may want smaller copies, export to mail and post to self is cheap and easy, # batch conversion, or graphics convertor. # helpmenue.rb Created by Dan Rathbun on 14/02/2010. # 2010 @SCF. No? rights reserved. # modified for modal Mac usage by john@drivenupthewall.co.uk # show_modal works differently on PC's # user selected pdf + image veiwer # for PLAT=Mac & OS=OSX module SU_User module Menus require "sketchup.rb" # Check to see if the plugin is already loaded if not file_loaded? "_PDF_Viewer.rb" # where to look for it helpmenu=UI.menu('Help') helpmenu.add_separator # it's name in the Help menu helpmenu.add_item('PDF_Viewer') { file = UI.openpanel; get_dialog = UI;;WebDialog.new; get_dialog.show_modal; get_dialog.set_url(file) } end end file_loaded "_PDF_Viewer" end
If I move get_dialog.set_url(file) to the top will that allow multi-windows? I do get new file, iff I shut the first window
cheers
john -
@driven said:
Exactly, the Mac 'flaw' is the best feature
? It's terrible. Makes it impossible to make replacements for UI.inputbox.
-
@thomthom said:
? It's terrible. Makes it impossible to make replacements for UI.inputbox.
I'll more than likely agree if/when I get to that stage in coding, but being able to simply float the 'TextBook' over SU has already increased my workflow, so for now I see it as a blessing which I may curse later on...
BTW: I found the your 'missing manual' page helpful, but only found it through google after I almost last-night.
-
Yea - it'd odd that show on PC keeps the window ontop of SU, while on OSX it doesn't. So much for consistency.
??? == osx.show() pc.show() == osx.show_modal() pc.show_modal() == ???
Oh the sanity of being a SketchUp scripter!
-
@thomthom said:
Yea - it'd odd that show on PC keeps the window ontop of SU, while on OSX it doesn't.
on the PC, if you are watching a tutorial in a wd viewer, can you pause to draw and still see the video, or does it jump to the back,under SU, where you have to go find it to carry on?
-
Webdialogs on PC created using
.show()
is always parent to the SU window and will stay on top. Like SU's toolwindows. -
@driven said:
BTW: I found the your 'missing manual' page helpful, but only found it through google after I almost last-night.
Check out these links (bookmark them!):
Sketchup Ruby resources
http://forums.sketchucation.com/viewtopic.php?f=180&t=10142Developer's Forum Sticky Links
http://forums.sketchucation.com/viewtopic.php?f=180&t=20427State of Observers
http://forums.sketchucation.com/viewtopic.php?f=180&t=20676 -
cheers for those Dan, it is a bit hard to navigate this forum, when your not quite sure what your looking for...
don't suppose you know a way of turning off
UI.play_sound(Sketchup.get_resource_path("video/fera.mp3")) #in sync with when "stop" UI.stop_timer @timer1;"video/fera.mp3"
I know this dosen't work but I can't find any method of having the sound pause or stop when I turn off the video texture, which I can turn on and of at will.
I could change a new page and switch to another .mp3 (blank), but as an exercise I'm trying to avoid that as instead off pause, continue, need to start over to keep in sync...
john
Advertisement