Author Topic: Using And as If  (Read 5932 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Using And as If
« Reply #15 on: January 04, 2018, 10:39:02 AM »
Probably off topic, but something like this is much more legible to me for picking multiple points.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ p1 p2)
  2.   (while (and (or p1 (setq p1 (getpoint "\nPick first point: ")))
  3.               (setq p2 (getpoint "\nPick next point: "))
  4.          )
  5.     (grdraw p1 p2 1)
  6.     (setq p1 p2)
  7.   )
  8.   (princ)
  9. )




Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Using And as If
« Reply #16 on: January 04, 2018, 10:47:16 AM »
Guys, you missed the point - my example was not about prompting user for a points, but to visualise how the evaluations work, based on the user input.
I just find getpoint function an easy way to return a value or nil (by using only the mouse).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Using And as If
« Reply #17 on: January 04, 2018, 11:04:56 AM »
Probably off topic, but something like this is much more legible to me for picking multiple points.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ p1 p2)
  2.   (while (and (or p1 (setq p1 (getpoint "\nPick first point: ")))
  3.               (setq p2 (getpoint "\nPick next point: "))
  4.          )
  5.     (grdraw p1 p2 1)
  6.     (setq p1 p2)
  7.   )
  8.   (princ)
  9. )
  • I like the grdraw...
  • You're creating a variable (allocating space in the stack) even if...You should strive to be more hygienic with variable creation.
  • Mine can be used in a loop to get points and build a list to be undone/unwrapped like the LINE command.
...

Guys, you missed the point - my example was not about prompting user for a points, but to visualise how the evaluations work, based on the user input.
I just find getpoint function an easy way to return a value or nil (by using only the mouse).
Yes, I know. But are you starting to get my point (ronjonp and I just took your thread away from you by discussing a better getpoint procedure -i.e. the `whys' have started)?

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Using And as If
« Reply #18 on: January 04, 2018, 11:17:42 AM »
Yes, I know. But are you starting to get my point (ronjonp and I just took your thread away from you by discussing a better getpoint procedure -i.e. the `whys' have started)?

Ok, I didn't wanted to go offtopic - you might find this one interesting:
Code - Auto/Visual Lisp: [Select]
  1. ; http://www.cadtutor.net/forum/showthread.php?102283-Getpoint-amp-repeat
  2. ; (getpoints nil "\n>>> Specify point: ")
  3. (defun getpoints ( p m ) (cond ((not (setq p (apply 'getpoint (append (if p (list p)) (if m (list m)))))) p) ((cons p (getpoints p m)))) )
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Using And as If
« Reply #19 on: January 04, 2018, 11:46:34 AM »
But what about the grdraw feature?

Code - Auto/Visual Lisp: [Select]
  1. (defun points (/ plst pt p1 sp cnt)
  2.   ;;===================================================================;
  3.   ;; Smadsen's function for getting points and generating a list of    ;
  4.   ;; points.                                                           ;
  5.   ;;===================================================================;
  6.   (cond ((setq pt (getpoint "\nStart point: "))
  7.          (setq plst (cons pt plst)
  8.                p1   pt
  9.                sp   pt
  10.                cnt  2)))
  11.   (while pt
  12.          (initget "Close")
  13.          (setq pt (getpoint p1 (strcat "\nGimme point no. " (itoa cnt) ": ")))
  14.          (cond ((vl-consp pt)(grdraw p1 pt 2)
  15.                 (setq plst (cons pt plst) p1 pt))
  16.                ((= pt "Close")(grdraw p1 sp 2)
  17.                 (setq pt sp plst (cons pt plst) pt nil))
  18.                )
  19.          (setq cnt (1+ cnt))
  20.          )
  21.   (reverse plst)
  22. )
  23.  
  24. (defun getpointy (pt / ans)
  25.   ;; This proced may be another one of SMadsen's proceds or my own spin-off.
  26.   ;; -i.e. Not sure wheret this came from.
  27.   (if (= cntr nil)
  28.     (setq cntr 1))
  29.   (cond
  30.     ((setq ans (if pt (getpoint pt "\nSpecify point: ")
  31.                  (getpoint "\nSpecify point: ")))
  32.      (cond ((and ans pt)
  33.             (setq PointList (cons pt PointList)
  34.                   cntr      (1+ cntr))
  35.             (grdraw pt ans 2)
  36.             )
  37.            )
  38.      (getpointy ans)
  39.      )
  40.     )
  41.   PointList
  42. )
  43.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Using And as If
« Reply #20 on: January 04, 2018, 11:52:41 AM »
But what about the grdraw feature?

That was just a recursive play.  :tongue2:
But I also keep Lee Mac's subfunction in my lisp archive aswell:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( )
  2.         (LM:getpoints "\nSpecify first point: " "\nSpecify next point <done>: ")
  3. )
  4.  
  5. ;; Get Points  -  Lee Mac
  6. ;; Returns a list of UCS points selected by the user
  7. (defun LM:getpoints ( msg0 msgN / rtn tmp )
  8.         (and (setq tmp (LM:catchapply 'getpoint (list msg0)))
  9.                 (setq rtn (list tmp))
  10.                 (while (setq tmp (LM:catchapply 'getpoint (list msgN (car rtn))))
  11.                         (mapcar
  12.                                 '(lambda ( a b ) (grdraw a b 3 1))
  13.                                 (setq rtn (cons tmp rtn))
  14.                                 (cdr rtn)
  15.                         )
  16.                 )
  17.         )
  18.         (redraw) (reverse rtn)
  19. )
  20.  
  21. ;; Catch Apply  -  Lee Mac
  22. ;; Applies a function to a list of parameters and catches any exceptions.
  23. (defun LM:catchapply ( fnc prm / rtn ) (if (not (vl-catch-all-error-p (setq rtn (vl-catch-all-apply fnc prm)))) rtn))
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Using And as If
« Reply #21 on: January 04, 2018, 12:02:22 PM »
But what about the grdraw feature?

That was just a recursive play.  :tongue2:
...

My getpointy is recursive...?

Awe (*sadface*)? You don't want mine in your archive?


...hey!? Why are you redrawing my screen (why are you changing my environment)?!

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Using And as If
« Reply #22 on: January 04, 2018, 12:17:38 PM »
But what about the grdraw feature?

That was just a recursive play.  :tongue2:
...

My getpointy is recursive...?

I was talking about mine in reply #18, as I've thought you asked why it doesn't include the grdraw feature.


Awe (*sadface*)? You don't want mine in your archive?

I'm not really in the need for such subfunction yet(and never was), I just kept Lee's one for reference.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Using And as If
« Reply #23 on: January 04, 2018, 12:34:06 PM »
My reply to your #18 (#19) was asking why you didn't include a grdraw feature in your `recursive play' -i.e. I thought we were building a feature list for a better getpoint procedure. -e.g. My reply (#19) included a recursive function that included a `grdraw feature' don't you want to keep it for reference? ...That's hypothetical, I already know you w/don't want mine for reference (or `never will').

Boy, are we ever off-topic. Having fun?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Using And as If
« Reply #24 on: January 04, 2018, 12:44:01 PM »
No offense, John - I was just sharing related stuff where you might be interested in.
But I think from reply #14 starts a different discussion that worths a new thread.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Using And as If
« Reply #25 on: January 04, 2018, 01:10:42 PM »
Grrr1337, you did not offend me by not liking me or my code. However you must have missed very important point(s) entirely (starting at reply #1) then, because many are of the same light. -i.e. "simple isn't bad".
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org