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

    [Code] YARC – yet another ruby console

    Scheduled Pinned Locked Moved Developers' Forum
    22 Posts 4 Posters 3.7k Views 4 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.
    • thomthomT Offline
      thomthom
      last edited by

      @dan rathbun said:

      But there is still a problem with new height being remembered, both during the session and on restart. (It's like the height is hard-coded.)

      A new position, is not remembered during the session, but only on the next restart.

      Yes, it's an annoying WebDialog thing. If you close and reopen the webdialog within a session it doesn't remember the new position or size until the next session. 😞

      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

        @dan rathbun said:

        @dan rathbun said:

        Updated again, to ver 0.6.2, fixed the location and sizing of the WebDialog. (It now remembers where it the user puts it and it's size.)

        Actually it seems.. there are still a few issues with positioning:

        ...

        Well, because of the state of the API Dictionary.. I can no longer remember what is bugged and what is not!

        @unknownuser said:

        (http://forums.sketchucation.com/viewtopic.php?f)":2mfzj5er]Haven't checked it out, but on PC the position is stored between sessions, but not within sessions. If you make a webdialog, close it, then open it again it doesn't remember the last position - only the last position from last session.

        I haven't noticed because I am using Win32API calls to control where my Console is (.. I guess I gave up on Sketchup doing it. We can only wait so long for the vendor to fix bugs.)

        I'm not here much anymore.

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

          There is a way around this issue.. but I hate it. It's not best practice.

          You create a NEW instance each time the WD is opened, and abandon the old instance when it's closed.
          You'll lose any info and snippet links I think.

          I'm not here much anymore.

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

            So instances remember it... I see. They read the last position when the WebDialog initializes.
            Good point about the Win32API, for my WebDialog wrapper in TT_Lib I can add that. ..though OSX only... creating new instance isn't ideal in many of my cases because I want to preserve the content throughout the session. 😕

            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:

              ... creating new instance isn't ideal in many of my cases because I want to preserve the content throughout the session. 😕

              Yepper... you (and Aerilius,) would have to write to a log, and restore it on open.

              Actually, Aerilius is already saving the commands... he could just iterate them, and re-eval them to restore the output.
              And perhaps the snippets are already saved in a "snippet" directory ??

              I'm not here much anymore.

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

                Here's ver 0.6.1 with all the mods below added in for the "ae_Console/Console.rb" and "ae_Console/Console.htm" files.

                Updated again, to ver 0.6.2, fixed the location and sizing of the WebDialog.

                Updated again to ver 0.6.3 (It REALLY now remembers where it the user puts it and it's size. We let Sketchup do the work here.)
                !! Closing the dialog will clear it contents, and wipe out command snippets !!

                ae_Console_0_6_3.rbz
                ae_Console_0_6_3.zip


                Add class variables to hold the various singleton instance objects:

                @@console_dlg = nil
                @@command  = nil
                @@topmenu  = nil
                @@menuitem = nil
                
                

                (see bottom of post...)

                The open instance method should be named create and return a reference to the newly created UI::WebDialog instance:

                
                    (OSX)? @console_dlg.show_modal ; @console_dlg.show
                    return @console_dlg
                  end
                
                

                Then the instance open method should be:

                
                  def open
                    dlg = @console_dlg
                    if OSX
                      dlg.visible? ? dlg.bring_to_front() ; dlg.show_modal()
                    else # WIN
                      dlg.visible? ? dlg.bring_to_front() ; dlg.show()
                    end
                  end
                
                

                And the class method AE::Console.open()

                
                  def self.open(instance)
                    if @@console_dlg.nil? # nil if not yet instanced.
                      @@console_dlg = instance.method(;create).call # also opens it.
                    else
                      # The WebDialog instance exists, just open it.
                      instance.open()
                    end
                  end
                
                

                Lastly, I always suggest putting the "Run Once" block inside your namespace.
                (at the bottom of the file...) and the file_loaded() inside that block to prevent multiple entries in the $loaded_files array.
                (Actually, file_loaded() will not insert duplicates, but .. why call a method if you don't have to?)

                
                unless file_loaded?(File.basename(__FILE__))
                  $old_stdout = $stdout if !$old_stdout # in case you want to turn off traces
                  $stdout = AE;;Console.new
                  $stderr = $stdout # trap error displays as well
                  @@command = UI;;Command.new("Ruby Console (WebDialog)"){
                    self.open($stdout)
                  }
                  # Menu
                  @@topmenu = UI.menu("Window")
                  @@menuitem = @@topmenu.add_item(@@command)
                
                  file_loaded(File.basename(__FILE__))
                end
                
                end # class Console
                
                end # module AE
                
                

                Then you can (your choice,) provide class getter methods for singleton objects, that make sense. Ie, references that some other organizer script, might need a handle to:

                
                  # Provide a handle to the command, in case
                  # some other script wants to add it to a toolbar.
                  #
                  def self.command
                    @@command
                  end
                
                

                I'm not here much anymore.

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

                  Updated again to ver 0.6.3

                  (It REALLY now remembers where it the user puts it and it's size. We let Sketchup do the work here.)

                  !! Closing the dialog will clear it contents, and wipe out command snippets !!
                  So use minimize, instead of close, if you wish to keep these things.

                  See second post for d/l

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    Anton_S
                    last edited by

                    @dan rathbun said:

                    
                    > unless file_loaded?(File.basename(__FILE__))
                    > ...
                    > file_loaded(File.basename(__FILE__))
                    > 
                    

                    I recommend putting the whole __FILE__ instead of a File.basename(__FILE__). That way you would eliminate same filenames that are in different folders.

                    EX:
                    Plugins/Anton_Lib/core.rb

                    that statement would be true
                    ` unless file_loaded?(File.basename(FILE))

                    ...
                    file_loaded(File.basename(FILE))end`
                    Plugins/TT_Lib/core.rb

                    that statement would be false, preventing vital parts to be called
                    ` unless file_loaded?(File.basename(FILE))

                    ...
                    file_loaded(File.basename(FILE))end`

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

                      @anton_s said:

                      I recommend putting the whole FILE instead of a File.basename(FILE). That way you would eliminate same filenames that are in different folders.

                      +1

                      I have adopted the same pattern myself. Just using the filename is not a unique ID - full path is. It doesn't even have to be a filename you feed file_loaded - just any unique string.

                      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

                        Yup we've talked a bit about this before. (I didn't change what he had in his code. I thot it might be too far off topic.)

                        I've posted a new topic on this subject:
                        [ Code ] custom file_loaded() and file_loaded?()

                        @Anton_S: I sent you a personal edition via PM, check your inbox.

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          Anton_S
                          last edited by

                          yep, sure

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            Aerilius
                            last edited by

                            @anton_s said:

                            I recommend putting the whole __FILE__

                            That's very reasonable. I'll fix it.

                            I just wanted to let you all know that I'm working on improvements (esp. the snippets should have been saved over sessions) but I'm a bit busy at the moment. I'll publish a next version when I'm ready.

                            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