• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Custom Dynamic Component Functions = Ruby links

Scheduled Pinned Locked Moved Developers' Forum
30 Posts 9 Posters 12.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    Dan Rathbun
    last edited by 8 Apr 2012, 04:19

    Yep.. what Jim said.. however, his example can also be written in Ruby (on PC using the Win32ole.so extension, which many users have already installed to their "Plugins" directory, or they have it in their full Ruby library directory, if they have installed the full Ruby edition, and pushed it's lib path into the $LOAD_PATH array.)

    So to use the "SendKeys" example (which seems to be a common function name in many of the programming languages available, from low-level C, to the higher level languages such as VB, C# etc.)

    Goal: To provide a cross-platform Ruby method, named SendKeys() that sends keystrokes to the Sketchup application.

    1) Choose a community namespace. As an example, lets say (for argument's sake,) this will go within the SKX project namespace, and beneath that we'll wrap it within a GUI submodule.

    module SKX; end # make sure outer namespace is defined
    
    module SKX;;GUI
    
      if RUBY_PLATFORM =~ /(darwin)/i # on Mac
    
        def self.SendKeys(keystring)
          # the Mac code using AppleScript
        end
    
      else # on Windows
    
        def self.SendKeys(keystring)
          # the WIN code using Windows Scripting Host
        end
    
      end
    
    end # module SKX;;GUI
    

    This is the one file approach, which may not be the best, because it makes everyone update their file(s) even when a revision is made for a certain platform. I show it to make an important point about Ruby, in that it is a dynamic language that can be defined during runtime. (In this example, we would define the same method, two different ways, depending upon which platform it will run on.)

    The separate file approach may be better. Where a user chooses an install package for the proper platform, so that their "Plugins/SKX/GUI" directory, only contains the Ruby object definitions for their platform.

    To use this proposed feature, scripters would simply require the proper module definition file:

    require("SKX/GUI/keyboard.rb") SKX::GUI::SendKeys("require_all 'c:/plugins'"+SKX::GUI::KBD::ENTER)

    P.S.: Locally within a custom module or class, a scripter can create 'nickname' shortcut references that point at long nested qualified objects, like:
    gui = SKX::GUI @kbd = SKX::GUI::KBD
    or even:
    ENTER = SKX::GUI::KBD::ENTER
    So don't be afraid of well organized, multi-nested module namespaces.
    Also.. if say, the KBD submodule was just a mixin module of constants, scripters could, if they wished, mix it into their module(s) or class(es) by inclusion:

    module Author;;FancyPlugin
      require("SKX/GUI/keyboard.rb")
      include(SKX;;GUI;;KBD)
      # now all constants in KBD module, are mixed in.
    end
    

    💭

    I'm not here much anymore.

    1 Reply Last reply Reply Quote 0
    • J Offline
      jeff hammond
      last edited by 8 Apr 2012, 17:10

      the wording in AppleScript is keystroke.

      keystroke "v" (for the v key)
      keystroke "V" (is for shift + v)
      keystroke "V" using command down (for shift-cmmd-v or paste in place)

      likewise, you can also do menu items:

      click menu item "Outer Shell" of menu "Tools"

      dotdotdot

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 8 Apr 2012, 22:28

        @unknownuser said:

        the wording in AppleScript is keystroke.

        Yea.. and what is the point your making ??

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • J Offline
          jeff hammond
          last edited by 9 Apr 2012, 00:19

          @dan rathbun said:

          @unknownuser said:

          the wording in AppleScript is keystroke.

          Yea.. and what is the point your making ??

          just saying that ruby could write the macro script. (but I'm pretty sure I'm not thinking about doing this the right way 😉 )

          like if a user turns on the macro recorder (.rb plugin) then does a series of commands they want to automate then click 'stop ecording'(or whatever).. ruby will then write the commands used in a scpt file in the format of my previous post.. then puts it in the services folder so the user now has a sketchup macro without leaving sketchup or manually typing up an AppleScript.

          edit. oh, I was also just saying it's 'keystroke' in applescript as opposed to 'sendkeys'

          dotdotdot

          1 Reply Last reply Reply Quote 0
          • B Offline
            bmike
            last edited by 9 Apr 2012, 01:23

            Jeff,

            Very much hope you do a thread on how to use services in Mac. I've moved back to Mac after a too long trip through various PCs and am very curious about Services, AppleScript, and Automator. Anything you put together for Services in SketchUp would be appreciated.

            mike beganyi design + consulting llc

            1 Reply Last reply Reply Quote 0
            • J Offline
              jeff hammond
              last edited by 9 Apr 2012, 16:35

              @bmike said:

              Jeff,

              Very much hope you do a thread on how to use services in Mac. I've moved back to Mac after a too long trip through various PCs and am very curious about Services, AppleScript, and Automator. Anything you put together for Services in SketchUp would be appreciated.

              I'm going to do a thread today on it.
              I think I'll keep it super basic at first then the thread can evolve from there into the other possibilities.

              dotdotdot

              1 Reply Last reply Reply Quote 0
              • B Offline
                bmike
                last edited by 9 Apr 2012, 16:38

                @unknownuser said:

                @bmike said:

                Jeff,

                Very much hope you do a thread on how to use services in Mac. I've moved back to Mac after a too long trip through various PCs and am very curious about Services, AppleScript, and Automator. Anything you put together for Services in SketchUp would be appreciated.

                I'm going to do a thread today on it.
                I think I'll keep it super basic at first then the thread can evolve from there into the other possibilities.

                Great!
                I'll keep an eye out for it!

                mike beganyi design + consulting llc

                1 Reply Last reply Reply Quote 0
                • J Offline
                  jeff hammond
                  last edited by 9 Apr 2012, 19:50

                  ok. I made a little macro example in this thread:

                  http://forums.sketchucation.com/viewtopic.php?f=15&t=44503

                  .

                  dotdotdot

                  1 Reply Last reply Reply Quote 0
                  • halroachH Offline
                    halroach
                    last edited by 10 Nov 2016, 10:18

                    @tig said:

                    Please read this http://cfcl.com/twiki/bin/view/Projects/SketchUp/DA_Adding_Functions
                    which covers how to add your own 'custom functions' to a DC. ...

                    The link seems not to work anymore (It actually looks like an endless loop of DNS forwarding!?)
                    Anywhere else where the info may be found?

                    FlexTools - Super Quick Windows, Doors, Slats...

                    1 Reply Last reply Reply Quote 0
                    • halroachH Offline
                      halroach
                      last edited by 20 Nov 2016, 12:44

                      Seems like the site is back up and running! The link about "Adding Functions" seems to have changed to this:
                      http://cfcl.com/twiki/bin/view/Projects/SketchUp/Cookbook/DA_Adding_Functions

                      FlexTools - Super Quick Windows, Doors, Slats...

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 2 / 2
                      • First post
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement