assafius Posted September 20, 2012 Posted September 20, 2012 Hey all, I want to lisp something that checks whether a given point is within the current viewport or not. Anybody has any idea ? Thanks. Quote
Lee Mac Posted September 20, 2012 Posted September 20, 2012 Consider the following functions: [color=GREEN];; On Screen-p - Lee Mac[/color] [color=GREEN];; Returns T if the given point is visible in the active viewport.[/color] ([color=BLUE]defun[/color] LM:OnScreen-p ( p [color=BLUE]/[/color] c h v ) ([color=BLUE]setq[/color] c ([color=BLUE]trans[/color] ([color=BLUE]getvar[/color] 'viewctr) 1 0) h ([color=BLUE]/[/color] ([color=BLUE]getvar[/color] 'viewsize) 2.0) v ([color=BLUE]list[/color] ([color=BLUE]*[/color] h ([color=BLUE]apply[/color] '[color=BLUE]/[/color] ([color=BLUE]getvar[/color] 'screensize))) h) ) ([color=BLUE]apply[/color] '[color=BLUE]and[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]<[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]-[/color] c v) p ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] c v))) ) [color=GREEN];; Viewport Extents - Lee Mac[/color] [color=GREEN];; Returns two WCS points describing the lower-left and[/color] [color=GREEN];; upper-right corners of the active viewport.[/color] ([color=BLUE]defun[/color] LM:ViewportExtents ( [color=BLUE]/[/color] c h v ) ([color=BLUE]setq[/color] c ([color=BLUE]trans[/color] ([color=BLUE]getvar[/color] 'viewctr) 1 0) h ([color=BLUE]/[/color] ([color=BLUE]getvar[/color] 'viewsize) 2.0) v ([color=BLUE]list[/color] ([color=BLUE]*[/color] h ([color=BLUE]apply[/color] '[color=BLUE]/[/color] ([color=BLUE]getvar[/color] 'screensize))) h) ) ([color=BLUE]list[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]-[/color] c v) ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] c v)) ) Quote
CheSyn Posted October 10, 2013 Posted October 10, 2013 (defun c:test ( / c r h w ul lr) (setq c (getvar 'viewctr)) (setq r (getvar 'screensize)) (setq h (/ (getvar 'viewsize) 2)) (setq w (* h (/ (car r) (cadr r)) ) ul (list (- (car c) w) (+ (cadr c) h)) lr (list (+ (car c) w) (- (cadr c) h)) ) (princ) ) Lee, I have used the above in conjunction with (ssget "_c" ul lr), but am curious why you used the trans function (UCS to WCS)? Is this just a form of error trapping? Quote
Lee Mac Posted October 10, 2013 Posted October 10, 2013 but am curious why you used the trans function (UCS to WCS)? Because the VIEWCTR system variable is expressed relative to the active UCS and I wanted the points returned by the function to be expressed relative to WCS. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.