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

    Get Toolbars from ObjectSpace

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 3 Posters 665 Views 3 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

      I can get a collection of UI::Toolbar objects using the following code:

      toolbars = [] ObjectSpace.each_object(UI::Toolbar) {|t| toolbars.push(t)}

      But, in some plugins, the Toolbar is created in a module namespace:

      module JF tb = UI::Toolbar.new("Hello Toolbar") end

      And these do not show up when using the ObjectSpace code. Is there a way to find them also?

      Hi

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        Hmm, that's not what I'm seeing. The tool I'm working on, I create the toolbar from within my module. But it comes up just fine with your code, slightly modified to show names

        ObjectSpace.each_object(UI::Toolbar) {|t| puts t.name}

        I guess it probably won't show them if they are created after SU loads though, since they are not created in SU.

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

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

          You are right - my bad, I see the Toolbar also. Just an oversight on my part.

          However, when I do the show/hide on a Ruby Toolbar, it looks like a new Toolbar object is created each time, so multiple Toolbars of the same name (but different id's) are being created using UI.toolbar("name") to access the Toolbar.

          UI.toolbar("Test").object_id returns a new value each time it is called.

          5.times {p UI.toolbar("Jim").object_id}
          86540730
          86540700
          86540670
          86540640
          86540610
          

          Hi

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

            @jim said:

            However, when I do the show/hide on a Ruby Toolbar, it looks like a new Toolbar object is created each time, ...

            This is a Windows thing. For instance each time the Console window is shown (then hidden,) then shown again, a new Window instance is created. (It's handle changes.) Since toolbars are also window objects, they'll have the same behavour.

            I'm not here much anymore.

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

              Thanks Dan.

              I was seeing a lot of what looked like unnecessary Toolbars objects being created in ObjectSpace after using UI.toolbar("name"), but I see they go away after a GC.start - so I guess this is a non-issue.

              Hi

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

                Ok, I see it now.

                If I create a Toolbar like so:

                cmd = UI::Command.new("Command") { do_something } UI.toolbar("Do Something").add_item(cmd)
                or
                UI::Toolbar.new("Do Something").add_item(cmd)

                The Toolbar does not show up in ObjectSpace (although does exist in SketchUp,) presumably because there is no reference to it?

                If I do it this way:

                cmd = UI::Command.new("Command") { do_something } tb = UI.toolbar("Do Something") tb.add_item(cmd)

                The Toolbar does show in ObjectSpace, even when tb is a local var that goes out of scope.

                Hi

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

                  Yea that's weird. I never recommend using any constructor without making sure that there is a reference to it for later use.

                  We are still lacking (auto-generated) collections for many types of things, incl. toolbars.

                  Either the collection object would be "held" by the UI module (ie: UI::ToolbarSet,) or "held" by the class itself, and accessed via a class method.

                  I'm not here much anymore.

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

                  Advertisement