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: RDoc question

      @thomthom said:

      While YARD just worked. Based on RDoc syntax, but with @tags.

      I'll have to bookmark that then. maybe it should go on the Sticky Links page?

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

      @unknownuser said:

      Markup

      • The markup engine looks for a document’s natural left margin. This is used as the initial margin for the document.* Consecutive lines starting at this margin are considered to be a paragraph.

      Does RDoc recognize \n ?

      As in:
      ` # Returns an Array object.

      \n

      Added: 1.1.0

      def to_a(orient_by_columns = false)`

      or would that just produce "*n" ?

      I think I have seen some markup in the standard ruby lib files that had <p></p> embedded.
      _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Create toolbar on the fly

      @pout said:

      Am I correct? Is it not possible to create a toolbar, from in the ruby console, using these commands?

      The danger is that the console is running inside Object, and you are using local variables (cmd and toolbar.) Any other 'unwrapped' script that afterward uses the same variable names, will make those 'symbols' point to other UI::Command and UI::Toolbar objects, and you will lose access to them. (Ruby will still know what they are, and the command and toolbar should still work. But you will not be able to make any changes, such as changing the tooltip text.)

      IF that's OK, or your just testing, no harm. But if you want later access to your command or toolbar objects, you will need to keep them in unique variable identifiers. For example, you could store them in a Hash.
      MyToolbars={'FancyCommand' => cmd, 'PoutTools' => toolbar }
      Then later on:
      MyToolbars['FancyCommand'].tooltip="Select object before doing something Fancy!"

      See this post for more info:
      http://forums.sketchucation.com/viewtopic.php?f=180&t=15621&p=220266#p219128

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Ruby namespace?

      @dan rathbun said:

      Here's a couple of test files:

      If you run the test scripts from the console, ie:
      load 'test/UnWrapped.rb',true
      and
      load 'test/NoName.rb',true
      you'll see that the annonymous namespace is assigned an identifier such as:
      #<Module:0x55EF32A4>
      it's basically a temporary pointer.
      Before you could do anything with it, the loaded script would be done parsing or loading or running and ruby will have set the pointer to nil.
      You can try it after running either script (they will report what the identifier is,) type the name of the identifier at the console with .inspect if you wish. Example:
      ` #Module:0x55EF32A4.inspect

      nil`
      _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: How do you execute Ruby API commands in headless mode?

      @advancecoder said:

      How do you execute Ruby Plugin API commands in headless mode (e.g. not opening the GUI for Google Sketchup Pro)?

      You Don't.

      I went 'round and 'round with another guy over at GoogleGroups that thought he could somehow use the engine behind Sketchup (which is Google Intellectual Property,) to write a better GUI and/or integrate it with a debugger.

      Anyhow, read the thread if your interested:
      http://groups.google.com/group/sketchupruby/browse_frm/thread/8d93e9408891fa59#

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: SU Menu Font and Size

      @thomthom said:

      Will need to do some testing. I got an OSX and Linux box...

      Here's a test page for the SystemColors:
      http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/colors/sys_colors.htm

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Ruby namespace?

      @jim said:

      Is there a way to get a reference to this anonymous namespace created by load?

      I'd like to do something like this:

      anon_namespace = load("/path/to/command.rb",true)
      > menu.add_item(anon_namespace.text) { anon_namespace.command }
      > 
      

      First of all load returns true/false for success or raises exceptions (such as LoadError, or SyntaxError from eval,) so you can't get it in that way.

      It can be got... but must be got from INSIDE the object.
      Also.. it's a temporary namespace.
      It needs to be used ONLY for UnWrapped linear scripts, that don't need any persistant objects (such as the cmd or text attribute vars in your 'wishcode' above.)

      So the UI::Command class instance object(s) need to be outside the temporary namespace, because they must persist for the session, in order for the menus to work; and their callblocks would be:
      { load('*somefile.rb*',true) }

      Here's a couple of test files:


      unzip to a test folder in the paths, such as Plugins/test

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

      Re: General

      @richmorin said:

      Class and method names could be turned into links
      to the appropriate API page, for ease of navigation.

      Rich, note the left Nav column. The second box labeled "Quick Reference" has exactly these Class index and Method index links.

      Re: Array class Introduction
      @richmorin said:

      Specific
      http://code.google.com/apis/sketchup/docs/ourdoc/array.html

      
      > The SketchUp Array class adds ...
      > ---
      > SketchUp adds ...
      > 
      

      The correct ruby term is **extends** (as in extending a base class.) The way it is currently worded, a reader might misconstrue that the class is a custom class within the Sketchup namespace (ie, Sketchup::Array ), which is NOT the case. My version would read " Sketchup extends the standard Ruby Array class with additional methods.."

      @richmorin said:

      (same subject... Array class Introduction)

      
      > Specifically, it contains methods ...
      > ---
      > Specifically, it adds methods ...
      > 
      

      The word ***add*** is better here, because it's more specific (as to the manner in which the base Array class was extended.)

      Re: AttributeDictionaries.each
      @richmorin said:

      http://code.google.com/apis/sketchup/docs/ourdoc/attributedictionaries.html

      
      > ... all of the attributes dictionaries.
      >                attribute
      > 
      

      For clarity I would suggest rewording the method description as: " *The each method is used to iterate through the entire list of attribute dictionary objects*."

      @unknownuser said:

      Throws an exception if there are no keys.
      (1) What specific exception is thrown? KeyError or IndexError or a custom SU error class? (the API should state what it is we may need to trap with a rescue clause.)
      (2) Error conditions are not documented in a uniform manner throughout the API. Sometimes they are noted in the method description paragraph; sometimes (as in this case,) as a separate paragraph of the description section; other times in the ***Returns:*** section. Perhaps it's time to add a third ***Exceptions:*** section list, where the list labels would be exception class names and the defintion text would be the reason why the exception is raised.
      (3) Why does this method raise an exception, and the *.[]* method returns *nil* when there are no keys (or matches)? IMHO, the proper ruby way is to raise the correct exception in both cases, AND provide the *.empty?*, *.has_key?* and *.length* (or similar named) methods so scripts can use them in conditional statements when checking the Dictionary lists. Example:

       model = Sketchup.active_model
       attrdicts = model.attribute_dictionaries
       if not attrdicts.empty?
         attrdicts.each {|key,value| puts key.to_s+" is "+value.to_s }
       else
         puts "Dictionary List is Empty!"
       end
      
      

      It just seems strange, as these are Array or Hash type classes, and they didn't inherit some of the basic funtionality, that they should have. Which brings us to...
      **(4) AttributeDictionaries.member?** is undocumented. Not that it does us any good, as it only takes an object, not a string name (returns false even for vaild dictionary names.) This means you need to know it exists in the first place, so why would we need to test it's membership? *.member?* is normally an alias for *.has_key?*, so if this method could be updated to ALSO take the dictionary string name, it would serve us well.

      Re: AttributeDictionaries Introduction

      @unknownuser said:

      You access this class not by performing an AttributeDictionaries.new but by grabbing a handle from an existing entity.
      http://code.google.com/apis/sketchup/docs/ourdoc/entity.html#attribute_dictionaries
      This only works for [ruby:2bffgwcd]model[/ruby:2bffgwcd] objects (seems the model has an empty dictionary list by default.) Other entities will return nil (as they do not have an AttributeDictionaries object created until after an AttributeDictionary has been attached.); the API should note that first a script needs to create an AttributeDictionary object, before the AttributeDictionaries object can be 'grabbed' (because it does not yet exist.)
      UPDATE (2010JAN23-DanRathbun) PC ver 7.1.6860:
      REVISED (2010JAN28-DanRathbun) See later post (this forum):
      [url=http://forums.sketchucation.com/viewtopic.php?f=180&t=17047&p=218516#p218516:2bffgwcd]http://forums.sketchucation.com/viewtopic.php?f=180&...p218516[/url:2bffgwcd]

      [i:2bffgwcd]Re: AttributeDictionary Introduction[/i:2bffgwcd]

      @unknownuser said:

      An Entity or Model object can have any number of AttributeDictionaries.
      [url:2bffgwcd]http://code.google.com/apis/sketchup/docs/ourdoc/attributedictionary.html[/url:2bffgwcd]
      This is confounding the use of the two differnet class names. (The parent should have been named [i:2bffgwcd]DictionaryList[/i:2bffgwcd], or better yet, [i:2bffgwcd]AttributeLibrary[/i:2bffgwcd]. [as in: shelf space for many dictionary volumes.]) Actually each entity can have only 1 [ruby:2bffgwcd]AttributeDictionaries[/ruby:2bffgwcd] object. The sentecnce should read "[ruby:2bffgwcd]An Entity or Model object can have any number of AttributeDictionary objects[/ruby:2bffgwcd]."

      Both AttributeDictionaries and AttributeDictionary Introductions should have an 'also see note' directing readers to Entity class methods [ruby:2bffgwcd].attribute_dictionary[/ruby:2bffgwcd] and [ruby:2bffgwcd].attribute_dictionaries[/ruby:2bffgwcd] on how to create them.

      It would have been nice to have a [ruby:2bffgwcd]new[/ruby:2bffgwcd] method for the child dictionary objects at least. We could then call something like:

      
      myEntity = Sketchup.active_model.selection[0]
      #
      # this is more intuitive
      attrdict = AttributeDictionary.new("My Dictionary", myEntity)
      #
      # this is not so
      attrdict = myEntity.attribute_dictionary("My Dictionary", true)
      
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: New API doc - typos and questions

      @unknownuser said:

      AttributeDictionaries (Introduction )
      http://code.google.com/apis/sketchup/docs/ourdoc/attributedictionaries.html
      You access this class not by performing an AttributeDictionaries.new but by grabbing a handle from an existing entity.
      ... which is refering to Sketchup::Entity.attribute_dictionaries
      http://code.google.com/apis/sketchup/docs/ourdoc/entity.html#attribute_dictionaries

      @dan rathbun said:

      http://forums.sketchucation.com/viewtopic.php?f=180&t=17047&p=208352#p208352
      This only works for model objects (seems the model has an empty dictionary list by default.) Other entities will return nil (as they do not have an AttributeDictionaries object created until after an AttributeDictionary has been attached.); the API should note that first a script needs to create an AttributeDictionary object, before the AttributeDictionaries object can be 'grabbed' (because it does not yet exist.)

      UPDATE (2010JAN23-DanRathbun) PC ver 7.1.6860:
      REVISED (2010JAN28-DanRathbun):In, SU ver 7.1, IF the Dynamic Components extension is turned OFF, the entity.attribute_dictionariesmethod will appear to always return aSketchup::AttributeDictionariesobject for the entity, regardless of whether there are any memberSketchup::AttributeDictionary%(#4040BF)[objects.

      In addition, (if DCs are OFF,) all of the methods of the]Sketchup::AttributeDictionaryclass (except.name,) will no longer work!

      Theentity.attribute_dictionariesmethod was NOT changed in the previous release, as I thought. The method works as the API says it does, returning "nil if there are none." BUT the Dynamic Components extension must be enabled."
      http://code.google.com/apis/sketchup/docs/ourdoc/entity.html#attribute_dictionaries

      There is also no way to determine how many Dictionary objects, there are within an AttributeDictionaries collection (NoMethods: .size, .length, .count, or .empty?)

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

      My previous post onSketchup::AttributeDictionarieshas been REVISED See the original post:
      http://forums.sketchucation.com/posting.php?mode=reply&f=180&t=17047#pr218516

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: DC / Dictionary Interaction

      @thomthom said:

      @dan rathbun said:

      turned off the DC extension (which WILL make all the dictionary methods no longer work except .name)

      ?
      but the attribute methods existed in SU6 as well, right? then there was no DC... ❓

      I dunno, Thom, but that's what happens.

      Perhaps the way they wrote the DC it's so integrated now that, it's really part of the program, not really an extension. (I have a mind to comment out all the Extension code in the DC registration script, and just make it load always. That way I won't ever accidentely ever turn it off again.)

      It happened because, I was tracking down the source of JJ's eval warnings the day before I posted here. See:
      (eval): warnings are caused by Dynamic Components extension!
      and I guess I forgot to turn the DC back on.

      I'm happy to be wrong, and not have more bugs in the API to deal with!
      _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: DC / Dictionary Interaction

      @dan rathbun said:

      @thomthom said:

      @dan rathbun said:

      DO NOT USE:
      object.get_attribute
      object.set_attribute
      THEY ARE BUGGED AND DO NOT WORK

      Don't see where you got that from. I use them often and have no issues with them.

      They 'seem' to work. You can set a value, and then get it back. Which means it's saved 'someplace' in memory. But if you at the same time try to get a value, that was set thru the object.set_attribute, using the dict['key'] it's not in the dictionary. And dict.size returns 0. So there's some kind of 'break in the link' there.

      I'll do more testing tomarrow, perhaps if I save the file, and reopen it, things will get 'linked' back up.

      OK the test you wrote is the same one I had done at the console. I did it again and everything is fine.

      So I'm happy to say it was just my own confusion. Either I corrupted SU memory testing a plugin or had turned off the DC extension (which WILL make all the dictionary methods no longer work except .name)

      .. my Bad ! (OK, I revised my previous post.)
      _

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: DC / Dictionary Interaction

      @thomthom said:

      @dan rathbun said:

      DO NOT USE:
      object.get_attribute
      object.set_attribute
      THEY ARE BUGGED AND DO NOT WORK

      Don't see where you got that from. I use them often and have no issues with them.

      They 'seem' to work. You can set a value, and then get it back. Which means it's saved 'someplace' in memory. But if you at the same time try to get a value, that was set thru the object.set_attribute, using the dict['key'] it's not in the dictionary. And dict.size returns 0. So there's some kind of 'break in the link' there.

      I'll do more testing tomarrow, perhaps if I save the file, and reopen it, things will get 'linked' back up.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • DC / Dictionary Interaction

      Split off from: http://forums.sketchucation.com/viewtopic.php?f=180&t=25386

      @pauline01 said:

      up

      up??

      I don't think you have solved your problem.
      [REVISED - 28 JAN 2010]

      You can use:
      %(#BF0000)[*object*.get_attribute('*MyDico*', *numfriend*)] %(#BF0000)[*object*.set_attribute('*MyDico*', *numfriend*, *namefriend*)]

      OR also:
      %(#BF0000)[*mod* = Sketchup.active_model *obj* = *mod*.selection[0] *dict* = *obj*.attribute_dictionary('*MyDico*')] %(#008000)[# to get attribute values] %(#BF0000)[*namefriend* = *dict*[*numfriend*]] %(#008000)[# to set attribute values] %(#BF0000)[*dict*[*numfriend*]=*namefriend*]

      To deletedictionary key/value pairs, DO NOT USE:
      %(#BF0000)[*object*.set_attribute('*MyDico*',*numfriend*,nil)]

      instead USE:
      %(#BF0000)[*object*.delete_attribute('*MyDico*',*numfriend*)]
      OR:
      %(#BF0000)[*dict*.delete_key(*numfriend*)]

      To load your menu from a dictionary, DO NOT write your own loop.
      This can result in a 'fencepost error', and other errors
      _(where iterator vars are off by 1 ..etc.)
      USE the built-in AttributeDictionary iterator methods .each, .each_key and .each_pair, like this:

      %(#BF0000)[*dict*.each_pair do |*numfriend*, *namefriend*|] %(#F0F0F0)[_]%(#BF0000)[*menu*.add_item("Delete a Friend(#{*namefriend*.to_s})"){ *dict*.delete_key(*numfriend*) } end]%(#008000)[# dict iterate]
      __

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: [Plugin] Selection Toys

      @unknownuser said:

      Selection Modifier
      Selection Submenu - Currently there's two kinds of modifiers.
      The explanations are a bit confusing for me... I have alot of experience in Electronic Radio Frequency / Broadcast Engineering, where Filters are a very important device. So when I think of Filters I think of them in that respect. See if you think I'm correct here:

      @unknownuser said:

      One filters out the type of entity you want.
      This would be a 'Pass' filter?
      http://en.wikipedia.org/wiki/Band-pass_filter

      @unknownuser said:

      The other deselects the entity you specify.
      This is a 'Reject' Filter? (also sometimes called a 'Trap' or 'Notch' Filter from the way the signal looks on a Spectrum Analyser.)
      http://en.wikipedia.org/wiki/Notch_filter

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: New API doc - typos and questions

      Geom::Point3d.<
      http://code.google.com/apis/sketchup/docs/ourdoc/point3d.html#%3C

      @unknownuser said:

      Returns:
      true if the point2 is closer to the origin.

      Following the example, I get the opposite result.

      TheReturns:should probably read,
      " *true* if the point2 is **farther** from the origin; *false* if the point2 is closer to the origin (than the receiver.)

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

      Geom::Vector3d.[=]
      [="]http://code.google.com/apis/sketchup/docs/ourdoc/vector3d.html#[]=[/url]
      Again the HTML anchor may cause problems in some browsers, suggest '#subscriptEquals'

      Obviously the #[]= anchor tag in the url cannot even be displayed properly in this forum.All of the #anchor links to methods using special chars need to be changed to comply with the HTML spec, as ThomThom noted:
      @unknownuser said:

      ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). [url:nfjuel6m]http://www.w3.org/TR/html4/types.html#type-name]("http)

      @unknownuser said:

      Returns:
      value _______ the newly set coordinate value

      the Geom::Vector3d.[] method returns class Float
      BUT, the Geom::Vector3d.[]= method returns the class of the argument.

      The code example may be misleading to the unwary,
      @unknownuser said:

      value = vector[i] = coordinate
      

      ..if the class of the coordinate variable is Integer then the class of the value variable will also be Integer.
      This causes a coder to do a two-step expression if they want a Float, ie:

      
      coordinate = 2
      vector[i] = coordinate # returns Integer 2
      value = vector[i]  # value.class >> Float
      

      %(#FF4000)[Two Issues:

      1. Is 'coordinate' the correct term, or would 'component' be a better term when refering to vectors?1. If all the rest of the methods that return subscript values from a Vector3d object are Float, then perhaps this method should as well, regardless of the class of the argument.]
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: New API doc - typos and questions

      Geom::Vector3d.set!
      http://code.google.com/apis/sketchup/docs/ourdoc/vector3d.html#set!

      @unknownuser said:

      This is a shortcut for writing:
      Clarify: "This is a shortcut for setting all coordinates of the vector, instead of setting them individually in three statements."

      @unknownuser said:

      You may also call this method with an array or another vector:
      Confusing. (I first took this mean that the SU extended Array class had an Array.set! method; which is NOT the case.)
      Clarify: "You may also call this method with an Array or a Vector3d object as the first argument,(and any other arguments will then be ignored.)"

      Add: "If only one Numeric argument is supplied, or if a one element Array is supplied, then only the x value will be changed. IF only 2 values are supplied, in the same way, then the z value will remain unchanged.
      All coordinate values must be implicitly convertable to Float class.
      (If you pass a nil value, a TypeError exception is raised.)"

      @unknownuser said:

      Arguments:
      x ____ The x value for the vector.
      y ____ The y value for the vector.
      z ____ The z value for the vector.
      vector2 ____ A Vector3d object.
      Remove 4th argument. (There is no valid fourth argument for this method. All args beyond 3 are ignored.)
      Clarify: (suggested Argument list)
      Arguments:
      x ____ The x value for the vector, a Vector3d object, or an Array.
      y ____ The y value for the vector. (optional)
      z ____ The z value for the vector. (optional)

      Better Code Example:

      
      vector = Geom;;Vector3d.new 0,0,1
      vector.set! 1,0,0  # three Numeric arguments
      vector2 = Geom;;Vector3d.new 1,2,3
      vector.set! vector2  # one Vector3d argument
      # vector now is (1,2,3)
      array1 = Array.new(4,5,6)
      vector.set! array1[2]  # one Numeric argument
      # vector now is (6,2,3)
      vector2.set! array1  # one Array argument
      # vector2 now is (4,5,6)
      vector.set! [5,4]  # one Array with 2 values
      # vector now is (5,4,3)
      # change x and z in one statement, this way;
      vector.set! 9, vector.y, 8
      # vector now is (9,4,8)
      
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: New API doc - typos and questions

      Geom::Vector3d.x=
      http://code.google.com/apis/sketchup/docs/ourdoc/vector3d.html#x=
      Geom::Vector3d.y=
      http://code.google.com/apis/sketchup/docs/ourdoc/vector3d.html#y=
      Geom::Vector3d.z=
      http://code.google.com/apis/sketchup/docs/ourdoc/vector3d.html#z=

      #Anchors: '=' char should be replaced with 'equals' in links.

      All 3 methods suffer from the same return class anomoly as the Vector3d.[]= method, in that they return the class of the argument (which may not always be Float.) In contrast, the .x, .y and .z methods always return class Float.
      Propose that the .x=, .y= and .z= methods should be modified to return Float as the .x, .y and .z methods do.

      Propose to add note: "See the **.set!** method to set all three coordinates in one statement." ( .. to the description sections, of each of the three methods.)

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

      Geom::Point3d.offset
      Code example has errors:
      [line1]replace"point ="with"point1 ="
      [line1]use parameter delimiters both lines
      [line3]replace".offset**!**"with".offset"
      add comments
      Corrected code:

      
      point1 = Geom;;Point3d.new(10,10,10)
      vector = Geom;;Vector3d.new(0,0,1)
      point2 = point1.offset vector
      # point1 is unchanged
      # point2 is Point3d(10, 10, 11)
      
      

      Geom::Point3d.offset!
      Code example has errors:
      [line1]replace"point ="with"point1 ="
      [line1]use parameter delimiters both lines
      add comments

      
      point1 = Geom;;Point3d.new(10,10,10)
      vector = Geom;;Vector3d.new(0,0,1)
      point2 = point1.offset! vector
      # point1 now equals point2
      # point2 is Point3d(10, 10, 11)
      
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • 1 / 1