Jump to content

Recommended Posts

Posted

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.

Posted

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))
)

  • 1 year later...
Posted

(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?

Posted
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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...