Reverse operation of view.screen_coords
-
I added some 'ruby' tags to make it clearer...
I hope this is not ALL of the code...
Have you set theview
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....... -
@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.
-
@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
-
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. -
Though, at 2:30 it's hard to process these thigns...
-
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,
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
-
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
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
-
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 useadd_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...
-
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
-
Do the same thing but do not change the target ?
Advertisement