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: Could SketchUp be transformed to a BIM or PEN System?

      .
      Interesting post over at Google Groups:

      "A plugin for 5D construction animation in Sketchup"

      posted in SketchUp Discussions
      Dan RathbunD
      Dan Rathbun
    • RE: Tool <> WebDialog <> Observers relationship

      @adamb said:

      But the rule of thumb in OO systems, is you create stuff, use it and explicit/implicit release stuff.

      Agreed.. however, it would nice to have direct control over "my" objects. When I want to get rid of an object, I'd like to call a dispose method. Perhaps also a release method that would release ALL references (vars) to the object. And finally, I'd like the undef function/keyword to act upon references (of all kinds,) so when I'm done with a reference, it can be removed from the module/class reference hash-table. (There is cheat to this. Use vars that begin with a capital letter so Ruby sees them as Constants, then you can use the remove_const to remove the definition.)

      Anyhow... these wishes need to be voiced over at
      http://redmine.ruby-lang.org/projects/ruby/issues

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Tool <> WebDialog <> Observers relationship

      @adamb said:

      Well Dan is sensible guy who says smart stuff. But I'm not quite sure why you want to keep a reference to the Tool around rather than release it back to the system.
      Depends... if it's a base drawing or editing tool, that will be used often.. keep it around. If it's say a import, export or report tool, that will be used only on occasion, then yes create it when it's used, and release the reference to it when it's no longer needed. (Hoping GC will dispose on it.)

      @adamb said:

      The specific reason I generally keep dialogs as class variables is to avoid the weird GC behaviour I wrote about earlier.
      So is there a difference when the WebDialog instance, is created inside Object (at the console,) as opposed to within a custom namespace (Class or Module.) ?? It's always dangerous to create objects in the ObjectSpace, because all other objects may inherit them in some way (especially true of methods.) Local variables, Class variables and Instance variables defined in Object (at the console,) act strangly like Global variables when they're inherited by all the other objects.

      @adamb said:

      The exception is sometimes performance when you pre-create Pools of objects to use/share. But this isn't one of those cases.
      Well I have no idea what kind of tool he's talking about. If it's an occasional tool, then you are correct AB. If it will be used often, he will want to, keep the instance alive.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Tool <> WebDialog <> Observers relationship

      @unknownuser said:

      @dan rathbun said:

      Tools are meant to be re-used.

      I have downloaded Google's 'rectangle.rb' tool example ...
      Warning! Most of the Google Ruby examples, have very poor Ruby programming practices. (One of the things on my to-do list is to edit these examples, so newbies see the proper Ruby way of scripting. Just need to find the time is all.)

      @unknownuser said:

      The tool is created each time the plugin is started.
      And that makes my point. The example is a poor example.

      @unknownuser said:

      Maybe if I have a Tool as a global variable inside a MyWebDialog class it multiplies now tools, every-time I open the dialog..
      Globals are not kept inside a class, even if they are defined inside a class.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Tool <> WebDialog <> Observers relationship

      @unknownuser said:

      What if I a tool is being cancelled. I want to close the associated myDlg with the onCancel(reason,view) method in the tool. But if I will do that I will triger on_close in the webdialog which will destroy the tool. Am I right?

      NO. Just because you stop using a Tool, does not cause the Tool object to be destroyed.
      Tools are meant to be re-used. The next time the user clicks a toolbar button (or menu item,) for your tool, Sketchup will call the Tool's activate method. This means that the Tool class object is still defined and should remain defined. If you purposely cause Garbage collection on the Tool object, and Sketchup trys to call it's activate method, either an Ruby exception will be raised, or worse, a Bug Splat!

      I would always advise, making a reference (variable) that points to: Tool instances, WebDialog instances, Command instances, etc. that persist, and can be accessed again. You can put these references in a Set class object, or a Hash.

      I suggest using a Hash structure called $PLUGIN which is a global. Your plugin (and other plugins,) then create sub-Hashes inside $PLUGIN, and use a "short-name" for the specific plugin as a keyname.
      Within the sub-hash, who's keyname is your plugin "shortname", you can save any kind of settings or data, and most important, refernces (aka variable names,) to important things your plugins "owns" such as menu items, command objects, webDialog objects, tool objects, etc. Then anytime after creation, you could access those objects, say to dynamically change the tooltip for a toolbar button assigned to a command object.
      (I actually have modified the extension.rb file [SketchupExtension class definition,] that automates the use of a $PLUGIN hash.)

      The reason, I am talking about this is, I have seen people create WebDialogs, and Tools, without assigned a reference to the object. The way I understand Garbage Collection is 'supposed' to work, is that if an object has a reference pointing at it, Ruby 'marks' it as 'in use'. When no references are pointing at an object, Ruby will 'unmark' the object, making the object eligible to be 'swept up' by Garbage Collection.
      So when I want an object to stay around, I make sure I assign a reference to it, that will persist (an instance ref, a class ref, and last resort global.)
      When you hear people say "To get rid of an object, set it to nil", they are wrong. You cannot set an object to nil. You can only set a reference (which may be one of several,) that is pointing at the object in question, to point at at different object. In this case, the new object chosen (by tradition,) is the nil object (ie: the singleton instance of the NilClass class.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      @driven said:

      SKSocket doesn't show up under XP....

      Nor does:
      class Sketchup::Geodesic

      I have module Precision, but not the 3 methods your list shows.

      I cant find (mix-in) module Smoothable (is this a plugin?)

      None of the DC classes or modules are on your list.

      The following classes, don't have prototypes defined (BUT SHOULD!):
      UI::InputPoint [*no-proto]
      UI::Menu [*no-proto]
      UI::PickHelper [*no-proto]
      UI::Tool [*no-proto]

      Sketchup::FrameChangeObserver [*no-proto]

      And then the standard extensions:
      LanguageHandler ( should be moved to -> UI::LanguageHandler )
      SketchupExtension (should be moved to -> Sketchup::Extension)

      P.S. - I accidently opened your list in ol' plain Notepad and it of course could not handle the EOLs.
      But when I opened it in Notepad++ no problem, and the app automatically switched to UNIX EOLs for that 1 file tab.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      @chrisglasier said:

      @driven said:

      what does #arity mean??

      disappointingly - the number of arguments - but I don't know what the -1's mean on your list.

      "For methods written in C, returns -1 if the call takes a variable number of arguments."
      http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_method.html#Method.arity

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: WebDialog.set_html() Gotchas

      @martinrinehart said:

      @dan rathbun said:

      .And a good example of why I like Ruby so much:
      Js: %(#8000BF)[crlf = String.fromCharCode( 13 ) + String.fromCharCode( 10 );]
      Ruby: crlf = 13.chr<<10.chr

      I couldn't tell if you were being serious or sarcastic.
      Quite serious and honest. (Most people tire of sarcasm very quickly, myself included.)
      @martinrinehart said:

      The Ruby's terse but it wins no prizes for readability. I'd replace either of these with crlf = ASC(13) + ASC(10).
      Edit: Do I have that backwards? CHR(13) + CHR(10)?
      Several times now I've seen you make comments that Ruby "wins no prizes for readability" and something about 'Monty' your pet Python. I don't care what Language is better, it doesn't matter. (Ruby was chosen as the scripting language for Sketchup by the powers that be.)
      I have NO problems reading Ruby. It makes sense when your brain finally reaches the point of object epiphany. (With Ruby, it didn't happen for me right away, even though I was exposed to semi-OOP languages in the past.) In Ruby the 13 is an object, an instance of class Fixnum. It inherits instance methods from it's class, which usually operate on the object itself, so in Ruby the 'tradition' is to name the method for the class of the output. What could be simpler than that 13.chr will return the 13th character is from the character set currently in use?
      The example from Js the reverse. (I purposely avoid any disparaging term here. It's just different is all, not better, not worse.) Instead of being an object method as in Ruby, the Js statement is more a Library function. String being the library, fromCharCode the function, and then the 'term' that you wish it to operate on must be passed as a parameter. (Obviously what I most meant [in my previous post,] is that often there's alot less typing in Ruby, but that's not the best reason why I like Ruby.)
      So, the main point I am making, is that Ruby with it's 99% OOP structure, requires a reverse way of thinking while reading and writing the code.
      I'm not against Js, I learned it ..oh 12 years ago I guess. And have nothing against Python, I was about to dive in and learn it, when I found Ruby. I still may.. I like the fact of being able to compile Python programs.
      Since we are on the subject (going off topic abit,) since SU Ruby plugins can be writen in C and compiled into so or dll, there shouldn't be any reason why you can't write SU plugins in Python and compile them. It would require (not sure what Python calls them,) "wrappers"?
      There is a guy in NZ who says he has a Python plugin for Sketchup, he calls it SuPy:
      http://groups.google.com/group/sketchupruby/browse_frm/thread/7fdc49a451ae3cae#

      Anyway.. the point on character substitution is well taken. Another one for the long list WebDialog pitfalls (AAAaaaHHHhaha aaa SPLAT!)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      @driven said:

      @ Jim, had a look at the charts, very nice

      @ JIM .. dittos from me. I'd like some that we're left right hierachry, tho.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      An old post on SkSocket at over at GG.
      http://groups.google.com/group/sketchupruby/browse_frm/thread/0b81977cc5d795ba#

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      @driven said:

      or is there an easy way to have an introspective, local, platform aware list....

      Of all the .rb/.rbs files in the Tools/Plugins file heirarchy ?

      .. or the objects they create, ie: Classes / Modules / Methods, etc. ??

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • Open Komodo

      Open Komodo
      http://www.openkomodo.com/

      I'm wondering if anyone has Open Komodo Edit, and as it's Scintilla based, if it has the same lexing bug we've seen in SciTE and NotePad++ ??

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      Well being a Mac guy.. be careful here:

      Notepad is a crappy plain jane text editor that comes with Windows; and is even known to screw up files made for windows.

      Notepad++ is a full featured code editor based on the Scintilla core (which is cross-platform.) I just don't know anyone's ever compiled a Mac version.

      Haven't had time to look at that editor, I'm happy with Notepad++ as an editor, that can be expanded with plugins. (such as a console, debugger interface etc.)

      The problem is not a lack of editors or IDEs, or even those that work with Ruby,.. it's that Sketchup does NOT use standard Ruby. The answer is to get both Sketchup and an IDE to be using (or acceesing,) the same instance of Ruby. We don't have a choice NOW, because it's Sketchup that loads the Ruby instance, and into that instance is where Sketchup loads it's API extensions.

      I WISH for the future, that the Google Team can be convinced to let us have more control over Ruby.

      • A configure setting where WE tell Sketchup the location and name of the Ruby Interpreter binary (so it can be pointed to the standard Ruby bin directory of whatever version we want to run or test.)* The option to load the SU API extensions into a Ruby Process that is already running, and started by the user, or the IDE, rather than Sketchup. (Hoping here that when SU crashes, it doesn't take Ruby down with it.)
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: WebDialog.set_html() Gotchas

      .
      And a good example of why I like Ruby so much:

      Js:
      %(#8000BF)[crlf = String.fromCharCode( 13 ) + String.fromCharCode( 10 );]

      Ruby:
      crlf = 13.chr<<10.chr

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: WebDialog.set_html() Gotchas

      What if you use the standard escape sequences for regular expressions, which both Ruby and Js share.

      %(#8000BF)[crlf = '\r\n';]

      Does the writing to the Temp file replace the escape sequences?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: HELP setting up a SU code editor

      @driven said:

      ... when I cleaned and reformatted using Unix Line Delimiters as suggested (as apposed to PC or Mac specific) some of the script worked without additional work, while there seemingly identical originals still didn't...

      So Notepad++ has 3 options for EOL (which is apparentley auto set on install for the platform the user is on.) On my PC, it was set to 'Windows'.

      The other options are 'Mac' and 'UNIX'.

      IF UNIX EOLs work on Mac, how does it work for Ruby on a PC??

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Tool &lt;&gt; WebDialog &lt;&gt; Observers relationship

      assume that myToolsObs is the predefined observer object:

      myDlg = UI;;WebDialog.new( ...parameters...)
        #... callback methods ... set_html ...
      myDlg.set_on_close do
        toolset = Sketchup.active_model.tools;
        toolset.remove_observer( myToolsObs )
        # do other pre-close tasks
        # such as save data from WebDialog
        Sketchup.active_model.select_tool(nil)
      end #set_on_close
      myDlg.show
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      @unknownuser said:

      You saying that the example is buggy makes me not feel so warm a fuzzy about learning off of that example, I'd rather see one that works.

      Eric, The 'bugs' are not that bad:

      read this thread, it is an example of one of the 'issues' with the API
      sample (it's not module wrapped.)
      http://groups.google.com/group/sketchupruby/browse_frm/thread/4f22a3a...

      below 'class LoadHandler', add this line:
      attr_reader(:error)

      in 'method onFailure', make this change:
      rename $last_error to @error so the line reads:
      @error = error_message

      now the if statement will work correctly.

      The whole thing (for YOUR plugin, plus any other code) needs to be wrapped in a module SketchTHIS block. You MAY have nested modules and classes inside your Top Level Namespace (SketchTHIS.) If you plan more than one plugin, that works with your site, OR is 'site-branded' each should be (or end up in,) in it's own submodule, beneath the outer namespace SketchTHIS. Read the post at Google Groups to see how to use file spanning. (It means even if you don't know what the next plugin will be named, or how many you may end up with; each will be protected from each other in their own namespace; all will be protected from the rest of the Ruby plugin world.)
      NOTE, that for module and class names, Ruby may not allow the use of a '!' character; it's kind of reserved for method names and a form of the not operator, (as in !=) 'not equal to'.

      **You might have missed the fact that the use of a LoadHandler class object is optional.

      You can always just use (for testing):
      Sketchup.active_model.definitions.load_from_url("myurl/comp.skp")
      within the WebDialog callback method, that executes when the user clicks the "download to model" button. (The filename part of the url string changes of course, depending on the file.)

      The component is added to the InModel Component List, but an instance is NOT added to the actual model. (The user would need to drag&drop into the model, in the normal way of adding a component instance to
      the model.)

      I think that's what you are after?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Download to Sketchup button

      @unknownuser said:

      Where do I place the code?
      Sketchup Ruby is client side. (It does NOT go on the website.)

      @unknownuser said:

      So that Ruby code sample you gave me seems to be exactly what I need, according to the description.
      Actually I did notice a few errors in that sample code. It could be cleaned up and better implemented.

      @unknownuser said:

      Here's the deal though, I am REALLY Ruby illiterate...
      Well you'll need to take some time and get literate, or run the risk of having your code collide with other plugins, possibly making users angry.
      or..
      Check the script libraries for something similar, that you can tweak and customize for your own use, (which is one way to learn more quickly.)
      or..
      If you don't have the time, you can hire someone experienced, to write it for you, or cleanup your code.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Units Strings i18n

      @tig said:

      The US idea was to go back to the Latin ... spelling which came from Latin to French and then to UK English ...
      ..um, actually it's not Latin, it's Greek, metron/metros [μέτρον/μέτρος]

      @tig said:

      and the French did invent the 'metre' !
      I take issue with the word 'invent.' I would replace it with the phrase 'first to design, approve and put into use, a decimal based measurement system.'
      Others, including Englishmen, Germans and Italians had made proposals for a decimal based metrological system (or units for such a system,) predating the French effort, by more than a century.

      @tig said:

      ... in UK English there are two words 'meter' and 'metre'
      This British method (with two words,) makes alot of sense!
      I wish we (in the US) would adopt this as well.

      P.S. As you might guess by now, metrology is one of my major interests.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • 1
    • 2
    • 231
    • 232
    • 233
    • 234
    • 235
    • 245
    • 246
    • 233 / 246