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

    Window handle from process

    Scheduled Pinned Locked Moved Developers' Forum
    37 Posts 5 Posters 3.3k Views 5 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.
    • A Offline
      Alienizer
      last edited by

      @dan rathbun said:

      While Sketchup starts up, and is processing the rubies in the Plugins and Tools folders, the UI is not yet finalized. The menus and toolbars are not built until all rubies that modify or create toolbars have been processed.

      Is there a way to "wait" until SK is loaded? I'm not using the title bar caption to find the window, I'm using Process.pid and iterate all windows to match the pid.

      I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

        @alienizer said:

        Is there a way to "wait" until SK is loaded?

        Not exactly. (I've been working on a utility to do just that. Not yet happy with it.)

        On Mac it may be easier, as it does not open a new blank model until after processing the rubies. (On Windows, a new blank model is opened, before processing the startup scripts.)

        A workaround that scripters use is the UI.start_timer block.
        However that can be defeated if any other script has a LoadError. The modal "LoadError" dialog pops up, and you never know how long it will take for the user to read and then dismiss the dialog.

        I'm not here much anymore.

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

          One way that seem to work for me now is...

          Using the code to find the SK window using the pid, get the window text, and if =~ /SketchUp/i then you have the right one, otherwise, set the window handle to nil and when your ruby code gets called for whatever reason, test if the window handle is nil, and it it is, re-get it again, then continue execution.

          So far, this way has worked for me all night, running 3-5 instances of SKP, and running them using direct, shortcuts, skp docs, via an exe and all. It worked even when other ruby script has errors.

          I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

            What happens if a user has the Custom Toolbars plugin installed, and the "Sketchup" toolbar is visible and floating?

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              Can't you can simply 'assemble' the current SKP's Sketchup window's top bar 'displayed text' from Sketchup.is_pro? and Sketchup.active_model.title - ''=='Untitled' ?. Then test a window with that exact same 'name' ?
              I know, what if the user has two 'Untitled' SKP's open? Just shoot him! [or post an error message and exit].
              OR perhaps even pre-test the current SKP with if Sketchup.active_model.path=='' then insist on it being named/saved before your tool is run ?
              I know they could still have two SKPs open from different folders which could have the same 'title'... but now I am getting tired 😒

              TIG

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

                @@Alan

                Are you working on a free or paid plugin?

                Do you want to get the current Ruby (Sketchup) process' application window from the Ruby side, or the C-side ??

                I'm not here much anymore.

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

                  @dan rathbun said:

                  @@Alan Are you working on a free or paid plugin?

                  Neither! But if I can make something usefull, it will be free. I'm kind of learning right now, until I'm good enough to give something.

                  @dan rathbun said:

                  Do you want to get the current Ruby (Sketchup) process' application window from the Ruby side, or the C-side ??

                  Either way is fine. I only need to know this to set the parent window of my dll forms. So if ruby knows it, I can pass it along to my dll. But if I can get it directly from my dll, that's good too.

                  I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

                    @alienizer said:

                    I only need to know this to set the parent window of my dll forms.

                    I wonder the hWndParent param is optional in most of those window create functions.

                    If a Thread (of a Process) creates a window, where the parent is not specified, does it default to the TopWindow of the Process, in this case the Sketchup application window ??
                    .. or does the Desktop become the parent ??

                    When a Process is destroyed (and all it's Threads,) does the system automatically destroy all the windows that the Process created ??
                    .. I think the answer is NO because I was able to make a UI.messagebox popup window, appear from within a Sketchup::AppObserver onQuit() callback, that stayed displayed, even after all the other Sketchup windows (incl. the main window,) had been destroyed.
                    The system did not like it, and I think the BugSplat! window popped up after dismissing the messagebox. I did, of course, log it as a bug for the Sketchup::AppObserver class. (Actually the bug is that Sketchup does not wait until the onQuit callbacks have completed, before shutting down.)

                    I'm not here much anymore.

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

                      It default to the desktop window if a parent is nil. By setting the parent window (SKP), you are sure to get the WM_QUIT message when SKP is closed. hWndParent is optional, but again, the desktop becomes the parent if hWndParent is nil.

                      I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

                        @tig said:

                        Can't you can simply ....

                        After having explained that using the title bar text is problematic (and subject to a bug while loading on Windows,) you still advise doing it?

                        Again, the "Untilted" string is NOT the same on all language localizations, and some contain unicode characters.

                        It's also possible that a SKP filename could contain unicode characters.

                        Then you add two more situations that can "throw a shoe in the works".


                        @unknownuser said:

                        **, the designer and original implementor of C++":37wih2kn]

                        "If you think it's simple, then you have misunderstood the problem"

                        [floatr:37wih2kn]Did you really really say that? - Bjarne Stroustrup's C++ FAQ[/floatr:37wih2kn]

                        I'm not here much anymore.

                        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