sketchucation logo sketchucation
    • Login
    1. Home
    2. Dan Rathbun
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update
    Offline
    • Profile
    • Following 0
    • Followers 1
    • Topics 92
    • Posts 4,904
    • Groups 2

    Posts

    Recent Best Controversial
    • RE: New API doc - typos and questions

      Sketchup.load
      http://code.google.com/apis/sketchup/docs/ourdoc/sketchup.html#load

      The Sketchup.load method does NOT expose the wrap argument, so we can specify wrap=true for rbs scripts.

      For some unknown reason, the Google team defeated, or just didn't pass the 2nd argument (wrap) on to the aliased standard load, when they overrode it to handle rbs decrypting.

      Please fix this!
      _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: New API doc - typos and questions

      UI::WebDialog
      http://code.google.com/apis/sketchup/docs/ourdoc/webdialog.html

      Limiting the WebDialog Size and setting :resizable=false still allows MSIE window to have a working Maximize button on the captionbar. Clicking it maximizes the dialog (which should not be so.) The 'Size' option in the SystemMenu dropdown is greyed, as it should be, 'Maximize' in the menu is also active.

      ` opts = Hash.new

      other options set

      opts[:resizable] = false
      dlg=UI::WebDialog.new( opts )
      dlg.min_height = 100
      dlg.max_height = 100
      dlg.min_width = 200
      dlg.max_width = 200
      dlg.set_size(200,100)
      dlg.show`
      _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [Concept] Materials++

      @remus said:

      A colour picker a la the native one would be very helpful.

      I've long wanted a color picker for use with SU Ruby.

      Had planned to see if Chameleon could be setup as a WebDialog to give us a quick and dirty picker. It's a free (BSD license,) totally Js based popup picker.
      http://karmatics.com/chameleon/

      I can get the native color picker to popup thru Sketchup.send_action but can't figure out how to get the return color value. (There is an object for Win32 that can be embedded in webpages for the crappy Win3.0 style picker on MSIE, but noone wants that one, and it's not cross-platform.)

      So me thinks Chameleon might be a fasttrack solution. I wanted to make it a standalone WebDialog that could be called from ANY ruby, or from ANY WebDialog (via a callback to ruby.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Alternate API, Pioneers Wanted

      @martinrinehart said:

      Edit: Got enthused. If I used the Ruby Matrix, matrix multiplication would be done in C, not in Ruby. Yay!
      On further investigation, life's too short to wade through such awful doc. Ugh.

      The RDoc Reference page, at:
      http://www.ruby-doc.org/core/classes/Matrix.html

      or are you refering to the source document?
      %(#000080)[___________________________________________________________________]
      [url=http://www.ruby-doc.org/core/:3e3wceft]Ruby Core RDocs: Main Framed Webpage[/url:3e3wceft]
      _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Alternate API, Pioneers Wanted

      There's a namespace problem.

      If the files are loaded 'as is' your Matrix class will collide with the Standard Ruby Baseclass Matrix (which is far better, more methods etc, than yours.)

      Perhaps wrap it in module Rinehart ? (or some other appropriate name.)
      It's OK to have a Matrix and a Rinehart::Matrix ... they won't collide.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Alternate API, Pioneers Wanted

      rather than use the global variable to make your own conversion to radians, you can use:

      Degrees to Radians
      Numeric.degrees
      http://code.google.com/apis/sketchup/docs/ourdoc/numeric.html#degrees

      Radians to Degrees
      Sketchup.format_angle
      http://code.google.com/apis/sketchup/docs/ourdoc/sketchup.html#format_angle
      or
      Numeric.radians
      http://code.google.com/apis/sketchup/docs/ourdoc/numeric.html#radians

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: WebDialog set_file

      UI::WebDialog.set_file
      BUG found

      Found the problem on PC.
      It's a boo-boo using the File.join method. An extra SEPARATOR is getting inserted at the beginning of the URL string, so that whatever the pathname, whether you use the optional relative path (2nd argument) or not, the resulting URL passed to the browser begins with:
      file:///

      For this test I have Rick Wilson's lil' html help file in the Support folder:
      Rename it to .html and put it in the Sketchup Support folder

      my_dialog=UI;;WebDialog.new('Smustard Organizer Compatibility',true,'test',800,600,100,100,true)
      SUpath=Sketchup.find_support_file('') #empty string needed!
      my_dialog.set_file('Support/Smustard_Organizer.html',SUpath)
      my_dialog.show
      

      On the PC this results in MSIE error dialog stating that 'Internet Explorer cannot find the file:
      "file:///C:/Program Files/Google/Google SketchUp 7/Support/Smustard_Organizer.html"_'
      Trying various combinations of the set_file method: 1 argument, 2 arguments, etc., I have also been able to get 2 types of error webpages, 'Internal Server Error' and the normal useless 'Cannot Open the Webpage error' with the likely reasons ie: No Internet connection, etc.

      LESSON
      UseUI::WebDialog.set_url instead.

      my_dialog=UI;;WebDialog.new('Smustard Organizer Compatibility',true,'test',800,600,100,100,true)
      SUpath=Sketchup.find_support_file('') #empty string needed!
      # Remove leading file separator on Mac (or Win without Drive;) 
      SUpath.slice!(0,1) if SUpath[0,1]==File;;SEPARATOR
      # File.join will put it back in
      my_dialog.set_url( File.join('file;//localhost',SUpath,'Support/Smustard_Organizer.html'))
      my_dialog.show
      

      It is quite likely that .set_file actually just calls .set_url passing the latter improperly concatenated pathname string portions misusing the File.join method. (Obviously the set_file method could be fixed using the slice! technique above.)

      UI.openURL
      The same technique can (and should) be used with UI.openURL so that code is cross-plaform.

      • On Mac, testing has shown that OSX wants 'file://localhost' at the begining of the URL or it can't find the file.* On PC, Windows will adjust the URL, stripping off the 'file://localhost' and passing the rest of the path to whatever application is registered for the file extension. (Not always the browser.)

      WebDialog.new
      Two things to note here.

      Comma Separated Parameter List form: IF the pref_key argument is nil or '' (empty string), the remaining arguments are ignored. (This is why I set the key to 'test' in the examples above.) So if you are attempting to make a WebDialog that does not save settings, and it is not showing at the position and size you want, this may be why.

      Hash as Parameter form: Contrary to what has been said that the dialog_title parameter cannot be set through the hash, it CAN be. However, there is a bug in this new Hash based functionality. In that the Google coder did not take into account that there are several ways of defining a Hash, ie, with Symbol keys or String keys. The coder should have just converted each key using to_s and then made the value assignments based on the keystring, but didn't. So the Hash based form is 'quirky'. You must use Symbolsas keys, NOT Strings:
      hsh=Hash[:dialog_title=>'Title passed by Hash', :scrollable=>false, :preferences_key=>'MyDialog', :width=>800, :height=>600, :left=>100, :top=>100, :resizable=>true]
      AND once again if you omit the :preferences_key value pair, it seems the remaining arguments are ignored.. ie default position is 0,0 and size is 250,250 instead of those specified in the hash.

      Conclusion: Because of the kwappy way the WebDialog API was coded, we must pass ALL parameters or Hash keys (which actually defeats the advantage of the Hash, over a Comma Sep'd Parameter List.)
      _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: WebDialog set_file

      @thomthom said:

      file:/// is a valid URI. http://en.wikipedia.org/wiki/File_URI_scheme#Windows

      Firefox diplay local URIs like that. IE will open such URI and convert it into what you see in Windows Explorer. So odd that it'd be problems with the webdialog then.
      Yes 3 slashes work if I paste it into the addressbar of a normal MSIE browser.
      But for WebDialog, on PC (Win32),
      where path=Sketchup.find_support_file(''):

      my_dialog.set_url('file://localhost/'+path+'/Support/webpage.html')
      Works

      my_dialog.set_url('file:///localhost/'+path+'/Support/webpage.html')
      Error

      my_dialog.set_url('file:////localhost/'+path+'/Support/webpage.html')
      Works

      my_dialog.set_url('file://///localhost/'+path+'/Support/webpage.html')
      Works

      my_dialog.set_url('file://////localhost/'+path+'/Support/webpage.html')
      Works

      my_dialog.set_url('file://localhost//'+path+'/Support/webpage.html')
      Works

      my_dialog.set_url('file:///localhost//'+path+'/Support/webpage.html')
      Error

      my_dialog.set_url('file:////localhost//'+path+'/Support/webpage.html')
      Works

      my_dialog.set_url('file://///localhost//'+path+'/Support/webpage.html')
      Works

      my_dialog.set_url('file://////localhost//'+path+'/Support/webpage.html')
      Works

      Any more than 6 /'s before localhost or 2 following, does not work for WebDialog.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: WebDialog set_file

      @thomthom said:

      ah. .set_file was passed the URI. now I see.

      No I thought .set_file was doing this:

      def set_file(filename, path='') %(#F0F0F0)[__]protocol='file://' %(#F0F0F0)[__]set_url( File.join(protocol,path,filename)) end

      But Ruby's File.join is actually kinda smart. Google may have used their own dumb version that adds extra /s.

      But I'm not sure:

      my_dialog.set_file('C:/scite/WebDialogTips.html','')
      Works

      my_dialog.set_file('C:/scite/WebDialogTips.html')
      Works

      my_dialog.set_file('WebDialogTips.html','C:/scite')
      Error ('Cannot Load Webpage' Error Webpage, but NOT MSIE Error dialog.)

      my_dialog.set_file('WebDialogTips.html','C:/scite/')
      Works

      EDIT NOTE: For this test, I copied file 'WebDialogTips.html' into 'C:/scite/' because the sciTE folder is in my System PATH (not my Ruby $LOAD_PATH.)

      my_dialog.set_file('WebDialogTips.html','')
      and
      my_dialog.set_file('WebDialogTips.html')
      both produce the MSIE Error Dialog, that says:
      "Cannot find 'file:///WebDialogTips.html'. Make sure the path or Internet address is correct."

      So the Win System PATH makes no difference.
      _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

      @driven said:

      don't suppose you know a way of turning off ...
      This needs to be broken off into a new thread. It's far removed from the WebConsole/RubyEditor discussion.
      (and sorry.. John, I don't mess with sound in Sketchup or WebDialogs. My only suggestion would be to embed a media player of some kind in the webpage. Check up on the html OBJECT tag. [EMBED and APPLET are deprecated.])
      http://msdn.microsoft.com/en-us/library/ms535859(VS.85).aspx

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

      @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=10142

      Developer's Forum Sticky Links
      http://forums.sketchucation.com/viewtopic.php?f=180&t=20427

      State of Observers
      http://forums.sketchucation.com/viewtopic.php?f=180&t=20676

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

      @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.

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

      @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.

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

      @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.

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

      @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.)

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

      @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.

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: How to install a Ruby Gem for use in SketchUp

      @driven said:

      EDIT: I was digging around in systems library and came across this, can anyone shine a light on it's meaning and if it may be causing any of the many Mac ruby glitches that rear their heads.

      Notes on building the stand-alone reader.

      That looks like it refers to the C++ files for building the SKP Reader extension for a third-party application. So those 'issues' are C++ issues with the SKP Reader SDK, not Sketchup itself or the SU Ruby API.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: WebDialog set_file

      I think the problem is the API is not right (or explaining things the way they work.)

      Sketchup.find_support_file and Sketchup.find_support_files do not return the same format.

      One return a pathname with the Rubyish forward slash as file separator.
      The other returns a Win32 like pathname with escaped backslashes, ie 'C:\Program Files\Google' etc.

      The example for WebDialog.set_file is showing:
      dialog.set_file "c:\\mypage.html"

      The only other thing I'd recommend is NOT using + to concat pathnames.
      Use the Ruby function File.join whenever possible if forwardslash is to be the file separator.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Tool Needed

      @chris fullmer said:

      Sketchup.select_tool(*toolclassobject*)
      (in 3 different places.)

      Chris of course, meant to say:
      Sketchup.active_model.select_tool(*toolclassobject*)

      I disagree with putting the argument Toolclass.new in the select_tool method without a symbol.

      It can easily lead to newbie's creating multiple instances of the tool (when only 1 is ever needed.) And without a symbol (variable) pointing at the tool, you can't easily access it to call public methods.

      What public methods? Well I do something a bit weird. I define the tool's UI::Command object INSIDE the tool itself, within the initialize method. ( So the block for the command is {Sketchup.active_model.select_tool(self)}.) I then create several public methods, one called cmd that returns the UI::Command object so any of it's methods can be called, such as .menu_text; also an add_to_toolbar( toolbar ) and an add_to_menu( menu ) method, so the tool can be added to any number of menus or toolbars, after the fact, using the proper menutext and toolbar button images. I also have a set of params for the .new call, that includes (optionally) a menu (defaults to "Plugins") and/or toolbar which the tool will add itself to (internally calling the previously mentioned methods.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Tool Needed

      @chris fullmer said:

      The activate method is called everytime the tool is instantiated. So it is a great place to put the first processing of your script - validation, tool process flow, etc.

      Should read:
      "The **initialize** method is called ONCE whenthe tool is instantiated. So it is a great place to put the first processing of your script - validation, tool process flow, etc."

      The **activate** method is called everytime the tool is selected (from the menu or a toolbar button [via the Model.select_tool method.]) This method usually sets the @tool_state variable to it's starting value (often 0,) loads the tool's cursor, and prompts the user to do something on the status bar.

      Other tips on methods:

      You can (like any class,) define whatever private methods you wish, in addition to the predefined callback methods, in order to keep your code readable and easier to debug.

      A reset method often helps keep things clear (some people just call activate internally instead, but I prefer a standalone reset method.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • 1 / 1