SketchUcation Plugin Store

 

 

[plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby alexschreyer » Fri Feb 05, 2010 4:26 pm

Thanks, Dan, for going through this so thoroughly. Everyone, please feel free to suggest code improvements. I would like to make this as useful as possible. Of course, I'll mention every help on the "About" tab.

@Dan: I'll incorporate your revisions into the output code. That is really the part here that I had looked at the least.

I like the idea of having tabbed multiple files. With the current tab support that should be relatively easy to implement.

And thanks for the hint on the Windows UI look for IE. I didn't even know about the tag.

Cheers,
Alex
Author of "Architectural Design with SketchUp":
http://sketchupfordesign.com/
User avatar
alexschreyer
 
Posts: 137
Joined: Mon Jan 28, 2008 6:58 am
Location: Amherst, MA, USA
Name: Alexander Schreyer
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] WebConsoleEX - abort operation

Postby Dan Rathbun » Fri Feb 05, 2010 6:16 pm

I think I see another problem. If an error occurs don't you need to abort the operation instead of committing it?

Try something like this:
Code: Select all
  add_action_callback("exec") do |webconsole_dialog, p|
    v = webconsole_dialog.get_element_value('console').strip
    # puts v    # what's this for -- testing ??
    r = nil
    begin
      Sketchup.active_model.start_operation "RubyEditor"
      begin # evaluation
        r = eval v
      rescue => e
        r = e
        raise # pass to outer rescue clause
      end # eval
    rescue
      Sketchup.active_model.abort_operation
    else # only do if NO errors
      Sketchup.active_model.commit_operation
    ensure # always do this
      r!=nil ? r = r.to_s : r='nil'
      p r
      r.gsub!(/ /, " ")
      r.gsub!(/\n/, "<br>")
      r.gsub!(/'/, "&rsquo;")
      r.gsub!(/`/, "&lsquo;")
      r.gsub!(/</, "&lt;")
      webconsole_dialog.execute_script("document.getElementById('results').innerHTML='#{r}'")
    end
  end # callback
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] WebConsoleEX - default key

Postby Dan Rathbun » Fri Feb 05, 2010 6:30 pm

Alex.. you did not change the Name of the DefaultSettings Key ('WebCon'), so your plugin is overwriting the values for Jim's standard WebConsole in the registry.

There is always the possibilty that some people may still wish to use Jim's "plain Jane" version from time to time, even with yours installed.

You should setup a unique Keyname for your defaults.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby alexschreyer » Fri Feb 05, 2010 7:45 pm

I'll change the dialog name. Must have overlooked that one. I changed the class name.

In the meantime, I figured out how to get linebreaks from a file into a dialog.

Code: Select all
filename = UI.openpanel
f = File.new(filename,"r")
text = f.readlines.join.gsub!(/\n/, '<KghBr31sD>')

ndlg = UI::WebDialog.new("Ruby Web Console", true, "WebCon123", 600, 400, 100, 100, true)
ndlg.set_html ("<html><head></head><body><textarea style='width:100%;height:100%' name='mybox' id='mybox'></textarea></body></html>")
ndlg.show {
  ndlg.execute_script("var text = '#{text}';var asddsa = text.replace(/<KghBr31sD>/g,String.fromCharCode(13));document.getElementById('mybox').value = asddsa")
}


I think I saw the method (i.e. using a gibberish tag) discussed recently in the developers forum. I'll give that a try soon.

Cheers,
Alex
Author of "Architectural Design with SketchUp":
http://sketchupfordesign.com/
User avatar
alexschreyer
 
Posts: 137
Joined: Mon Jan 28, 2008 6:58 am
Location: Amherst, MA, USA
Name: Alexander Schreyer
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby chrisglasier » Sat Feb 06, 2010 2:41 am

alexschreyer wrote:
@chrisglasier: ... It can very well work with my editor.


It is not your editor it belongs to Jim; what you did, as I did, was to dress it up. But I don't want to focus on individual efforts but more on why the cognoscenti allow software companies to fob us off with metaphors for paperwork rather than providing digital machines.

Take for example your original cheat sheets and my/Jim's Sketchup API digital device which provided an opportunity to link up many other devices like the console. The style is not an issue and you are more adept at implementing the links than an amateur and reluctant coder like me; the code is freely available here.

I am very disappointed that you ignored this opportunity to exploit a way to link up data (that belongs to objects that have names) and digital devices (that can automate common tasks).
User avatar
chrisglasier
 
Posts: 1014
Joined: Tue Jun 03, 2008 9:11 am
Location: Hong Kong/Zhuhai
Name: Chris Glasier
Operating system: Windows
SketchUp version: 8
License type: Free
SketchUp use: other
Level of SketchUp: Intermediate

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby alexschreyer » Sat Feb 06, 2010 4:38 am

@chrisglasier: I see now where you are coming from. My idea with my revision of Jim's Web Console was to make it more functional and spruce up the visuals but keep it easy enough for the beginning coder. I'll look again at your approach with the namesets but it seemed to me at the time to complicate things. I guess I just don't fully understand it yet.

I am all for collaboration and combining efforts, though.

Cheers,
Alex
Author of "Architectural Design with SketchUp":
http://sketchupfordesign.com/
User avatar
alexschreyer
 
Posts: 137
Joined: Mon Jan 28, 2008 6:58 am
Location: Amherst, MA, USA
Name: Alexander Schreyer
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: buttons

Postby Dan Rathbun » Tue Feb 09, 2010 2:03 pm

Just a note on personal preference.

If you use the META tag I gave you previously, the buttons (New, Open, Save, Quit) take on the look of the nice XP style buttons (rounded corners & which hilite on hover, etc.) They look just as they do in native dialogs.

The jQuery buttons you have used take up more space (especilally height-wise) and have the look of the old MS Frontpage styling, which I have always hated.

I prefer the native XP look.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby alexschreyer » Tue Feb 09, 2010 3:34 pm

@Dan: You are right, going with the OS styling also makes sense to keep elements looking "native" on Win and Mac.

I wanted to go with the jQuery UI framework, though, so that a) the dialog looks exactly the same on Win and Mac and b) later I could offer different styling to users, so that they can pick their preference from a dropdown. The UI system has various nice templates:

http://jqueryui.com/themeroller/

One question: I have to save some preferences (like the UI selection) locally. Can I reliably use cookies or should I go with an ini file?

Cheers,
Alex
Author of "Architectural Design with SketchUp":
http://sketchupfordesign.com/
User avatar
alexschreyer
 
Posts: 137
Joined: Mon Jan 28, 2008 6:58 am
Location: Amherst, MA, USA
Name: Alexander Schreyer
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby thomthom » Tue Feb 09, 2010 3:41 pm

Cookies can be purged by the user or utilities that clean the browser data. Safest is to store it separately.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: WebConsole Preferences

Postby Dan Rathbun » Wed Feb 10, 2010 12:46 am

thomthom wrote:Cookies can be purged by the user or utilities that clean the browser data. Safest is to store it separately.

Agreed.

You can use Sketchup.write_default and Sketchup.read_default to save settings in the Registry (Win32) or plist files (Mac) but they have a few disadvantages.

Once you create a key, you cannot remove it, so they can become cluttered with old setting keys that are not used anymore.

And they can be only 1 level of heirarchy, even though the Windows Registry supports any numbers of levels. (It's a tree structered database.) Perhaps this is a limitation of the Mac plists and Google is enforcing it on both platforms for 'sameness'?

Also.. XP Home has a Registry limit size (I'm constantly on the edge of it and often get the Registry Limit reached Warnings. If I'd known about it I would have paid the extra and bought XP Pro.)

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. Did you know that Module and Class definitions can be split up into multiple files? They can. The main file can be the functional part of the class definition, and the other can be just a Hash declaration inside the same class 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.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: WebConsole Preferences

Postby thomthom » Wed Feb 10, 2010 8:31 am

Dan Rathbun wrote:Also.. XP Home has a Registry limit size (I'm constantly on the edge of it and often get the Registry Limit reached Warnings. If I'd known about it I would have paid the extra and bought XP Pro.)

Never knew that.
...how much stuff you got installed? I've installed lots of random stuff on my old xp box through up the years - never had that warning.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Registry Limit

Postby Dan Rathbun » Wed Feb 10, 2010 11:41 pm

thomthom wrote:
Dan Rathbun wrote:Also.. XP Home has a Registry limit size (I'm constantly on the edge of it and often get the Registry Limit reached Warnings. If I'd known about it I would have paid the extra and bought XP Pro.)

Never knew that.
...how much stuff you got installed? I've installed lots of random stuff on my old xp box through up the years - never had that warning.

TOO much stuff! OpenOffice Suite, AutoCAD, Epson Scanner Software, Windows SDK, MS VisualStudio (w/ VB, C#, C++, SQL Server), Debugging Tools for Windows, Windows Support Tools, PowerToys for Windows XP, MS HTML Help Workshop, PCB123, AdobeReader, Paint.NET, NotePad++, SciTE, FamilyOrigins (Genealogy dBase), Google Sketchup 7.x, Google Earth. ..etc...
(And at one time 2 full versions of MS Flight Simulator; which I uninstalled.)

I believe I didn't get the errors until after I installed AutoCAD. I can't find the exact error message at a MS search, but did find an article dated 2007 that says the RSL (Registry Size Limit) "no longer applies" to Windows XP or Windows Server 2003. But I know I have got the error popup after that.

@Alex: Thinking more about this. You don't need need to worry at all regarding this issue. The RSL applies only (if it even does anymore,) to the System Hive of the Registry. Sketchup settings are saved in the User Hive, which does not have (or never had) any size limit.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: WebConsole Preferences

Postby Dan Rathbun » Wed Feb 10, 2010 11:50 pm

Dan Rathbun wrote: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.)
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby alexschreyer » Thu Feb 11, 2010 5:26 am

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
Author of "Architectural Design with SketchUp":
http://sketchupfordesign.com/
User avatar
alexschreyer
 
Posts: 137
Joined: Mon Jan 28, 2008 6:58 am
Location: Amherst, MA, USA
Name: Alexander Schreyer
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby driven » Sat Feb 13, 2010 9:16 pm

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
driven
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

[code] Access a PDF in your default Browser

Postby Dan Rathbun » Sun Feb 14, 2010 7:42 am

driven wrote:Is it possible, or could I put it on my website and read it from there (less preferable as the books not published yet)?

I think it would be better to open the PDF file using the Adobe Reader browser plugin running in a normal instance of Safari (in your case.)

How to Access a PDF in your default Browser
Safari on Mac | MS Internet Explorer on PC

Copy the code below save it to a file name 'helpmenu.rb' and put it in your plugins directory.
Code: Select all
# helpmenu.rb for PLAT=Mac & OS=OSX
# Public Domain
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('Your TextBook Title') {
      UI.openURL("file://localhost#{ENV['HOME']}/ruby/help/textbook.pdf")
    }
    #   #{ENV['HOME']} inside a double-quoted string
    #   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
Revised: Added 'file://localhost' to openURL argument.(see posts below.)
Last edited by Dan Rathbun on Wed Jul 07, 2010 5:00 am, edited 3 times in total.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby driven » Sun Feb 14, 2010 2:57 pm

@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




Code: Select all
#
#  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


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
Code: Select all
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??
driven
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby driven » Sun Feb 14, 2010 5:38 pm

GOT IT....
Code: Select all
#
#  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

KirillYouTube.rb
Please, register (free) to access all the attachments on the forums.
driven
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby Dan Rathbun » Sun Feb 14, 2010 8:34 pm

driven wrote:@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.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby driven » Sun Feb 14, 2010 9:10 pm

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
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby Dan Rathbun » Mon Feb 15, 2010 1:16 pm

driven wrote: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')
__OPTIONS['MacShowModal'] ? show_modal() : show()
else # it's a PC
__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.)
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby thomthom » Mon Feb 15, 2010 1:23 pm

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.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby Dan Rathbun » Mon Feb 15, 2010 1:34 pm

driven wrote: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.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby Dan Rathbun » Mon Feb 15, 2010 1:35 pm

thomthom wrote: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.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby Dan Rathbun » Mon Feb 15, 2010 1:45 pm

Dan Rathbun wrote: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.
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby driven » Mon Feb 15, 2010 2:00 pm

[quote="Dan Rathbun" He knows, we know. That's really what he wants... it to stay on top.[/quote]

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??
Code: Select all
#
#  _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
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby thomthom » Mon Feb 15, 2010 2:33 pm

driven wrote:Exactly, the Mac 'flaw' is the best feature

? It's terrible. Makes it impossible to make replacements for UI.inputbox.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby driven » Mon Feb 15, 2010 2:56 pm

thomthom wrote: ? 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.
driven
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby thomthom » Mon Feb 15, 2010 3:08 pm

Yea - it'd odd that show on PC keeps the window ontop of SU, while on OSX it doesn't. So much for consistency. :roll:

??? == osx.show()
pc.show() == osx.show_modal()
pc.show_modal() == ???


Oh the sanity of being a SketchUp scripter!
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [plugin] Ruby Code Editor as an extended WebConsole

Postby driven » Mon Feb 15, 2010 3:23 pm

thomthom wrote: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?
driven
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Need SketchUp Books, Models, Styles or Textures? Check out our One Stop Shop for SketchUp.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012

Next


 

Return to Plugins

Who is online

Users browsing this forum: elmer, krostah, massimo, musliadiadnan, Sketchunesia and 7 guests