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: Writing Readable Ruby

      @unknownuser said:

      [Is it because ] super [is ] a keyword? Hence this exception?

      I believe so. If you look at the lex.c file in the Ruby source, you'll see there are only 3 keywords that use argument lists: defined?, super and yield.
      In the eval.c file, you see these statements are converted into internal C function calls, (like everything else in Ruby.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: What? No Menu?

      Weird!
      If you send the following at the console, it works:
      UI.menu('Plugins').add_item('Hello') { puts "World" }

      Another thing. Each time you call UI.menu('Plugins') a new object is returned. I would think each of the standard menu objects would be created by the OEM extensions at startup, and the UI.menu method should return those, every time the method is called.

      Is this a bug that has creeped into the latter versions?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Writing Readable Ruby

      @unknownuser said:

      Putting parentheses after function and method calls improves readability.

      @unknownuser said:

      And I use parentheses for method arguments

      As do I, whenever possible. I always hated the varience in the early BASIC dialects (my first language,) regarding parameters. There was no standard. Then I picked up an old copy of TurboPascal from the FIT bookstore and learned it. (This was back in the mostly textmode, pre-VGA days.) It was great to have standard parentheses delimited procedure arguments for all functions and procedures. (Never went back to BASIC after that, and have avioded VB whenever I could.)

      Just a note, however. There is at least one very important exception to the rule of "always use parentheses" ... that is in the use of super.
      If your statement is: super() you are telling Ruby to call the superclass method with an empty argument list, even though the child method may have been passed arguments.
      If you want to pass the local arguments on up the inheritance chain (the default,) your statement needs to be: super
      You also have a third option of passing a new set of arguments up to the superclass method, different from those the child method was passed.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: What Every Programmer Should Know About Floating-Points

      @tig said:

      ... although personally I'm pretty 'bilingual' [bimetrical?]

      How about: multi-metrological ?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Source Code Indentation : Why certain amount?

      Elastic Tabstops

      Link Preview Image
      Tab stop - Wikipedia

      favicon

      (en.wikipedia.org)

      http://nickgravgaard.com/elastictabstops/

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Timer < 1.0 seconds ?

      Perhaps something like this: ( UPDATED, see new codeblock later in topic. )

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Timer < 1.0 seconds ?

      UPDATED: Perhaps something like this: ( NOT TESTED )

      
      def at_timer(seconds, repeat=false, multidelay=false, *args, &block)
      	result=nil; delay=true
      	sub = Thread.new(args) do |args|
      		Kernel.sleep(seconds) if delay
      		delay=false unless multidelay
      		result = yield(*args)
      		redo if repeat
      	end
      	return result
      end#def
      
      

      Does the args passing work OK?

      Note:
      (1) also I set it up so any kind of result could be returned from the yield block.
      (2) it does NOT have any check on block_given?, should an exception be raised if no block is given ??

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [Example] box.rb version 2.0.0

      @jim said:

      [5] Every method following a module_function declaration becomes a module function.

      Um.. are you saying that the newset doc has changed the way module_function works?
      Or.. that it does NOT work according to the docs? [ie a Ruby Core bug.]

      The old 'Pick-Axe' book for ver 1.6.x says if an arg list is given it applies to the methods identified by symbol, but without an arg list then it applies to following methods. (Similar in how public, private and protected work.)

      EDIT: The latest docs have no change from the old '1.6.x' docs. See:
      http://www.ruby-doc.org/core/classes/Module.html#M001642

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: Timer < 1.0 seconds ?

      I see 3 issues with Alex's example:

      (1) There is no easy way to pass values (args) into the Thread block.

      (2) The Thread block delay is repeated on each iteration instead of only before the first. Perhaps a means of doing either via a parameter to the outer method?

      (3) Will the Thread object should be disposed of when the outer method ends, or is a call to Thread.kill needed (and therefore a reference name for the internal Thread object would also be needed.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Source Code Indentation : Why certain amount?

      @mitcorb said:

      From a total outsider's point of view, I would like to thank you guys for discussing this matter of indentation in coding, ...

      ๐Ÿ˜‰ I started this thread because things seemed to slow down a bit in here this week, and I knew it would be an interesting discussion. [insert Mutley laugh here.]

      Truth is, I have not decided what, if any certain indent, is wrong/correct, too big/too small, etc.

      All I know is, at this time, I LIKE 2 spaces for Ruby (and most everything.) HTML in particular, (I don't know why,) but it really seems the most wastful and ugly with 4 or more space indents.

      Anyhow... what I was hoping for was specfic, nitty-gritty reasons for the 4 space (and no 2 space,) 'convention'.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Source Code Indentation : Why certain amount?

      @unknownuser said:

      Four spaces are more readable. It's easy to see who aligns with whom, even over a substantial vertical range.

      Not for ME. I never used 4 space idents (haven't yet gotten into Python,) and never saw or 'noticed' anything when I learned HTML, CSS, or Javascript (oh.. at least more than 10 years back,) that 4 spaces was some sort of 'convention'.

      I the past, with plain-jane text editors, perhaps ident alignment needed the help that 4 spaces provided. But with better code editors now having the ident guidelines and foldmargin symbols to mark nested blocks, your arguments regarding 'who aligns with whom' and 'readability over a vertical range' lose some of their importance.

      In addition, I can feel the muscles of my eyes having to do more work, yanking my eyeballs left and right, reading the 4 space example. This translates (for me,) into fatigue, headache and less programming time.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Source Code Indentation : Why certain amount?

      @unknownuser said:

      Deep nesting is not something to be encouraged.

      Another 'convention' stated, but without specifying fundamental reasons.

      In Ruby, if say there was a "law" of no more than 4 levels of indentation, a coder had to move 5th level code blocks into a separate method, there would be a time cost to make the method call. If the nested block in question was within an iterative block, the multiple method call delays could really add up. (One of the reasons I wish Ruby could be compiled.)

      I just feel, nesting is nesting, it occurs where it should or needs to occur. Meaning I prefer to create methods for good reason(s), not frivolous reasons.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Source Code Indentation : Why certain amount?

      @thomthom said:

      "outdent"?

      Yea.. if you look at some of Jim's code, you'll see he has a habit of outdenting codeblocks.

      onmargin
          indented
              indented twice
                  indented thrice
          outdented statement
          outdented statement
          outdented statement
                  end #3
              end #2
          end #1
      end
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • Source Code Indentation : Why certain amount?

      @unknownuser said:

      (http://forums.sketchucation.com/viewtopic.php?f)":2i409aa9]If you can choose, for example, a level of indentation in your source code editor (please don't choose two!) you have an option. If you are writing Python, four spacesis mandatory so you don't have an option.

      ...AND...
      @unknownuser said:

      (http://javascript.crockford.com/code.html)":2i409aa9]Indentation
      The unit of indentation is four spaces. ...

      I ask these questions, because neither Martin (code in general, Python specific,) nor Doug (Javascript specific,) give any reasons. [Obviously, the Python interpreter needed a specific indentation, by why was 4 chosen as opposed to 2, 3 etc? This discussion really is about what Ruby code indentation should be, but with a background of WHY predessesor languages chose certain indents.]

      What's so special about 4 space identation ??
      What makes it better than any other choice ??

      Why (Martin,) should I stop using 2 space identation ??
      I like it, it's quick to enter, it saves space, it is less likely for someone editing to be tempted to outdent a multi-nested block of code.

      I must state that I absolutely HATE outdented code blocks, they cover the ident guidelines in code editors.

      Would MY choice of identation matter, as SciTE, Notepad++ and any other good code editor can easily convert one identation setting to another ?? **

      **(You may need to asign macrokey(s) in your editor, if you don't wish to go through menus or dialogs.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [Example] box.rb version 2.0.0

      @frankc3250 said:

      Thank you so much! This has been driving me nuts.

      Your quite welcome, Frank. Glad I could help.

      So does this mean I can turn my SketchScout pin right-side up for today?

      For those interested in what prompted this revision, see the following thread over at GoogleGroups:
      http://groups.google.com/group/sketchupruby/browse_frm/thread/96975c731eabf8b1#

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: Trouble loading scripts outside Plugins directory

      @mgianzero said:

      I tried following the Google Ruby API website and so .... But it doesn't work. What am I doing wrong?
      The example assumes your script dir is a subdir of 'Plugins'.
      It does not explain the "tricks" of having a dir elsewhere.

      @mgianzero said:

      So I wanted to place my personal ruby scripts under "Documents/Sketchup/Marc_Scripts" on my Mac. I created a script ... In it I put:

      home = File.expand_path "-"
      (1) the HOME shortcut is a tilde char "~" not a dash.
      (2) You dont need a "home" var because it's already defined in the Environment Variable Hash on the Mac. To access it from Ruby use: ENV['HOME']
      So... the following:

      @mgianzero said:

      myrubyscripts = File.join home, "MyRubyScripts" require_all('Documents/Sketchup/Marc_Scripts')
      ..becomes:
      require 'sketchup' myscripts = File.join(ENV['HOME'],'Documents/Sketchup/My_Scripts')
      require_all( myscripts )

      This is the equivalent of what Jim showed with a literal argument.

      The drawback is you wind up with all the script entries in the $" array being long absolute paths. You could save memory space by stealing and modifying the code block within sketchup.rb::require_all, like so:

      
      begin
        # require('sketchup') ## not needed
        myscripts = ENV['HOME']+'/Documents/Sketchup/My_Scripts'
        $;.push( myscripts ) # add to $LOAD_PATH array
        old_wd = Dir.getwd   # save old working dir
        wd = Dir.chdir( myscripts )
        rbfiles = Dir["*.{rb,rbs}"]
        rbfiles.each {|f|
          if f.split('.').last=='rbs'
            Sketchup.require( f )
          else
            require( f )
          end
        }
        Dir.chdir(old_wd) # restore old working dir
      end
      
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Snap Alignment

      A quick look thru the API makes me think this would best be implemented as an extension to the Sketchup::Behavior class.
      http://code.google.com/apis/sketchup/docs/ourdoc/behavior.html#snapto

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Snap Alignment

      @august said:

      The question often comes up, especially from new users who are excited by hou MUCH SketchUp can do, about making parts that will fit together in proscribed ways like pipe fittings, Tinker Toys, model railroad sectional track, or Lego.
      Reminds me of the "glue points" in OpenDraw or MS Visio. I like this idea very much!

      @august said:

      Are there any kind of rotation snapping tools already built?
      Yes, "Snap Angle" is built-in. Open Model Info dialog and chose the Units page. (Can be changed thru Ruby, using the Units Options Provider.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Google's New API Doc

      Does it behave the same in Safari? or is it unique to MSIE?

      Does changing the standards-compliance mode in your <!DOCTYPE> tag have any effect?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Google's New API Doc

      @martinrinehart said:

      Recently (last few days?) Google changed the API Doc's HTML/CSS/JavaScript. They added an option to show/hide the left-side navbar.
      You have to look closely, but the bar itself is still there. Another click restores. Nice.

      NOT new. It's had this collapsing navbar for as long as I can remember.

      @martinrinehart said:

      ..., but after a second or so, a large div (or ?) locates itself over the methods doc ...The method doc is still there. You can see little hints of it peeking out on the far right, but the covering thingie hides everything until the "add your own comments" at the bottom.

      This is SOMETIMES caused by a manual typo in the HTML, where a closing tag is not 'proper'.
      An example, look at the source of the "Release Notes" page, line 380. The closing tag of the <p> element is not correct, and the following <h2> tag does not render correctly. (It should look like the "What's new in SketchUp 7.0 M1" heading above it.)

      Other possibilties include YOU overriding or adding to Element Styles or Classes with your own stylesheets, or a global stylesheet set in MSIE > Internet Options > General (tab) > Accessibility (button).
      Check your stylesheets especially for any style changes to <h2> elements (as that seems to be the one with the skyblue background on the API pages.)

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