sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🔌 Smart Spline | Fluid way to handle splines for furniture design and complex structures. Download

    Reverse operation of view.screen_coords

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    30 貼文 5 Posters 1.4k 瀏覽 5 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • J 離線
      jpark
      最後由 編輯

      @dan rathbun said:

      There is a "hard to find" link on each message "POST A REPLY" page, in the right column, beneath the "Smilies" list.

      Now I'm enlightened 😍 Thanks Dan

      @tig said:

      I hope this is not ALL of the code...

      No this is an output of individual Ruby Console execution. This is my attempt to debug each line of your sample code to check each variable's current value. Programming is my hobby and I just picked up Sketchup and Ruby couple of months ago so I have a lot to learn.

      Back to pickray method - All screen postions (ie p0, p1, p2, and p3) return different value yet pickray method of these points return identical 3D point as camera eye position but with different vector. How come?

      John

      1 條回覆 最後回覆 回覆 引用 0
      • thomthomT 離線
        thomthom
        最後由 編輯

        eh.. TIG, I think we both did a brain-fart. We have to do a raytest - otherwise the ray will return a point which is based on the camera eye... because all pickray origin from the camera eye.

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

        1 條回覆 最後回覆 回覆 引用 0
        • thomthomT 離線
          thomthom
          最後由 編輯

          Though, at 2:30 it's hard to process these thigns...

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

          1 條回覆 最後回覆 回覆 引用 0
          • TIGT 離線
            TIG Moderator
            最後由 編輯

            Here's a much better version that uses planes, lines, vectors, and takes arguments to change panning from right/left and up/down etc - allowing a toolbar button set to be easily made...

            require 'sketchup.rb'
            ### Usage TIG.screenpan(1), where the argument can be either 1, -1, 2 or -2
            ### 1=right, -1=left, 2=up, -2=down
            ### make 4 'arrow' buttons in a toolbar using the 4 alternative commands.
            module TIG
                def self.screenpan(direction=1)
                    m = Sketchup.active_model
                    v = m.active_view
                    c0 = v.corner(0)
                    c1 = v.corner(1)
                    c2 = v.corner(2)
                    c = v.camera
                    e = c.eye
                    t = c.target
                    up = c.up
                    di = c.direction
                    pa = [e, di]
                    i0 = v.inputpoint(c0[0],c0[1]).position
                    i1 = v.inputpoint(c1[0],c1[1]).position
                    i2 = v.inputpoint(c2[0],c2[1]).position
                    p0 = Geom.intersect_line_plane([i0,di], pa)
                    p1 = Geom.intersect_line_plane([i1,di], pa)
                    p2 = Geom.intersect_line_plane([i2,di], pa)
                    vx = p0.vector_to(p1)
                    vy = p0.vector_to(p2)
                    case direction
                      when 1
                        c.set(e.offset(vx), t.offset(vx), up)
                      when -1
                        c.set(e.offset(vx.reverse), t.offset(vx.reverse), up)
                      when 2
                        c.set(e.offset(vy.reverse), t.offset(vy.reverse), up)
                      when -2
                        c.set(e.offset(vy), t.offset(vy), up)
                   end
                end
            end
            

            TIG

            1 條回覆 最後回覆 回覆 引用 0
            • J 離線
              jpark
              最後由 編輯

              TIG,

              It works great and I actually understood your program steps. Now I need to dig into reference material to create tool bars.

              Thanks for your help

              John

              1 條回覆 最後回覆 回覆 引用 0
              • TIGT 離線
                TIG Moderator
                最後由 編輯

                Insert this whole block of code inside the mIN 'module' near the beginning - between
                module TIG
                and
                def self.screenpan(direction=1)
                Then put the whole of the code in a file called 'TIG-screenpan.rb' in the Plugins folder and restart...
                Put your buttons icon .PNG files inside a subfolder in Plugins called 'TIG-screenpan'.
                Name then as shown, for small/large icons, for each of the 4 buttons, 8 PNGs in all...
                This is the menu code...

                ### menu
                unless file_loaded?(File.basename(__FILE__))
                  cmd1=UI;;Command.new('TIG.screenpan_RIGHT'){self.screenpan(1)}
                  cmd1.tooltip=('TIG.screenpan_RIGHT')
                  cmd1.status_bar_text=('TIG.screenpan_RIGHT; Pan RIGHT..')
                  cmd1.small_icon=File.join('TIG-screenpan', 'pan1-16.png')
                  cmd1.large_icon=File.join('TIG-screenpan', 'pan1-24.png')
                  cmd_1=UI;;Command.new('TIG.screenpan_LEFT'){self.screenpan(-1)}
                  cmd_1.tooltip=('TIG.screenpan_LEFT')
                  cmd_1.status_bar_text=('TIG.screenpan_LEFT; Pan LEFT..')
                  cmd_1.small_icon=File.join('TIG-screenpan', 'pan_1-16.png')
                  cmd_1.large_icon=File.join('TIG-screenpan', 'pan_1-24.png')
                  cmd2=UI;;Command.new('TIG.screenpan_UP'){self.screenpan(2)}
                  cmd2.tooltip=('TIG.screenpan_UP')
                  cmd2.status_bar_text=('TIG.screenpan_UP; Pan UP..')
                  cmd2.small_icon=File.join('TIG-screenpan', 'pan2-16.png')
                  cmd2.large_icon=File.join('TIG-screenpan', 'pan2-24.png')
                  cmd_2=UI;;Command.new('TIG.screenpan_DOWN'){self.screenpan(-2)}
                  cmd_2.tooltip=('TIG.screenpan_DOWN')
                  cmd_2.status_bar_text=('TIG.screenpan_DOWN; Pan DOWN..')
                  cmd_2.small_icon=File.join('TIG-screenpan', 'pan_2-16.png')
                  cmd_2.large_icon=File.join('TIG-screenpan', 'pan_2-24.png')
                  ###
                  toolbar=UI;;Toolbar.new('TIG.screenpan')
                  toolbar.restore if toolbar.get_last_state==TB_VISIBLE
                  toolbar.add_item(cmd1)
                  toolbar.add_item(cmd_1)
                  toolbar.add_item(cmd2)
                  toolbar.add_item(cmd_2)
                  sub=UI.menu('Tools').add_submenu("TIG.Screenpan...")
                  sub.add_item(cmd1)
                  sub.add_item(cmd_1)
                  sub.add_item(cmd2)
                  sub.add_item(cmd_2)
                end
                file_loaded(File.basename(__FILE__))
                ###
                

                [UNTESTED!]

                TIG

                1 條回覆 最後回覆 回覆 引用 0
                • J 離線
                  jpark
                  最後由 編輯

                  TIG

                  Once again, I thank you for your generous assistance ❗ 😄

                  With 1 minor correction, this is working as intended.

                  @unknownuser said:

                  sub=UI.menu('Tools').%(#FF0000)add_item

                  Changed add_item to add_submenu

                  This is the only line of code I did not fully understand

                  @unknownuser said:

                  unless file_loaded?(File.basename(FILE))

                  I know this is to make sure the plugin load once, but can you explain 'basename(FILE)'?

                  Moving onto to my next challenge, what method do I need to look at in order to display an area of image whose vertices are known (sort of like zoom window without maually selecting zoom area)

                  John

                  1 條回覆 最後回覆 回覆 引用 0
                  • TIGT 離線
                    TIG Moderator
                    最後由 編輯

                    Again.... untested stupid typo ! 😒
                    Sorry!
                    add_item adds a command directly to that menu
                    sub=...add_submenu adds a 'submenu' to that menu,
                    in which you can then use add_item...
                    I changed original in case others copy it... 😕

                    The system variable __FILE__ gives the full-path of each loading .rb script [fails if compiled as a .rbs!].
                    There are many 'File' methods, so if it is say
                    'C:/Program Files/Google/Google SketchUp 8/Plugins/xxx.rb'
                    File.basename(__FILE__) >>> 'xxx.rb'
                    and also
                    File.basename(__FILE__, '.*') >>> 'xxx'
                    File.extname(__FILE__) >>> '.rb'
                    File.dirname(__FILE__) >>> 'C:/Program Files/Google/Google SketchUp 8/Plugins'
                    etc etc...
                    Of course you can use it with and string that is a 'file-path' - like you'd get from an 'open' dialog etc...

                    I'll sleep on your last question...

                    TIG

                    1 條回覆 最後回覆 回覆 引用 0
                    • inteloideI 離線
                      inteloide
                      最後由 編輯

                      Hello,

                      I want to resurrect this topic ;o)

                      I'm looking for a way to align the model in the view to have the View.corner(0) align with the left bottom of viewport (screen).
                      I tried your code above, unsuccessfully : looks like the model is out of the viewport.

                      The idea would to write a script the slide the model, in top perpencidular view, from left to right, or from top to bottom, keeping current zoom.

                      Looks like my request is similar to the original request of this thread but, I cannot achieve what I want...

                      Does anybody have an idea ?

                      Thank you in advance.

                      Inteloide

                      Humanity will do a huge step when the IT professionals will understand that computers are tools...

                      1 條回覆 最後回覆 回覆 引用 0
                      • Dan RathbunD 離線
                        Dan Rathbun
                        最後由 編輯

                        Do the same thing but do not change the target ?

                        I'm not here much anymore.

                        1 條回覆 最後回覆 回覆 引用 0
                        • 1
                        • 2
                        • 2 / 2
                        • 第一個貼文
                          最後的貼文
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement