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: Determine Whether a Point is 'in' a Volume

      @remus said:

      The original idea was to check lots of points in the bounding box of the object and see what proportion of them are in the volume, then take that proportion of the volume.

      IF the object is box-like, it would be very easy.

      pt=[1,2,3] bb=obj.bounds in_volume=bb.contains?(pt)

      Unfortunately, not all volumes can be box-like and aligned with the x,y,z axes.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [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.)

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

      @thomthom said:

      @dan rathbun said:

      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.

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: [Bug]Win32api.so and Sketchup7

      @cjthompson said:

      Do you know which version of Ruby you took the Win32api from?

      Just as a head's up, so you'll know... Win32API.so is not distributed with Ruby 1.9.x and up. It is replaced by Win32API.rb, which is a translator script, that 'fools' old calls to the Win32API.so, by translating those calls into DL library calls.
      It is supposed to work transparently, because most uses would load the so by simply:
      require 'Win32API'
      The require method looks for .rbfiles first, so it would load the new translator, instead of the .so, ... in a normal ruby install.

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

      @thomthom said:

      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.

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: SketchUp RUBY API Wishlist [way of coding wishes, please]

      Sketchup::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: Ruby namespace?

      @jim said:

      @jessejames said:

      I noticed when i do obj.methods, and obj.private_methods, there is a lot of pollution in there. Names that obviously don't belong to that obj.

      I wouldn't call it pollution. You're seeing all the methods that the object has. Some of them are inherited, some are class methods, others are instance methods. I suspect what you expected to see were only the instance methods of a class.

      This is VERY important! For understanding Ruby,... but more so.. how the Sketchup Ruby API (and standard Pure-Ruby extensions (such as 'sketchup.rb' [as the best example,]) can be incorrectly implemented.

      Ruby scripts... (if you don't tell them specifically what namespace to run in,) will run in (the global constant namespace,) TOPLEVEL_BINDING. (A Binding class object, is 'sort-of' an execution directive to a namespace.)

      (1) TOPLEVEL_BINDING is preset to Object (uppercase.)

      (2) Everything in Ruby is an object (lowercase,) meaning it is either an Object class, or a subclass (at some level of descendancy,) of Object class. [You may think of the lowercase word 'class' as 'type' if you come from a language where 'type' is more understandable. But recent revisions to Ruby are attempting to remove the word 'type' in favor of 'class.' Keep in mind that there is in Ruby a class Class, which is subclass of class Module, which is subclass of class Object.]

      (3) The Sketchup Ruby Console operates in TOPLEVEL_BINDING. (Open the console and type: self <ENTERkey> , what do you see?

      (4) Any script loaded runs in TOPLEVEL_BINDING.

      (5) This means that most objects defined in TOPLEVEL_BINDING are in fact then defined WITHIN class Object. So if you define a method (without wrapping it with a Class or Module namespace, it is defined as a method of class Object. (Take a look at the 'sketchup.rb' script in the Tools folder and note the names of the methods defined there.)

      (6) As every object in Ruby is a subclass of Object, every object will inherit (in some way,) those objects defined within class Object, including methods, constants, etc. IF you have incorrectly defined them there.

      (7) The methods within the 'sketchup.rb' script were intended (for the most part,) to extend developer's use of the classes Module and Class. BUT they were not wrapped within the proper namespace(s) in the script, and so get defined as methods of Object, and so become inherited by ALL classes, such as the Numeric classes, the Sketchup::Entity subclasses, the Geom::subclasses, etc. where they will NEVER be used.
      Open a new model, draw something simple a cube, select a Sketchup::Face object. Switch to the console, type (all 1 command):
      **Sketchup.active_model.selection[0].private_methods(true).sort.join("\n")**
      Look at the list, you will see that the Face object has inherited as private methods (which you will never call from outside the object,) all those methods defined in 'sketchup.rb'!
      What kind of drain of memory will this have when you get to a model that has tens of thousands of Entities it it?

      "How do you fix this?"
      (a) ANSWER: 'sketchup.rb' MUST DIE! The methods within NEED to be moved (defined as an extension,) to the proper %(#BF0000)Module where they should have been added in the first place:

      to module Sketchup:

      • file_loaded* file_loaded?* require_allto module UI:

      • add_separator_to_menu* inputbox (really a patch that needs to be made part of UI.inputbox.)
        (b) Edit any script you use, that does not wrap it's code in a module namespace, especially method definitions with a module wrapper. Don't use any rbs (scrambled ruby) that you cannot wrap. (Contact the author and ask they wrap their code.)

      (c) If you can.. use the load method with the wrap parameter set true, for menu command scripts, etc. when editing many many plugins is not an option. (The wrap argument for load will wrap the script in an anonymous namespace, and protect the global namespace from corruption.)

      (d) Ask the Google Sketchup Team to fix the Sketchup::load method to expose the wrap argument, so we can specify wrap=true for rbs scripts. For some unknown reason, they defeated, or just didn't pass the 2nd argument (wrap) on to the aliased standard load, when they overrode it to handle rbs decrypting.
      _

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

      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.

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: Bug - WebDialogs are caching and not refreshing images

      I don't think it's an SU bug, it's probably a browser cache quirk.

      I wonder if the image table was enclosed inside a FORM block, would the Js method %(#BF00BF)[form.reset] cause the images to refresh?

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

      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.

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

      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:

      
        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!(/ /, "&nbsp;")
            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
      
      
      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

      @dan rathbun said:

      (2) The puts method returns nil so you won't see anything if Jim's code stripped textstring "nil" out.

      OK if a var evaluates to nil, and then you convert it to a String with .to_s, the result is an empty length String.

      So line 73 needs a nil test, thus:

      r!=nil ? r=r.to_s : r='nil'

      (Don't just have "r" as the boolean expression, because false values would get set to 'nil' instead of 'false'.)

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

      @alexschreyer said:

      @Chris Fullmer: Looking at the result capture code, it appears to convert characters such as the newline into HTML characters before sending it to the dialog. I tried to find a way around this - to no avail. Sending a newline \n to the execute_script doesn't work for me. Apparently that's why Jim put these conversions in there. I'll try later if there is an easier way to "encode" these before sending and "decode" them in Javascript in the dialog.

      Yes the HTML conversion may be necessary for the WebDialog side but not for the STDOUT.

      Alex YOU caused the HTML tags to also go to STDOUT by inserting the line "p r" AFTER the conversion gsub! statements. IF "p r" is needed, move it up before the conversion statements.

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

      @unknownuser said:

      (No output?) The Ruby Console reports no error - but does output the puts statements.
      @alexschreyer said:

      @thomthom: Not sure why there is no output. I didn't touch Jim's code that deals with capturing the Ruby response - does this also happen with the original Web Console?

      Yes it happens with the original WebConsole.

      (1) Keep in mind that the output pane in the WebConsole (currently) displays the result of the eval method, NOT the output stream of STDERR and/or STDOUT as the SUConsole does. (This is why for multiple statements you see only the result from the LAST statement.)

      (2) The puts method returns nil so you won't see anything if Jim's code stripped textstring "nil" out.

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

      @alexschreyer said:

      @thomthom: The bottom of the page disappears when the window width gets so small that the file name breaks into the next row. I wanted to keep the layout fluid so that elements adjust on resize, but maybe I can find a better way to arrange the page more reliably.

      I'd like to see the rb filename on the line below the toolbar (as a step towards future tabbed multi-snippet interface where the filename would be on the tabs anyway.)

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

      @alexschreyer said:

      I have also not tested this on a mac.

      For the PC, put the following META tag in the HEAD section, so the browser displays Themed Controls instead of those old ugly plain Win 3.x style controls (ie buttons, scrollbars, etc.)

      The Mac (Safari) should just ignore the tag.

      HTML

      
      	<!-- Use MS Common Controls ver 6+ if available -->
      	<!--  (also known as XP style themed controls.)  -->
      	<META HTTP-EQUIV="MSThemeCompatible" CONTENT="Yes">
      
      

      _

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: Get_element value for checkbox

      You might just try and keep the state of the control in your own Js variable, and then use onclick or onchange events to toggle the variable ON/OFF value.

      I do it for 'toggle buttons' such as buttons that collapse / uncollapse a <DIV>.

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

      Sketchup::ViewObserver
      http://code.google.com/apis/sketchup/docs/ourdoc/viewobserver.html
      @unknownuser said:

      (Introduction Section > Code example:)

      # This is an example of an observer that watches tool interactions.
      

      The comment line should read:" # This is an example of an observer that watches **for changes to a view**."

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Observers WhishList

      Sketchup::AppObserver

      Anyone interested in any of the following event methods?

      Extensions
      Sketchup.register_extension**%(#BF0000)[onRegisterExtension( extObj, loadFlag, regResult )
      onLoadExtension( extObj, loadResult )]**

      • onUnloadExtension needs fixing. Currently passes the extension name, BUT text names are not necessarily unique, for example there are several extensions, by several different authors called "SelectionMemory".
        In addition what would we do with a textname anyway? There is no method to find an ExtensionObject by searching using a textname, as well as even having access to the ExtensionsCollection/Manager.
        We definately need the object handle passed, then we can access any of the extensions attributes, including the name, example:

        onUnloadExtension( extObj )

      Internet Connection
      IF Sketchup.is_online returns false, an Observer could be used to watch for an when an Internet Connection is established. This may be needed for some extensions that download help information, or textures or other files from the internet (especially when the user has a dial-up connection.)
      %(#BF0000)[onInternetConnect
      onInternetDisconnect]

      Send Action
      fired by Sketchup.send_action%(#BF0000)[onBeforeSendAction( action )
      onAfterSendAction( action, result )]

      Thumbnails Bulk events
      Would likely be used by Gallery or webpage generator Plugin extensions.
      %(#BF0000)[onAfterSaveThumb( obj, img, result )
      onBeforeSaveThumb( obj, img )]

      When fired by:
      %(#BF0000)[ComponentDefinition.save_thumbnail
      Model.save_thumbnail
      View.write_image]
      (if img is thumbSize)

      • obj is the source object handle* img is the output imgStringPathname
        When fired by:
        Sketchup.save_thumbnail

      • obj is the input skpStringPathname* img is the output imgStringPathname
        _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: RDoc question

      @thomthom said:

      But I do like the sound of the @tags it has available. Appear to leave more control than plain RDoc. Such as parameter types and return types and version numbering.

      It's sounding better all the time!

      Keep us advised.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • 1
    • 2
    • 236
    • 237
    • 238
    • 239
    • 240
    • 245
    • 246
    • 238 / 246