sketchucation logo sketchucation
    • Login
    1. Home
    2. Dan Rathbun
    3. Posts
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download
    Offline
    • Profile
    • Following 0
    • Followers 1
    • Topics 92
    • Posts 4,903
    • Groups 2

    Posts

    Recent Best Controversial
    • RE: Collaborative Effort - Ruby Template, RDoc, and Localization

      @jim said:

      What about creating an abstract base class named Plugin which provides inspectors for the information? Not only could inspectors be created for name, author, copyright, license, etc; but also inspectors for menus, Commands and toolbar images?

      This way, external applications (menu organizers, etc) can simply ask the plugin about itself.

      I've actually done some playing around & testing this past week along these lines, before I saw this post.

      I had seen, in many standard (extra Sketchup) ruby scripts, that coders were just declaring a string constant "VERSION" at the top of their outer code blocks. This could be easily accessed ie:, Module::VERSION.

      But then the spark for me was seeing somewhere (perhaps within the RubyGems files,) someone took it a baby step forward by making the constant VERSION a Hash with 4 elements, the first 3 Integer components of the version number, and the 4th a string concatonation of the first 3. ie:

       VERSION=[MAJOR => 0, MINOR => 0, TEENY => 0, STRING => (MAJOR,MINOR,TEENY).join(".") ]
      

      This was a bit better, as you could get any one of the version components for comparison, without having to convert to numeric, by calling as an example:

       if Module;;VERSION[MAJOR] < 7 {..do a block..}
      

      Or if you wanted the whole version string, you'd call, like so:

      messagebox( "The plugin version is; #{Module;;VERSION[STRING]}" )
      

      But the spark had not yet ignited into flame until I stumbled across the standard ruby class OpenStruct. When I read the filenotes in 'ostruct.rb', I immediately thought this is perfect for versioning !!

      OpenStruct is similar to the built-in class Struct, but really makes it act like a true data object should act in an object oriented language like Ruby. Struct on the other hand is so much like a hash, there doesn't seem to be much benefit in it; as you still set and access values as you would in a hash object.

      OpenStruct is SO MUCH better! You simply state a new object name = followed by OpenStruct.new(keylist), where the keylist is just that; a list of data keys to create. The class creates all the keys as attributes, and automatically sets up getter and setter accessors for each one!

      (Pssst! [whispering off topic this would also be great for ruby-side JSON as OpenStructs will look and act just like Javascript Objects..)]

      So my thoughts are to set up a custom subclass of OpenStruct called VersionStruct, or just a custom class called VersionStruct that uses an OpenStruct. Still playing and testing which way is better. Any way the goal is to have something that is all setup correctly that can be either 'included' or mixed-in into a top code block, so the module or class inherits the data structure; OR instanstiated into a code block if it's set up as a class. (I cannot see making coders cut and paste a codeblock into everyscript, errors may creep in.) Anyway.. after instantiating a VersionStruct, a coder would set the fields, then freeze the VERSION object (so the data cannot be changed after the script is loaded.)

      Example: ['RubyTools' is a fictional Namespace.]

      
      module DandyCode
      
        VERSION = RubyTools;;VersionStruct.new(2,1,4)
        # first 3 parameters are integers; major, minor, teeny
          # note VERSION.string is created automatically
        VERSION.author="Ruby A. Coder"
        VERSION.copyright="(c) 2010 by author"
        VERSION.disclaimer="No Waranty...no particular purpose...author to be held harmless ...etc"  # can be preset
        VERSION.termsOfUse="Free for Public Use...etc." # can be preset
        VERSION.title="Title of this plugin code"
        VERSION.description="A short explanation of it's features."
        VERSION.minSUverMajor=7
        VERSION.minSUverMinor=1
        VERSION.dependancies=self.DependancyList
        VERSION.exclusions=self.ExclusionList
        VERSION.freeze
      
        DependancyList = Array.new
        DependancyList[0] = DependancyItemStruct.new(module='JRF;;Inputbox', minverMajor=2)
      
        ExclusionList = Array.new
        ExclusionList[0] = ExclusionItemStruct.new(module='SluggishKeyTrapper', allVers=true)
      
        VERSION.freeze
      
       .. more code ...
      end # module
      

      Anyway.. ideas to chew on...

      Currently.. I'm only playing with a VERSION structure that has Major, Minor, Teeny and String attributes.

      The other attributes in the above example, or discussed in the prior posts, could be in a separate struct as Jim suggested called 'Plugin' or whatever. (We've seen a similar thing done with the Sketchup Extension Class, except that it's put in a separate file.)

      For those interested, who don't have a full ruby install, I attach the ostruct.rb file that ships with Ruby 1.9.1 (put it in a folder that's in the search path, perhaps the Tools folder. I personally have it in a folder named 'Library' which I put in my search path.)


      ostruct.rb

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [Code] Ruby Extension for Sketchup color integers

      Added to the original post (root of thread,):

      Clarification: As discussed in the thread below... these methods really belong within the class to which they provide benefit and functionality. This class or classes, would be any Color object class that is defined in ruby, for whatever purpose. The example code can be rewritten slightly, so as to make it a generic mix-in module, for including in any Color class definition. In this way any Color class could inherit the conversion methods in the mixin module. Such a module would have as it's first line "module ColorIntegerConversion" instead of "class ::Integer", and this will be the way that it would be submitted for Standard Ruby, NOT as an extension to the ruby base Integer class.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [Code] Ruby Extension for Sketchup color integers

      Firstly, I stated in the 2 posts, (the root of this thread,) that it was OPTIONAL; and (in the API doc thread,) that it was TEMPORARY.
      (I went back and re-emphasized those words in both posts, by bold caps.)

      @unknownuser said:

      You can perfectly publish your functionality as a custom class taking an integer parameter.
      TRUE !! And this IS in the works. I've been working on the SKX extension for the Sketchup::Color class. These functions will be added in, because that's WHERE they REALLY belong! (I needed to write them up separately, for testing before adding them in. ...AND there's no way of telling when the first SKX release will happen.)

      @unknownuser said:

      Alternatively, you can create a custom subclass of Integer, which contains the additional methods.
      Too cumbersome... the Color class method implementation is the norm.

      @unknownuser said:

      I am not familiar with color coding conversion, but I guess this applies in specific contexts, where you can perfectly accept to use specific variables created on purpose for this usage, through one or the other methods above.

      • To be honest, before this week, I thought there was only 1 way to represent colors as integers ( and Thom thought there was only 1 'other' way...) πŸ˜„ Research showed otherwise.
      • Now... these conversion principles are NOT my brainstorm (ie, invention.) Although I swear I authored the binary manipulation code in my methods without seeing what was done elsewhere. (What's the fun in figuring out the answer to a puzzle, if ya' cheat?)
      • If you look at the GDI+ library, you'll find that they already have similar functions built-in! But they are in C/C++, which requires you to use a Win32API call in order to use them. In addition, they are cumbersome to use, even in this way, because you would have to instantiate a GDI+ color object, in order to make use of their conversion methods.
      • The point is however, that in GDI+, these functions are class methods of the Gdiplus::Color class; and in the case of OpenGL, they would be class methods of the whatever C++ Color class wrapper is made (the standard OpenGL library is in C.) In the SU example, they set them up as the Sketchup::Color class.
        Anyway.. I agree, they should be in the class to which they provide benefit or funtionality.
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [Code] Ruby Extension for Sketchup color integers

      @thomthom said:

      Very clean code though. Well documented.

      Thank you for the compliment sir! πŸ’š

      After 32 years in Engineering Documentation, I probably tend to overdocument; slap revision numbers on everything. πŸ˜„

      This code is actually a triple exercise:

      • To see if the solution could be 'pure ruby.' (I think I proved it can be.) In this respect, it can also serve as an example.* Second; it's been say 20/25 years since I did anything in Assembler and still wanted to see if I could figure out how to 'move bits around.'* Lastly, I'm trying to learn the RDoc markup, and this was my 1st real attempt at putting that into code. I'm sure I made markup mistakes. The RDoc README info is vague... for instance, I can't figure out how to cause 'code blocks.' HTML tags?
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: New API doc - typos and questions

      A TEMPORARY fix for dealing with the differing formats of color integers.

      Adds 4 methods to Integer (and subclasses Bignum and Fixnum.)

      Get it in the main Ruby Discussion forum, thread:
      [Ruby Extension] for Sketchup color integers

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • [Code] Ruby Extension for Sketchup color integers

      This is an OPTIONAL extension for Ruby that helps deal with the differing formats for RGB, RGB0, RGBA and ARGB color integers. [For more info see this thread..]

      It is a Ruby extension for Sketchup, not an extension to Sketchup per se.

      I know that some of you just hate to modify base classes, BUT... that's what the power of Ruby is all about. (I DO intend to submit it to RubyForge for inclusion into standard ruby, but it would not make it in until after 2.0.x sometime.) In the meantime you can use it as an add-in.

      The base class in question, is the Integer class, and it's subclasses Fixnum and Bignum.

      Clarification: As discussed in the thread below... these methods really belong within the class to which they provide benefit and functionality. This class or classes, would be any Color object class that is defined in ruby, for whatever purpose. The example code can be rewritten slightly, so as to make it a generic mix-in module, for including in any Color class definition. In this way any Color class could inherit the conversion methods in the mixin module. Such a module would have as it's first line "module ColorIntegerConversion" instead of "class ::Integer", and this will be the way that it would be submitted for Standard Ruby, NOT as an extension to the ruby base Integer class.

      The script is not scrambled. I place it in the public domain. No Warranty, etc.


      STD_Fixnum_colorInts.rb

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

      @jim said:

      Sketchup::Color.new

      new can accept a hex value (not string) as the parameter: for example 0xFF0000 (undocumented)

      But, it reverses the red and blue values. Here is a Console session. (bug)

      
      > Sketchup;;Color.new 0xFF0000
      > Color(  0,   0, 255, 255)
      > Sketchup;;Color.new 0x0000FF
      > Color(255,   0,   0, 255)
      > 
      

      ANY numeric input is bugged, no matter Fixnum or Hex or Octal. NOT TRUE... see my next post
      [Console Sesion]

      
      c1 = Sketchup;;Color.new( 255 )
      Color(255,   0,   0, 255)
      # You'd expect (0,0,255,255) ...but
      c2 = Sketchup;;Color.new( 256 )
      Color(  0,   1,   0, 255)
      # that's just plain weird!
      
      

      The color "DarkOrchid" = Hex:#9932CC RGB: 153,50,204
      Using the ColorName all seems to go well on "new"
      [Console Sesion]

      
      c3 = Sketchup;;Color.new("darkorchid")
      Color(153,  50, 204, 255)
      # all OK so far, lets get the integer output...
      c3.to_i
      13382297
      # is that right? Let's see what Ruby says...
      "0x9932CC".hex
      10040012
      # so the .to_i ouput is NOT correct.. 
      #### UPDATE; Ruby returns the correct integer for an ARGB string, ####
      ####  but not the correct integer for an RGBA color, which OpenGL uses.  ####
      # ... but what is integer 13382297 for?
      #### UPDATE; it's for the RGBA color "DarkOrchid"
      #### see the next 2 posts.
      "0xCC3299".hex
      13382297
      # it's for RGB;(204, 50, 153) NOT (153, 50, 204)
      
      

      So.. Sketchup::Color.to_i has the same bug. NOT TRUE... see my next post.
      I'm working on aColor Mixin for the SKX project that ... needs more work.

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

      @thomthom said:

      @dan rathbun said:

      
      > > c1 = Sketchup;;Color.new( 255 )
      > > Color(255,   0,   0, 255)
      > > # You'd expect (0,0,255,255) ...but
      > > 
      

      Ah! They treat a single int as a full colour code. Used to do this stuff in VB apps that used long ints for colours.
      YES.. a single arg is 'read' as either a ColorNameString or a 32bitColorInteger (not read as a 8bitColorComponentByte, unless 3 or 4 args are given.)

      @thomthom said:

      Why are you expecting a blue value from that? Getting a Red colour is what I'd expect, going left to right in RGB...
      Because I was thinking of the 'newer' way of representing colors in binary (in which the blue is the lowest order byte); and you are refering to the 'older' way (in which the red is the lowest order byte.)
      So both of us are both wrong and correct at the same time.😍

      @thomthom said:

      You get the int by first extracting the rgb components, then:...
      Actually I was using bit shifting, it's easier for me to understand, makes for a compact looking method, and is supposed to be much faster on 32 bit architecture.

      The truth (after several hours of research,) is that the whole story is more complex. The binary [integer] format AND the array [component] format for colors depends on platform, specification (ie things changed over time,) and what graphics library is in use by the color.

      The 'old' way you remember is the RGB format, which was a 24bit integer, and had the red as the low-order byte; the blue as the high (3rd) byte. The math you describe will work for this... see previous post, refering to VB coding days.

      Then came Win32. Colors were expressed as 32bit integers, but the industry could not agree on what the extra 4th byte was to be used for. Win32 was released with the 'old' GDI library using the COLOREF structure; it was the same as the 24bit RGB but the 4th byte was labeled 'Reserved' and had to be set to 00 if specified. (I think it defaulted to 00 as well.)

      Later, came, the GDI+ library and .NET; and by that time the alpha camp won out, and the 4th byte became the 'aplha channel.' BUT... they changed the format to ARGB format:
      [C from WinowsSDK::GdiPlusColor.h:beginline 288]

      // Shift count and bit mask for A, R, G, B components
          
          enum
          {
              AlphaShift  = 24,
              RedShift    = 16,
              GreenShift  = 8,
              BlueShift   = 0
          };
      
          enum
          {
              AlphaMask   = 0xff000000,
              RedMask     = 0x00ff0000,
              GreenMask   = 0x0000ff00,
              BlueMask    = 0x000000ff
          };
      
      // Assemble A, R, G, B values into a 32-bit integer
          
          static ARGB MakeARGB(IN BYTE a,
                               IN BYTE r,
                               IN BYTE g,
                               IN BYTE b)
          {
              return (((ARGB) (b) <<  BlueShift) |
                      ((ARGB) (g) << GreenShift) |
                      ((ARGB) (r) <<   RedShift) |
                      ((ARGB) (a) << AlphaShift));
          }
      
      

      Also take note, that HTML/CSS colors conform to ARGB.

      However... when Microsoft, and the W3C switched to ARGB.. others did not.

      OpenGL went with the RGBA format, and did not swap the red and blue, just added the alpha as the 4th byte above the blue, as in the original RGB ( or as in the 'old' GDI 32bit COLORREF with the alpha occuping the 'Reserved' 4th byte.)

      So why am I worrying about this?
      Well, I was 'mixing-in' the standard ruby library Comparble, so Sketchup::Color class objects could be compared to one another, and other objects, ie: integers and arrays that a coder might create for comparison sake. The simplest comparison is at the integer level, and it seemed to me that there was a math bug in the SU Color class.

      So.. it turns out there is NO correct color integer, NOR color array, but instead 4 versions (editions) of each! ( RGB, RGB0, RGBA and ARGB ) The 1st being 24bit/3 element array; the following 3 being 32bit/4 element arrays.

      
      Form  ArrayFmt   HexInteger   Used by;
      RGB   [r,g,b]      0xbbggrr   Win16
      RGB0  [r,g,b,0]  0x00bbggrr   Win32, GDI
      RGBA  [r,g,b,a]  0xaabbggrr   OpenGL
      ARGB  [a,r,g,b]  0xaarrggbb   Win32, GDI+,.NET, HTML/CSS
      Form  bits  (MSB)--Binary Representation--(LSB)
      RGB    24            bbbbbbbb gggggggg rrrrrrrr
      RGB0   32   00000000 bbbbbbbb gggggggg rrrrrrrr
      RGBA   32   aaaaaaaa bbbbbbbb gggggggg rrrrrrrr
      ARGB   32   aaaaaaaa rrrrrrrr gggggggg bbbbbbbb
      
      

      This greatly complicates implementing comparison, which may be why it was not done in the first place.

      Also.. the idea of whether one color is greater or less than another, depends upon your viewpoint. If you like to think of color as having 'frequency magnitude', where red have lower freqs, and blue have higher freqs, than direct comparison of RGBA integers will work for you. On the other hand, most people (scientisits) refer to colors as having 'wavelength magnitude' where the blues have shorter wavelengths, and the colors have longer and longer wavelengths as you appraoch the red. So in the 2nd case you might prefer the ARGB; but a comparison of RGBA integers would give you an opposite result.

      Oh.. we might think why not use a to_hash method and then the comparisons would be able to match up the rgba keys, but to complicate things further there are different types for the values: byteinteger, float 0.0-1.0, percent 0-100%.
      It's looking like it's more trouble than it's worth.

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

      COLOR ...by the way...FYI

      Another Color Table with much more info then the one on the SU API Color page, is at
      MSDN Samples - Dynamic Color Reference

      It's a DHTML sample page... takes awhile to load (and I have broadband.) Once loaded you can sort the table by any column, by clicking it.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Could SketchUp be transformed to a BIM or PEN System?

      IFC2SKP plugin
      http://www.ohyeahcad.com/ifc2skp/index.php

      Question? Is there an SKP2IFC ?

      Update: I checked their forum at: http://ifc2skpforum.websitetoolbox.com/
      and they mention almost 2 years ago that the SKP exporter would be out 'in a few months'; the world is still waiting...

      posted in SketchUp Discussions
      Dan RathbunD
      Dan Rathbun
    • RE: Could SketchUp be transformed to a BIM or PEN System?

      How to BIMify SketchUp: Collaborative editing works for building programming, too!
      A blog by Alex Schreyer (posted September 30th, 2008,) with links, and replies with other links.

      301 Moved Permanently

      favicon

      (www.alexschreyer.net)

      posted in SketchUp Discussions
      Dan RathbunD
      Dan Rathbun
    • RE: Hide Toolbars On Load

      @simonstaton said:

      ...now is there one of these [methods] that I can make that will hide the getting started toolbar on load? ...[snip]...

      ANSWER: Yes there is !
      The following code hides the "GettingStarted" toolbar at any time, whether it's docked or floating.

      status = UI.set_toolbar_visible("GettingStarted", false)
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: New API doc - typos and questions

      @thomthom said:

      Does it give any visible difference when it's set to true as oppose to false?

      I don't know. I don't have an Apple machine. [..wish I could install OSX of my 686 clone for devlopment. XCode looks like a neat IDE.] There are so many attributes, methods, etc. there it's hard to guess what the SU API is refering to.

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

      @thomthom said:

      What's unexpected there is :mac_only_use_nswindow - Same as WebDialog.navigation_buttons_enabled?

      Isn't 'nswindow' a base Cocoa (or Carbon) window class?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Dialog - Simple WebDialog Communication Underware

      Got another 'jewel' for the WebDialog list of treasure's:

      If you want to have the nice XP styled 'themed' controls (buttons, scrollbars, tabs, etc.), instead of the old ugly Win 3.x style, there's a META tag to put in the HEAD section.
      This 'formally' is known as MS Common Controls ver 6 (where the old ver was 5.) These controls are housed in comctl32.dll, which shipped with XP. (Look at properties to see product ver, not file version.)

      here's the tag:

      
      <!-- This tells the HTML frame to use MS Common Controls ver 6+ if available -->
      <!--  (also known as XP style themed controls.) .HTA files always NEED this. -->
      <META HTTP-EQUIV="MSThemeCompatible" CONTENT="Yes">
      
      

      For more info, see Using Visual Styles with HTML Content on page: http://msdn.microsoft.com/en-us/library/ms997646.aspx#xptheming_topic11

      ..and BTW if ya' wonderin' why SU doesn't use ver 6 controls in their dialogs, it's because they didn't turn them 'on' (as a dependant assembly,) in the Sketchup.exe manifest. A holdover from preXP days I imagine. I'm running SU with them ON, but there are some display issues with the brown buttons on the left of the status bar (no images,) as well as few other things. [See post in Google groups, Technical Issues if interested. Have forwarded a 'bug' report to Google as well. Perhaps the next version, they'll have all the controls updated seeing as how they only support XP and higher.]
      .

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: WebDialog help - hide scrollbars

      @newone said:

      If so, why does it renders buttons so old-way?

      Sometimes Standards Compliant mode on MSIE turns MS Common Controls back to the old 'unthemed' set (they look like old Win 3.x ugly controls.)

      See my post in the other WebDialog thread for a META tag that goes in the HEAD section.
      Sometimes it can turn the 'XP themed' ver 6 controls back on.
      I don't know if they work in Strict mode, but the tag should work for Tranistional mode.

      http://forums.sketchucation.com/viewtopic.php?f=180&t=22698#p196706

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Dialog - Simple WebDialog Communication Underware

      Some.. they are great. You have all the power of any application. Read and write direct to files (don't have to go thru SU.)

      Really, I believe HTAs are the answer to much of what ppl have been agonizing over.
      (For those who don't know, an HTA stands for HyperText Application. It's really an HTML file, that has been renamed .hta; and on Windows it gets loaded by a MSIE stub called mshta.exe, which opens it in a similar way that SU does, but mshta.exe makes it a secure webdialog.)
      In ruby you would open your HTA with the UI.openURL("mydlg.hta") command.

      My thots are:

      1. upgrade to Daniel J. Berger's newer better Win32::Api
        ...(req's swaping some parameters, he put the dll last, instead of 1st.)
      2. also install his module for Win named pipes.
      3. then ruby would open a named pipe (same name as dlg) as the server
      4. then call the openURL "dlg.hta"
      5. the JS in dlg.hta would after body load open a connection to the waiting pipe as client
      6. two way comms from then on
      7. the dlg would need to put a I'm closed message in the pipe before it closes
      8. and the ruby script would dispose of the pipe when no longer needed

      no more messin' with ghost protocol args
      I've been workin' on a simple JSON module to pass things back and forth.
      ..but other things interrupt...
      probs updating all my .NETs
      probs with rubygems... so I uninstalled ruby 1.8.6
      need to get 1.9.x installed with a newer rubygems

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Hide/show a WebDialog

      .
      I guess the only thing to do is move it off screen.

      WebDialog.set_position(3000,3000)
      

      ..or whatever X,Y works for you

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

      Face.mesh
      http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/face.html#mesh

      @unknownuser said:

      Valid flags are:

      [condensed: 0, 1, 2, 4 ]

      Add these numbers together to combine flags. A value of **5** will include all flags, for example.

      I seem to get 7 (as shown in the example,) when I add all the flags.
      πŸ€“

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

      @thomthom said:

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

      True if successful, false if unsuccessful.
      Surely it would return the value being accessed?

      Verified!
      Sketchup.read_default('Preferences','SnapAngle') returns 15.0
      [My current setting; which happens in this case to be class Float.]

      The API doc is vague about the default argument. The definition should read (as things work now):
      "(optional) A value to return, if the variable is not found or empty."
      [The way it is written, I read it as being a value to write into the registry.]

      The lack of error checking in this method, can easily create false Resistry Keys.
      Example: if you misspell the key (section on the Mac,)... ie:
      [note misspelled 'Preferences']:
      Sketchup.read_default('Prefer ances','SnapAngle')
      ... the method creates a new 'Preferances' key, with nothing under this new WORTHLESS key. (No Valuename, no value.) The method then just returns nil. [On Win32, we must manually use the Registry Editor to get rid of this junk!]

      If the key is correct, but the Valuename is wrong (or does not exist,) the method just returns nil, [again,] or the default ReturnValue.

      If the the Key is correct, AND the Valuname is correct, but the Value is empty, the method returns nil, [once again,] or the default ReturnValue.

      So we have 3 situations in which the method can return nil, and no way thru the SU API to tell what the situation is. [yes we can use one of the full ruby Win32 Registry modules, and I may begin doing this.]

      A fourth situation, is if the value is an empty string, (ie '' or "" are stored in the registry value the method just returns the empty string (and NOT nil.) The return class of the method is string in this case.
      This can happen if you use Sketchup.write_default( key, valuename, ""), but its not necessary as each value in the registry has a type, and strings don't need delimiters.
      We should use instead Sketchup.write_default( key, valuename, nil) to clear a string value in the registry.

      I would propose a change to this method...

      (1 as is.) IF everything exists, it works OK, and the value is returned.

      (2 as is.) If (the Key exists, AND the Valuename exists,) AND the value is empty, then the method should return NIL without a default Return Value (3rd parameter,) OR the 3rd parameter if given.

      (3) If the EITHER the Key OR the Valuename do NOT exist, then the method should raise an exception similar to a hash index error, viz:
      Error in myprog.rb:22:in `Sketchup.read_default': key not found (IndexError) ...

      Then (reference methods for Hash class):
      CREATEseveral new boolean methods similar to Hash.has_key?, Hash.has_value? and Hash.empty? so the programmer can decide in their RESCUE block what action to perform;

      I'd envision these boolean methods to be named similar to:
      Sketchup.default_empty?
      Sketchup.default_has_key? (perhaps with a Mac alias .default_has_section? for plist files)
      Sketchup.default_has_valuename? (perhaps a Mac alias .default_has_variable? for plist files)

      .
      Thoughts?

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