TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mailmaverick on March 31, 2014, 04:36:22 AM

Title: Coordinates of current Zoom Window
Post by: mailmaverick on March 31, 2014, 04:36:22 AM
How to get min and max coordinates of current window in ModelSpace ? Note that (getvar "EXTMAX") and (getvar "EXTMIN") gives max and min coordinates of extents of the drawing but my requirement is current zoomwindow .

Title: Re: Coordinates of current Zoom Window
Post by: roy_043 on March 31, 2014, 04:48:06 AM
You can use these sys. variables to calculate those points:
VIEWCTR
VIEWDIR
VIEWSIZE
VIEWTWIST
SCREENSIZE

And searching this forum for these vars will no doubt lead to code samples.
Title: Re: Coordinates of current Zoom Window
Post by: mailmaverick on March 31, 2014, 05:01:34 AM
Thanks a lot.
Title: Re: Coordinates of current Zoom Window
Post by: ymg on March 31, 2014, 12:12:50 PM
Try this:

Code - Auto/Visual Lisp: [Select]
  1. (defun ve (/ vc vh sz vw vq ll ur)
  2.   ;; = View Extents                                               ;
  3.   (setq vc (getvar 'viewctr)
  4.         vh (getvar 'viewsize)
  5.         sz (getvar 'screensize)
  6.         vw (* vh (/ (car sz) (cadr sz)))
  7.         vq (mapcar '/ (list vw vh) '(2 2))
  8.         ll (mapcar '- vc vq) ; Lower Left  corner of current view ;
  9.         ur (mapcar '+ vc vq) ; Upper Right corner of current view ;
  10.   )
  11.   (list ll ur)
  12. )
  13.  
Title: Re: Coordinates of current Zoom Window
Post by: Lee Mac on March 31, 2014, 06:08:35 PM
Pretty much the same method as ymg:

Code - Auto/Visual Lisp: [Select]
  1. ;; Viewport Extents  -  Lee Mac
  2. ;; Returns two WCS points describing the lower-left and
  3. ;; upper-right corners of the active viewport.
  4.  
  5. (defun LM:ViewportExtents ( / c h v )
  6.     (setq c (trans (getvar 'viewctr) 1 0)
  7.           h (/ (getvar 'viewsize) 2.0)
  8.           v (list (* h (apply '/ (getvar 'screensize))) h)
  9.     )
  10.     (list (mapcar '- c v) (mapcar '+ c v))
  11. )
Title: Re: Coordinates of current Zoom Window
Post by: ymg on March 31, 2014, 06:50:52 PM
lee,

I like the:

Code: [Select]
(apply '/ (getvar 'screensize))
Neat!

ymg
Title: Re: Coordinates of current Zoom Window
Post by: Kerry on March 31, 2014, 07:13:06 PM
That looks rather MP'ish.
Title: Re: Coordinates of current Zoom Window
Post by: ymg on March 31, 2014, 07:55:02 PM
Kerry,

Quote
That looks rather MP'ish.

Don't know if you are referring to the bit of code up there.

It could be because I don't know where it came from, had it lying in the library.

ymg
Title: Re: Coordinates of current Zoom Window
Post by: Kerry on March 31, 2014, 10:07:25 PM
I was referring to the snippet
Code - Auto/Visual Lisp: [Select]
  1. (apply '/ (getvar 'screensize))

I agree it's  very neat.
Title: Re: Coordinates of current Zoom Window
Post by: MP on March 31, 2014, 10:21:59 PM
That looks rather MP'ish.

Wow Kerry, good eye. From a little over 9 years ago (last line of logic):

Code: [Select]
(defun VPCords ( )
    (   (lambda (offset)
            (   (lambda (viewctr)
                    (list
                        (mapcar '- viewctr offset)
                        (mapcar '+ viewctr offset)
                    )
                )
                (getvar "viewctr")
            )
        )
        (   (lambda (halfHeight aspectRatio)
                (list
                    (* halfHeight aspectRatio)
                    halfHeight
                )
            )
            (* 0.5 (getvar "viewsize"))
            (apply '/ (getvar "screensize"))
        )
    )
)

That said, once you achieve competence in LISP the odds one's approach will appear similar to another is rather high, so I doubt Lee lifted it from me. To wit, odds are Reni or Tony wrote something using a construct like I penned above 142 years before I did.
Title: Re: Coordinates of current Zoom Window
Post by: Kerry on March 31, 2014, 10:35:33 PM
No suggestion of 'lifting'. Just an acknowledgment of the frugality of that snippet.

I recognise better than most the likelihood of similarity ... I've been looking at this language for a long time.

added:
Regarding the 142 years  .. I'm older than Lisp so I call 'poetic licence' :)
Title: Re: Coordinates of current Zoom Window
Post by: MP on March 31, 2014, 10:45:28 PM
(http://i53.tinypic.com/1218r4m.jpg)

Added: Do I get points for being the same age as LISP?
Title: Re: Coordinates of current Zoom Window
Post by: Kerry on March 31, 2014, 10:53:32 PM

of course ... anyone who survived the 60's gets bonus points in my book.
Title: Re: Coordinates of current Zoom Window
Post by: MP on March 31, 2014, 11:08:26 PM
(http://ic.pics.livejournal.com/scapegoat1989/2550323/37515/37515_original.gif)
Title: Re: Coordinates of current Zoom Window
Post by: Bhull1985 on April 01, 2014, 07:17:46 AM
weirdest/funniest off topic posts ive read in a long time, kudos :) (and the gifs)







p.s.
....old people, hehe! To make this more relevant you all aren't so old, my grandfather was programming military systems in fortran in the 50's and 60's. You were yipper-snappers then I bet :D



p.s.s. I think old is just another word for "experienced"
Title: Re: Coordinates of current Zoom Window
Post by: snownut2 on April 01, 2014, 07:47:47 AM
....old people, hehe! To make this more relevant you all aren't so old, my grandfather was programming military systems in fortran in the 50's and 60's.

I had a yr of FORTRAN in college, thank god for IBM

There's one old college text book wouldn't be worth 10 cents today. (why do I still have it.)
Title: Re: Coordinates of current Zoom Window
Post by: Bhull1985 on April 01, 2014, 08:24:47 AM
Memories? :)
Title: Re: Coordinates of current Zoom Window
Post by: hmspe on April 01, 2014, 08:47:38 AM
Memories.  Yes.  Hollerith cards.  IBM 370. Fortran.  T.A. who wrote 'goto' with slashed through the o's.  Business students in the study room in the dorm who struggled with basic math, and engineering students who would do their homework (in seconds) to get them to stop griping about how hard their homework was.... 
Title: Re: Coordinates of current Zoom Window
Post by: ymg on April 01, 2014, 01:22:19 PM
From Express Tools:

Code: [Select]
(ACET-GEOM-VIEW-POINTS)
Will return a list Lower Left and Upper Right as 3d points.

Code: [Select]
((3737.61 598.711 0.0) (10595.1 3058.81 0.0))
Timing for 1 000 000 repetitions:
Quote
ACET                      Elapsed: 1.528 sec.
ve                          Elapsed: 9.859 sec.
LM:ViewportExtents  Elapsed: 9.813 sec.
vpcords                  Elapsed: 9.891 sec.
Title: Re: Coordinates of current Zoom Window
Post by: MP on April 01, 2014, 01:40:58 PM
express tools, meh
Title: Re: Coordinates of current Zoom Window
Post by: ymg on April 01, 2014, 01:46:42 PM

Quote
express tools, meh

 :lmao: Have to agree with you, it is a mixed bag.

ymg
Title: Re: Coordinates of current Zoom Window
Post by: hmspe on April 01, 2014, 02:42:51 PM
But it is very simple code:

Code: [Select]
(defun acet-geom-view-points ( / a b c d x )
 (setq b (getvar "viewsize")
       c (car  (getvar "screensize"))
       d (cadr (getvar "screensize"))
       a (* b (/ c d))
       x (trans (getvar "viewctr") 1 2)
       c (list (- (car  x) (/ a 2.0))
               (- (cadr x) (/ b 2.0))
               0.0
         )
       d (list (+ (car  x) (/ a 2.0))
               (+ (cadr x) (/ b 2.0))
               0.0
         )
       c (trans c 2 1)
       d (trans d 2 1)
 )
 (list c d)
)
Title: Re: Coordinates of current Zoom Window
Post by: ymg on April 01, 2014, 03:04:35 PM
hmspe,

no need to define it if you have Express Tool installed.

Believe it is part of aceutil.fas

All you need is:
Code: [Select]
(setq vext (ACET-GEOM-VIEW-POINTS))
ymg
Title: Re: Coordinates of current Zoom Window
Post by: hmspe on April 01, 2014, 05:11:33 PM
ymg,

I understand, but there are those who either do not have express tools or will not use express tools because they cannot be locally maintained or because they can't be sure everyone has them installed.
Title: Re: Coordinates of current Zoom Window
Post by: danallen on April 01, 2014, 05:42:24 PM
or on Bricscad!
Title: Re: Coordinates of current Zoom Window
Post by: Lee Mac on April 01, 2014, 06:15:30 PM
lee,

I like the:

Code: [Select]
(apply '/ (getvar 'screensize))
Neat!

ymg

Thanks ymg  :-)
Title: Re: Coordinates of current Zoom Window
Post by: ymg on April 02, 2014, 08:59:30 AM
@danallen,

Express Tools for Bricscad can be downloaded here: http://www.bricsys.com/common/applications/application.jsp?app=589 (http://www.bricsys.com/common/applications/application.jsp?app=589)

@hmspe,

I certainly do not advocate the use of acet for everything.  I was merely showing the possibilities.

As for the installed base, most everybody has them.

What is more of a problem is that documetation for them is kind of sparse,
plus some of the functions are less than ideal.  So your mileage may (will) vary.

ymg



Title: Re: Coordinates of current Zoom Window
Post by: Kerry on April 02, 2014, 09:03:16 AM
< ..>

What is more of a problem is that documentation for them is kind of sparse,
plus some of the functions are less than ideal.  So your mileage may (will) vary.

ymg

That covers the issue very well, I think.