TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: kraz on October 27, 2008, 12:32:14 AM
-
what are you called cad's screen? window?
anyway, i want to know current cad screen's 4 coordinate..or 2.
but the way that with viewctr, viewsize ....as following..is not good way for me.
##############################################################
(example)
(defun cur_screen_coo ( / scrsize viewsize viewctr width lx ly lz rx ry rz)
(setq scrsize (getvar "screensize")
viewsize (getvar "viewsize")
viewctr (getvar "viewctr")
)
(setq width (* (/ (nth 0 scrsize) (nth 1 scrsize)) viewsize))
(setq lx (- (nth 0 viewctr) (/ width 2))
ly (- (nth 1 viewctr) (/ width 2))
lz 0
rx (+ (nth 0 viewctr) (/ width 2))
ry (+ (nth 1 viewctr) (/ width 2))
rz 0
)
(list (list lx ly lz) (list rx ry rz))
)
##############################################################
there is many user's cad app windows...
and it is not return exactly.
-
Perhaps --
(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"))
)
)
)
-
wow...it's very nice....exactly return the current screen coords...
thanks...
-
the MP's lisp is very nice....
but i can not understand .... why it does...
Could you please explain the source with commentary ?
-
8-)
-
(http://www.theswamp.org/screens/mp/vpcords.png)
Let me know what part(s) you don't understand and I'll (try to) advise.
:)
-
Let me know what part(s) you don't understand and I'll (try to) advise.
What editor are you using? :?
-
What editor are you using? :?
For ascii matter ultra edit (http://www.ultraedit.com), for pixel dust paint shop pro (http://www.corel.com/servlet/Satellite/us/en/Product/1184951547051#versionTabview=tab0&tabview=tab0).
-
Just have to say I love reading the lists on this site... Just wish this sort of stuff would "come to me" when I sit down to do solve something!!!
-
I wonder why it return the correct coords..
offset = (list (* halfheight aspectRatio) halfheight)
what is it mean?
I can't understand the logic.. [aspectRatio * halfheight] hmm......
anyway.. I can't understand the Logic but I got the nice Logic...
thank you...
-
ah................... finally... I got it.
it is just EQUATION..
viewctr is centerpoint of current screen..
and offset.. it is absolute distance of x , y from centerpoint to corner of screen.
and then...(mapcar '- viewctr offset) (mapcar '+ viewctr offset)....
the logic is very easy...but the source is very difficult....
hmm... i was silly......
-
(http://www.theswamp.org/screens/mp/vpcords.png)
Let me know what part(s) you don't understand and I'll (try to) advise.
:)
Nice!!
-
As LAMBDA is a pending matter for me , I dig on the code and come with this other way to state it
(defun vp-coor ()
(setq screen-size (getvar "screensize"));_ Stores current viewport size in pixels (X and Y).
(setq screen-ratio ( / (car screen-size) (cadr screen-size)))
(setq view-size (getvar "viewsize"));_ Stores the height of the view in the current viewport. Expressed in drawing units.
(setq half-view-size ( * 0.5 view-size))
(setq view-ctr (getvar "viewctr"));_Stores the center of view in the current viewport. Expressed as a UCS coordinate.
(setq off-set (list ( * half-view-size screen-ratio) half-view-size))
(setq vp-cords ( list ( mapcar '- view-ctr off-set) ( mapcar '+ view-ctr off-set)))
)
Of course it maybe take a lot of recurses , but it can be a way to understand the LAMBDA function , also the variables shall be set to LOCAL .
-
ah................... finally... I got it ...
Glad you figured it out. :)
the logic is very easy...but the source is very difficult ...
Sorry. It was penned in a thread that challenged to solve that particular problem without using setq. Wasn't deliberately trying to make it obfuscated, tho I suppose the superfluous use of lambda can give that impression. (http://www.theswamp.org/screens/mp/blush.gif)
Nice!!
Thanks Mr.T. :)
-
Hi!
Thanks for this coding, but what if I want to get the farthest x coordinate to be sure to paste far enough to not be over something... I see the coord but I would like to use it in my code... I want to do a zoom extend in my lisp and then get the coord (x axis) and then paste my stuff at that coord (+ an offset). Is it possible to extract those coords in variable?
Thanks!
-
Super simple two variables EXTMAX and EXTMIN. (getvar 'extmax)