[code] (beta) Sketchup::Tools helper methods

Moderator: Jim

These Tool ID and ACTION hashes and methods, should be in namespace:

Sketchup::Tools
3
30%
SKX::Tools
6
60%
SUAPI::Tools
1
10%
 
Total votes : 10

[code] (beta) Sketchup::Tools helper methods

Postby Dan Rathbun » Sat Mar 26, 2011 11:02 pm

First this is beta. Solicting comments, etc.
@Didier - DO NOT copy this code and put it on your website!
(That goes for others as well.)

This is a work in progress.

I am not sure putting these methods in the Sketchup::Tools namespace is best, (although it allows the methods to be called from a Tools collection instance.)

Other options are to wrap these methods (with the hashes,) inside namespace:
  • SKX::Tools, or
  • SUAPI::Tools

SKX_SU_Tools_IDs.rb


I'm attaching a Poll to let you register your vote.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: [code] (beta) Sketchup::Tools helper methods

    Postby Dan Rathbun » Sat Mar 26, 2011 11:04 pm

    | This extension adds an ID hash to the Sketchup::Tools class, along
    | with methods to get information from the hash, concerning Sketchup
    | Tool String names and Tool Integer IDs for native tools.
    |
    | This extension adds an ACTION hash to the Sketchup::Tools class, along
    | with methods to get information from the hash, concerning Sketchup
    | native (and ONLY native,) Tool arguments for Sketchup::send_action().
    | (Before you say I'm missing action Strings... remember this is the
    | Sketchup::Tools class, and only TOOL actions are in this hash.)
    |
    | * Neither hash contains toolnames, IDs or action_strings for RubyTools !!
    |
    |
    | Where possible the query Class methods are independant of the active_model
    | and the active_tool, except for method id_to_tool_name() WHEN the id is
    | one of the shared ids:
    | 21126 shared by: 'SketchCSTool' & 'ComponentCSTool'
    | 21013 shared by: 'ComponentTool', 'PasteTool' & '3DTextTool'
    | In these cases, we try to guess the context using the active_model
    | and active_tool, in order to choose a String name to return.
    | (We cannot just ask the hash for the keyname with a given id, as there
    | are multiple keys in the hash with that Integer ID value.)
    |
    |
    | CLASS METHODS ADDED:
    |
    | Sketchup::Tools::action_string_valid?( action_string ) >> Boolean
    |
    | Sketchup::Tools::id_to_action_string( tool_id ) >> String
    |
    | Sketchup::Tools::id_to_tool_name( tool_id, model_arg ) >> String
    |
    | Sketchup::Tools::id_valid?( tool_id ) >> Boolean
    |
    | Sketchup::Tools::keys_for_action( action, empty ) >> Array
    |
    | Sketchup::Tools::list_actions() >> String
    |
    | Sketchup::Tools::list_actions_by_nickname() >> String
    |
    | Sketchup::Tools::list_tools() >> String
    |
    | Sketchup::Tools::tool_name_to_id( tool_name ) >> Integer
    |
    | Sketchup::Tools::tool_name_valid?( tool_name ) >> Boolean
    |
    | Sketchup::Tools::use( tool ) >> Boolean
    | * tool arg can be a String (or Symbol) tool_name or an Integer tool_id.
    |
    |
    | INSTANCE METHODS ADDED:
    | (These methods just call the Class methods of the same name, but
    | allow you to call them using a reference to a Tools instance.)
    |
    | toolstack = model.tools # Get a Tools collection instance.
    |
    |
    | toolstack.action_string_valid?( action_string ) >> Boolean
    |
    | toolstack.id_to_action_string( tool_id ) >> String
    |
    | toolstack.id_to_tool_name( tool_id ) >> String
    | * passes the toolstack's model as the 2nd arg to the Class method.
    |
    | toolstack.id_valid?( tool_id ) >> Boolean
    |
    | toolstack.keys_for_action( action, empty ) >> Array
    |
    | toolstack.list_actions() >> String
    |
    | toolstack.list_actions_by_nickname() >> String
    |
    | toolstack.list_tools() >> String
    |
    | toolstack.tool_name_to_id( tool_name ) >> Integer
    |
    | toolstack.tool_name_valid?( tool_name ) >> Boolean
    |
    | toolstack.use( tool ) >> Boolean
    | * tool arg can be a String (or Symbol) tool_name or an Integer tool_id.
    |
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: [code] (beta) Sketchup::Tools helper methods

      Postby driven » Sun Mar 27, 2011 12:20 pm

      Hi Dan,

      can't test it fully just now, but it loads fine (no conflicts) and the easy to figure out bits work on the mac. (i.e. 'list this')

      If you wrote test's, I'll run them as well...

      cheers

      john
      0
      learn from the mistakes of others, you may not live long enough to make them all yourself...

      driven 
      PluginStore Author
      PluginStore Author
       

      Re: [code] (beta) Sketchup::Tools helper methods

      Postby Jim » Sun Mar 27, 2011 5:50 pm

      I voted for the module name which requires the least typing.

      I think Sketchup should be avoided as it's a Google-maintained namespace.
      0
      Hi

      Jim 
      Global Moderator
       

      Re: [code] (beta) Sketchup::Tools helper methods

      Postby driven » Sun Mar 27, 2011 6:37 pm

      Jim wrote:I voted for the module name which requires the least typing.

      I think Sketchup should be avoided as it's a Google-maintained namespace.


      and I have suapi.rb already installed, I think it's your version, Jim.

      john
      0
      learn from the mistakes of others, you may not live long enough to make them all yourself...

      driven 
      PluginStore Author
      PluginStore Author
       

      Re: [code] (beta) Sketchup::Tools helper methods

      Postby Dan Rathbun » Sun Mar 27, 2011 11:27 pm



      I entered a temporary vote for Sketchup::Tools, just because I had it written this way, and so I can see the poll results as they come in.

      Jim wrote:I voted for the module name which requires the least typing.

      I think Sketchup should be avoided as it's a Google-maintained namespace.

      THESE methods really are helper methods for developer's, that don't really add any new functionality, to the Tools class.. which is why I questioned if they belonged, specifically, in the Sketchup::Tools API class.

      Although the use() IS a functional method, .. it's really just a wrapper for the Sketchup.send_action() method, (so does not actually add new functionality.)

      I got sick of having to look up the send action strings, and the fact that in many cases, those string arguments do not "jive" with the tool name strings. So this is the inspiration for the "nickname" arguments to my use() method, where you can just type use('Look') and not need to remember that the send action string is really "selectTurnTool:"

      It is nice to have the use() method as an instance method, but that can be achieved thru a mixin module, so it can be added to anyone's module or class.
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: [code] (beta) Sketchup::Tools helper methods

        Postby Dan Rathbun » Sun Mar 27, 2011 11:37 pm

        driven wrote: and I have suapi.rb already installed, I think it's your version, Jim.

        Now the SUAPI module, is a namespace I myself have used in the past for developer helper utilities, both unpublished, and some I've shared.

        The suapi.rb script does not exactly use the SUAPI outer (toplevel,) namespace module.

        That script was written by Remi Goux, and uses the class namespaces SUAPIHelpMenu and SUAPIHelpMenuExtension, (both of which violate a rule I strongly believe in, .., that only Ruby Base classes should be defined at the toplevel.)

        The script also makes changes to the Ruby classes Class and Module which I personally do not care for.

        Now.. that does not mean Remi's ideas are not valid.. only that there is a better implementation, which is html help menus (in a WebDialog or the Help Instructor.)

        Anyway.. what suapi.rb does, need not be done each time Sketchup loads... so the script could be changed to generate a html help menu document, and only run periodically to update the help document.

        Regardless... this script (or one similar,) would best also be wrapped in a submodule of the SUAPI toplevel module,.. likely SUAPI::HelpMenu and it's extension instance reference would be a local or constant declared in that namespace.

        The creation of a SketchupExtension subclass is totally unneeded, so his class SUAPIHelpMenuExtension goes away. (Not to mention that it's frivolous, as it's defined at the bottom of the file that it itself registers as an extension. By the time Sketchup registers the extension, the code has already loaded, so checking|unchecking a box in the Preferences will have no effect.)
        0
          I'm not here much anymore. But a PM will fire email notifications.
          User avatar
          Dan Rathbun 
          PluginStore Author
          PluginStore Author
           

          Re: [code] (beta) Sketchup::Tools helper methods

          Postby Dan Rathbun » Mon Mar 28, 2011 1:19 am


          I am a bit unsure also, of using the SKX namespace. IF the SKX namespace and it's subnamespaces are for extending and patching the Google namespace objects only ?

          EDIT: Bulk of this post moved to new topic:
          SKX: Purpose and Philosophy

          So... given the above philosophy...(if you agree,) do my developer tool utilites belong in the SKX namespace?
          0
          Last edited by Dan Rathbun on Tue Mar 29, 2011 10:35 pm, edited 2 times in total.
            I'm not here much anymore. But a PM will fire email notifications.
            User avatar
            Dan Rathbun 
            PluginStore Author
            PluginStore Author
             

            Re: [code] (beta) Sketchup::Tools helper methods

            Postby Dan Rathbun » Mon Mar 28, 2011 1:38 am

            So I am kind of teetering between Sketchup::Tools and SUAPI::Tools, leaning toward SUAPI::Tools (and changed my vote to that for now...)

            .. and I set the poll so anyone can change their vote (anytime.)
            0
              I'm not here much anymore. But a PM will fire email notifications.
              User avatar
              Dan Rathbun 
              PluginStore Author
              PluginStore Author
               

              Re: [code] (beta) Sketchup::Tools helper methods

              Postby driven » Mon Mar 28, 2011 1:43 am

              I voted for SKX once so I'll stick by that...

              * John, did you notice that the command lister script I wrote was wrapped in module SUAPI ?
              no, I just ran a quick test between other things, haven't had a read yet...

              also the suapi.rb I use is highly modified (using yours and Jim's past advice), is wrapped in a version of Jim's nset(weddialog) and I only occasionally load it from Ruby Console when I chasing Mac clashes.

              cheers for all your efforts

              john
              0
              learn from the mistakes of others, you may not live long enough to make them all yourself...

              driven 
              PluginStore Author
              PluginStore Author
               

              Re: [code] (beta) Sketchup::Tools helper methods

              Postby thomthom » Tue Mar 29, 2011 12:57 pm

              I say SKX as I avoid touching the default Ruby and SketchUp namespaces at all costs. You never know what Google might add to them.
              0
              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund
              User avatar
              thomthom 
              PluginStore Author
              PluginStore Author
               

              Re: [code] (beta) Sketchup::Tools helper methods

              Postby Dan Rathbun » Tue Mar 29, 2011 9:13 pm

              What do you (and anyone,) have to say about the purpose of the SKX namespace (as I discuss in this topic: SKX: Purpose and Philosophy.)
              0
                I'm not here much anymore. But a PM will fire email notifications.
                User avatar
                Dan Rathbun 
                PluginStore Author
                PluginStore Author
                 

                Re: [code] (beta) Sketchup::Tools helper methods

                Postby Dan Rathbun » Tue Mar 29, 2011 11:06 pm

                BTW.. ThomThom I just today stumbled upon your "extension" for Tool ID constants. (Which in my mind is actaully extending the Ruby Base class Object, by defining global constants within the Object namespace.)

                Personally... I do not care for global constants, and they are not the correct Ruby way of handling these type of constants. The global constants in the SU API come from C programmers, who are used to most all constants being global.
                The Ruby way is to put tool constants in a Tools namespace (in our case, the Sketchup::Tools namespace.)

                I much prefer my way of having a Constant ID hash, whose keys are the bonafide tool names.

                Using any constant from a Library namespace, is easy in Ruby, just create a local var or local constant, within your own namespace, that references the actaul constant:
                Code: Select all
                module SuchAndSoforth

                  id = Sketchup::Tools::ID

                  tools = Sketchup.active_model.tools

                  if tools.active_tool_id == id['3DTextTool']
                    # do something
                  end

                end
                The other Ruby way to to put constants in little mixin modules, that are mixed into custom namespace(s).

                AND.. my reasons for creating the tool ID hash, is the same as yours. I need to workaround the Mac tool name bug. Also I do not agree Pecan that the tool ids will change. Perhaps true that the menu ids would change if we mess with the menus.. so don't. If this is true, messing with the menus will break Sketchup.send_action() on PC when integer args are used, (which can be avoided by converting numerics to strings, even on PC.)

                So I feel that Sketchup::Tools is the correct namespace for the constant ID hash, but perhaps not the "helper" methods, which I'm leaning toward putting in the SUAPI module.
                0
                  I'm not here much anymore. But a PM will fire email notifications.
                  User avatar
                  Dan Rathbun 
                  PluginStore Author
                  PluginStore Author
                   

                  Re: [code] (beta) Sketchup::Tools helper methods

                  Postby Dan Rathbun » Fri Dec 21, 2012 3:39 am

                  Pardon my multiple posts... but it helps me "talk' things out, somewhat like a journal, where I can see a record of my thoughts as they evolve. (Whether or not anyone reads them, or cares.)
                  0


                  Last bumped by Dan Rathbun on Fri Dec 21, 2012 3:39 am.
                    I'm not here much anymore. But a PM will fire email notifications.
                    User avatar
                    Dan Rathbun 
                    PluginStore Author
                    PluginStore Author
                     

                    SketchUcation One-Liner Adverts

                    by Ad Machine » 5 minutes ago



                    Ad Machine 
                    Robot
                     



                     

                    Return to Skx Extension Library

                    Who is online

                    Users browsing this forum: No registered users and 1 guest

                    Visit our sponsors: