sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Request: Command line input plugin

    Scheduled Pinned Locked Moved Plugins
    22 Posts 9 Posters 1.8k Views 9 Watching
    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.
    • J Offline
      Jim
      last edited by

      Are you sub-classing, or aliasing and redefining the class methods?

      Hi

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        @jim said:

        or aliasing and redefining the class methods?

        You are correct.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @thomthom said:

          @jim said:

          or aliasing and redefining the class methods?

          You are correct.

          I just hope that my version doesn't conflict.. ie: the constructor chain would not be broken, ...and visa versa.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @dan rathbun said:

            @thomthom said:

            @jim said:

            or aliasing and redefining the class methods?

            You are correct.

            I just hope that my version doesn't conflict.. ie: the constructor chain would not be broken, ...and visa versa.

            My intent was to just insert an intercepting hook - without further disrupting the objects. Just to collect the data that SketchUp doesn't expose.
            However, I'm far away from releasing it, as it would need lots more work, error catching and testing. Not sure if it ever will be released. Depends if it can be made without interfering - as meddling with base classes is something I generally prefer to stay away from. It's been mainly an proof of concept.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • fredo6F Offline
              fredo6
              last edited by

              It is relatively easy to catch all menu text and proc (via aliasing #add_item).

              It seems impossible to catch the proc for the UI::Command class. The proc argument is actually only passed in the .new construction. But very strangely, UI::Command does not seem to have a regular initialize constructor method like all Ruby classes.

              For instance, in the following code, the method initialize will NEVER be called

              
              class UI;;Command
                 def initialize
                     puts "Fake command initialize"
                 end
              end
              
              UI;;Command.new
              Error; #<ArgumentError; (eval);156;in `new'; wrong number of arguments (0 for 1)>
              (eval);156
              (eval);156
              
              

              This may explain why there has been problem with UI::Commands (the grey out menu issue), because if there is no constructor, there is no garbage too!

              Fredo

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @unknownuser said:

                It seems impossible to catch the proc for the UI::Command class. The proc argument is actually only passed in the .new construction. But very strangely, UI::Command does not seem to have a regular initialize constructor method like all Ruby classes.

                It's possible. 😄 I can send you the snippet if you want.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • fredo6F Offline
                  fredo6
                  last edited by

                  @thomthom said:

                  It's possible. 😄 I can send you the snippet if you want.

                  I just realized that UI::Command is a kind of fake class object factory. new is simply a class method, not an instance constructor (therefore there is no initialize method in that class).

                  Then, it is simple to trap both menus and commands

                  
                  class Sketchup;;Menu
                     alias_method ;add_item_orig6, ;add_item
                     def add_item(text, &proc)
                        MyModule.register_menu(self, text, proc)
                        add_item_orig6(text) { proc.call }
                     end
                  end	
                  
                  class UI;;Command
                     class << self
                        alias_method ;new_orig6, ;new
                     end	
                     def self.new(text, &proc)
                        cmd = new_orig6(text) { proc.call }
                        MyModule.register_menu(cmd, text, proc)
                        cmd
                     end
                  end	
                  
                  
                  

                  Assuming you register the command and menu object, text and proc via your own method MyModule.register_menu.

                  Fredo

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    <span class="syntaxdefault"><br />class </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Command<br />  <br />  alias </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">tt_old_new </span><span class="syntaxkeyword">;new<br /></span><span class="syntaxdefault">  private </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">tt_old_new<br /><br />  </span><span class="syntaxcomment"># @since 0.1.0<br /></span><span class="syntaxdefault">  def new</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">*</span><span class="syntaxdefault">args</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault">block </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    obj </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> tt_old_new</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">*</span><span class="syntaxdefault">args</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">&</span><span class="syntaxdefault">block </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    obj</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">proc</span><span class="syntaxkeyword">=,</span><span class="syntaxdefault"> block </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    obj<br />  end<br />  <br />end </span><span class="syntaxcomment"># class << UI;;Command<br /><br /><br /></span><span class="syntaxdefault">class UI</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Command <br />  <br />  </span><span class="syntaxcomment"># @since 0.1.0<br /></span><span class="syntaxdefault">  attr_reader</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">proc </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  <br />  </span><span class="syntaxcomment"># @param [Proc] value<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment"># @return [Proc]<br /></span><span class="syntaxdefault">  </span><span class="syntaxcomment"># @since 0.1.0<br /></span><span class="syntaxdefault">  def proc</span><span class="syntaxkeyword">=(</span><span class="syntaxdefault"> value </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">proc </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> value<br />  end<br />  protected </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">proc</span><span class="syntaxkeyword">=<br /></span><span class="syntaxdefault">  <br />end </span><span class="syntaxcomment"># class UI;;Command <br /></span><span class="syntaxdefault"> </span>
                    

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      I don't think I like overriding the inherited proc() method that comes down from Kernel (thru Object.)

                      We already have naming convention established in that class, ie set_validation_proc

                      I would suggest for setter, instead:
                      set_proc(&block) or set_command_proc(&block)

                      the getter:
                      get_proc(&block) or get_command_proc(&block)

                      and the getter for the validation proc:
                      get_validation_proc

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        Good point Dan. I've not checked such conflicts yet and one of the reasons I'd not released the code before.

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jim
                          last edited by

                          So what's going to happen when you guys start aliasing each other's aliased methods?

                          Hi

                          1 Reply Last reply Reply Quote 0
                          • thomthomT Offline
                            thomthom
                            last edited by

                            Nuffin? Just a chain of calls?

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 Reply Last reply Reply Quote 0
                            • J Offline
                              Jim
                              last edited by

                              @thomthom said:

                              Nuffin? Just a chain of calls?

                              Maybe. I don't know, I'm asking.

                              Hi

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

                              Advertisement