### Author Topic: Grdraw a point  (Read 165 times)

0 Members and 1 Guest are viewing this topic.

#### Grrr1337

• Bull Frog
• Posts: 355
##### Grdraw a point
« on: September 04, 2017, 01:50:42 pm »
Hi guys,

Code - Auto/Visual Lisp: [Select]
`; Grdraw a point; Display variables that might worth exploring: (mapcar 'getvar '(viewsize viewctr screensize)); (* (/ (cadr (getvar 'screensize)) YourScreenResolution2ndNumber YourPhysicalScreenHeight)) somewhere Kent Cooper explained; (GrdrawPoint (getpoint "\nPick:") nil nil nil nil) ; (GrdrawPoint (getpoint "\nPick:") 1 nil nil 10); (GrdrawPoint '(0. 0. 0.) -3 nil 3 10)(defun GrdrawPoint ( p c d n idx / i L )  (cond     ( ((lambda (x) (and (listp x) (= 3 (length x)) (vl-every 'numberp x))) p)             ; pointp      (or (eq 'INT (type c)) (setq c -1))                                                 ; c - colour      (or (numberp d) (setq d (* 10 (/ (getvar 'viewsize) (cadr (getvar 'screensize)))))) ; d - radius size      (or (and (eq 'INT (type n)) (< 0 n)) (setq n 12))                                   ; n - number of increments      (or (and (eq 'INT (type idx)) (< 0 n)) (setq idx 1))                                ; idx - highlighting index       (redraw) (setq i 0) (repeat n (setq L (cons (polar p (setq i (+ i (/ (* 2. PI) n))) d) L))) ; (/ (* 2. PI) n) is the angle increment      (repeat idx        (grvecs (cons c (apply 'append (mapcar 'list L (cons (last L) L))))) ; This technique was demonstrated by Roy - Thank you!        ; (grdraw (polar p (* PI -0.25) (* d 2.)) (polar p (* PI 0.75) (* d 2.)) c)        ; (grdraw (polar p (* PI -0.75) (* d 2.)) (polar p (* PI 0.25) (* d 2.)) c)        (mapcar           '(lambda (a) (apply 'grdraw (reverse (cons c (mapcar '(lambda (x) (polar p (* PI x) (* d 2.))) a)))))          '((-0.25 0.75)(-0.75 0.25)) ; '((-0.25 0.75)(-0.75 0.25)(1. 0.)(0.5 -0.5))        ); mapcar      ); repeat      L    )  ); cond); defun GrdrawPoint`

You may ask where I use this: I had one grread routine where I had to draw the basepoint (for reference), but also it was constantly changing its location - hence I had to entmake and entdel a POINT entity, which was way buggy'n'uncomfortable to do in a relatively big code.
It also contains some useless comments (sorry bout that).
Hopefully you'll find it useful in your codes...

BTW I don't think this thread belongs to "show your stuff" section, since its more related to lisp coding.

#### MP

• Seagull
• Posts: 16985
• brevity != aggression
##### Re: Grdraw a point
« Reply #1 on: September 04, 2017, 02:21:41 pm »
Good to see you exploring different ways to exploit lisp for tool making. Feel free to lift ideas from this post from yesteryear. Cheers.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.

#### Grrr1337

• Bull Frog
• Posts: 355
##### Re: Grdraw a point
« Reply #2 on: September 04, 2017, 03:19:14 pm »
Good to see you exploring different ways to exploit lisp for tool making. Feel free to lift ideas from this post from yesteryear. Cheers.

Ahh, thanks for sharing - I didn't expected anything related!
I was searching before, but couldn't find anything - perhaps of the lack of important keyword(s): grdraw / grvecs.
So I guess it would be nearly impossible to find something similar without help, since 95% of the threads related to point(s) are about dealing with vertices / xyz coordinates / trans / bla-bla...

BTW I thought, that I could play a bit more, so the geometry could replicate the one to the PDMODE variable, but it would be a bit too much (considering my task is already solved).

#### Lee Mac

• Seagull
• Posts: 11780
• AutoCAD 2015 Windows 7 London, England
##### Re: Grdraw a point
« Reply #3 on: September 04, 2017, 06:17:51 pm »
Nice one Grrr1337 - I see you are also catching the gr* bug: the use of such functions quickly becomes addictive.

This is how I used to approach this particular task:
Code - Auto/Visual Lisp: [Select]
`;; grX  -  Lee Mac ;; p - [lst] WCS point at which to display 'X';; s - [int] size of point (in pixels);; c - [int] ACI colour of point;; Returns supplied WCS point. (defun LM:grx ( p s c / -s r q )    (setq r (/ (getvar 'viewsize) (cadr (getvar 'screensize)))          q (trans p 0 3)         -s (- s)    )    (grvecs        (list c            (list -s -s) (list s  s) (list -s (1+ -s)) (list (1- s)  s) (list (1+ -s) -s) (list s (1-  s))            (list -s  s) (list s -s) (list -s (1-  s)) (list (1- s) -s) (list (1+ -s)  s) (list s (1+ -s))        )        (list            (list r  0. 0. (car  q))            (list 0. r  0. (cadr q))            (list 0. 0. r  0.)            (list 0. 0. 0. 1.)        )    )    p)`

e.g.

(LM:grX (getpoint "\nPick a point: ") 5 3)

#### Grrr1337

• Bull Frog
• Posts: 355
##### Re: Grdraw a point
« Reply #4 on: September 05, 2017, 04:50:21 am »

Nice one Grrr1337 - I see you are also catching the gr* bug: the use of such functions quickly becomes addictive.

Indeed, I like to implement them wherever I can!

This is how I used to approach this particular task:

Thats a very pretty and confusing (for me) code and I assume you wrote it on-the-fly.
Thanks for posting it, I'll try to learn something from it, as grvecs is my hardest function to use from the gr* functions.