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

    Sketchup View origin

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 3 Posters 1.7k 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.
    • A Offline
      Anton_S
      last edited by

      http://www.filesanywhere.com/FS/M.aspx?v=8a6d688f5a9aa7a6aa9e

      I want to get the origin of view, relative to screen coordinates

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

        Viewport:

        classname : "AfxFrameOrView80u"
        ControlType : "ControlType.Pane"
        LocalizedControlType: "pane"
        Name: ""
        AutomationId: "59648"

        I'm not here much anymore.

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

          @dan rathbun said:

          Viewport:

          classname : "AfxFrameOrView80u"
          ControlType : "ControlType.Pane"
          LocalizedControlType: "pane"
          Name: ""
          AutomationId: "59648"

          Really interesting, what do i do with that?

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

            @anton_s said:

            Really interesting, what do i do with that?

            You were asking about making system calls.

            Use the info to find the view window. Once you have it's handle, you can request it's position on the screen.

            see this thread for examples:

            [Code] Win32 Moving/Showing/Hiding Toolbars and Dialogs

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • D Offline
              driven
              last edited by

              This script, by Matthew Scarpino, [written initially for PC's] gives the true design window on my mac.

              Is this what you want, or does SU-PC draw toolbars in view?

              "Automating Sketchup" by Mat is a great book...

              john

              view = Sketchup.active_model.active_view
              
              # Determine the size of the design window
              h = view.vpheight.to_s;
              w = view.vpwidth.to_s
              
              # Display the window dimensions
              puts "Window dimensions; " + w + ", " + h
              
              # Display the locations of the four corners
              puts "Upper left; " + view.corner(0)[0].to_s + ", " + 
                 view.corner(0)[1].to_s
              puts "Upper right; " + view.corner(1)[0].to_s + ", " + 
                 view.corner(1)[1].to_s
              puts "Bottom left; " + view.corner(2)[0].to_s + ", " + 
                 view.corner(2)[1].to_s
              puts "Bottom right; " + view.corner(3)[0].to_s + ", " + 
                 view.corner(3)[1].to_s
                 
              # Find the location of the window's center
              center = view.center
              
              # Display the coordinates of the window's center
              puts "Center; " + center[0].to_s + ", " + center[1].to_s 
              
              # Screen coordinates
              origin = view.screen_coords [0,0,0]
              puts "Origin; " + origin[0].to_f.to_s + ", " + origin[1].to_f.to_s
              
              # Find out how many units a five-pixel line should take
              size = view.pixels_to_model 50, [0, 0, 0]
              puts "Size of a 50-pixel line at the origin; " + size.to_s
              

              learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                @driven said:

                This script, by Matthew Scarpino, [written initially for PC's] gives the true design window on my mac.

                On Windows view.corner always return's the corners relative to view origin.
                So, view.corner(0) always return's [0,0], view.corner(1)[0] gives the view.width, view.corner(2)[1] return's the height. View.center returns [width/2, height/2]. From these, there is no way of knowing the Sketchup view origin relative to actual, screen coords.

                What I wan't is the Windows API or some other Function(s) that would give me the hwnd to Sketchup viewport. The Windows API Function FindWindow only works at finding the handles to the windows. It can't find the handle to a panel, button, icon or other stuff, but only to a window. Since viewport is a panel, FindWindow function wouldn't be able to get its handle.

                If I got the handle to viewport, I could then use GetWindowRect(hwnd, rect) method to get 1st and last corners of viewport in actual screen coordinates.

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

                  @dan rathbun said:

                  Use the info to find the view window. Once you have it's handle, you can request it's position on the screen.

                  Sketchup View is not a Window. I tried getting its handle by using function FindWindow.call(className, 0) but got 0. Then tried testing on toolbar dialogs. When toolbar was a child window (or not embeded into SU), I could get its handle, but when it was embedded into SU, FindWindow function returned 0. So, the FindWindow function doesn't works at finding handles to the panels, or 'ControllType.Pane'

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

                    Rightnow, I get the hwnd to viewport like that:

                    MyTool
                      def onMouseEnter(view)
                        p = 0.chr*8
                        GetCursorPos.call(p)
                        cp = p.unpack('ll')
                        @viewport_hwnd = GetWindowFromPoint.call(cp[0], cp[1])
                        rect = 0.chr*16
                        GetWindowRect.call(@viewport_hwnd, rect)
                        @viewport_rect = rect.unpack("l*")
                      end
                    end
                    
                    Sketchup.active_model.select_tool(MyTool.new)
                    

                    Not a good way. I would only be able to get vieport handle, once mouse enters the view.

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

                      @anton_s said:

                      @dan rathbun said:

                      Use the info to find the view window. Once you have it's handle, you can request it's position on the screen.

                      Sketchup View is not a Window.

                      EVERYTHING you see on the screen, in Microsoft Windows, IS a window. A button, an edit box, a static text label, a checkbox, ... ALL of them are a window, but their style does not have a resizable frame or a caption bar, like a application window or a dialog (which are also a window.)

                      @anton_s said:

                      I tried getting its handle by using function FindWindow.call(className, 0) but got 0.

                      FindWindow does NOT find embedded child windows, only toplevel windows.

                      You have to get the handle for the Sketchup Application window (the parent window,) then use that in
                      view_window_handle = FindWindowEx.call(parent_window_handle,0,"AfxFrameOrView80u",0)

                      Then use GetWindowRect using the view_window_handle.

                      I'm not here much anymore.

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

                        @dan rathbun said:

                        EVERYTHING you see on the screen, in Microsoft Windows, IS a window. A button, an edit box, a static text label, a checkbox, ... ALL of them are a window, but their style does not have a resizable frame or a caption bar, like a application window or a dialog (which are also a window.)

                        You have to get the handle for the Sketchup Application window (the parent window,) then use that in
                        view_window_handle = FindWindowEx.call(parent_window_handle,0,"AfxFrameOrView80u",0)

                        Thank you really much!!!, That should help!!!! 😄

                        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