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

    Reverse operation of view.screen_coords

    Scheduled Pinned Locked Moved Developers' Forum
    30 Posts 5 Posters 744 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.
    • thomthomT Offline
      thomthom
      last edited by

      Ah, yes! Of course - no need to pick anything. I forgot that the ray contained a point that could be used directly.

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

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

        Two brains are better than one [at least our combined IQs add up to around the average!!]
        πŸ˜†

        TIG

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

          I've already determined that my brain is on timeshare lease... πŸ˜’

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

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

            TIG and thomthom,

            Do you guys ever sleep!!??
            You gave me a plenty of assignment for the weekend; to digest all that you posted.

            For your info, I am attempting to model a 'plan viewer' for blueprints which will become framework for architectural components

            Thanks guys

            John

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

              "Sl-eep"..? πŸ˜•

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

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

                Just finished reading up on view.pickray method and ran TIG's sample code. At first glance it should have worked but does not. In executing each line, I find that p0 and p1 return same value as camera eye position. See Ruby Console responses below:

                p0=view.pickray(0,0)[0] Point3d(3255.11, 1479.16, 8761.61) p1=view.pickray(view.vpwidth,0)[0] Point3d(3255.11, 1479.16, 8761.61) p2=view.pickray(0,view.vpheight)[0] Point3d(3255.11, 1479.16, 8761.61) p3=view.pickray(view.vpwidth,view.vpheight)[0] Point3d(3255.11, 1479.16, 8761.61) cam=Sketchup.active_model.active_view.camera #<Sketchup::Camera:0x7ce5de0> cam.eye Point3d(3255.11, 1479.16, 8761.61) cam.target Point3d(3255.11, 1479.16, 127.281) cam.up Vector3d(0, 1, 0)

                How could this be? I thought I understood pickray method but NOT

                Off the topic note: where can I find instruction on how to annotate posting w/ codes, images, smiles, etc ...

                John

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

                  I added some 'ruby' tags to make it clearer...

                  I hope this is not ALL of the code...
                  Have you set the view and so on earlier ?
                  IF so... you don't use
                  cam=Sketchup.active_model.active_view.camera
                  but
                  cam=view.camera
                  ???
                  My code is a working example.......

                  TIG

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

                    @jpark said:

                    Off the topic note: where can I find instruction on how to annotate posting w/ codes, images, smiles, etc ...

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

                    Notice how the line "BBCode is ON" has a link ??

                    It leads you to a user guide for the code tags.

                    Most of these usable tags have toolbar button "inserters" already set up for you to use. You just click the button, it inserts the tag. and positions the cursor between the tags so you can type text (or paste text,) into them.

                    I'm not here much anymore.

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

                      @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 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        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 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          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 Reply Last reply Reply Quote 0
                          • TIGT Offline
                            TIG Moderator
                            last edited by

                            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 Reply Last reply Reply Quote 0
                            • J Offline
                              jpark
                              last edited by

                              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 Reply Last reply Reply Quote 0
                              • TIGT Offline
                                TIG Moderator
                                last edited by

                                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 Reply Last reply Reply Quote 0
                                • J Offline
                                  jpark
                                  last edited by

                                  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 Reply Last reply Reply Quote 0
                                  • TIGT Offline
                                    TIG Moderator
                                    last edited by

                                    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 Reply Last reply Reply Quote 0
                                    • inteloideI Offline
                                      inteloide
                                      last edited by

                                      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 Reply Last reply Reply Quote 0
                                      • Dan RathbunD Offline
                                        Dan Rathbun
                                        last edited by

                                        Do the same thing but do not change the target ?

                                        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