Author Topic: One up and why! (MyLine)  (Read 12565 times)

0 Members and 1 Guest are viewing this topic.

uncoolperson

  • Guest
Re: One up and why! (MyLine)
« Reply #15 on: August 23, 2006, 11:49:38 AM »
it gives the next poster the option of which way to continue the fun

anyone remember those choose your own adventure books?

LE

  • Guest
Re: One up and why! (MyLine)
« Reply #16 on: August 23, 2006, 11:51:04 AM »
Reply to the first post.

Code: [Select]
(defun MyLine  (/ cntr pt1 pt2)
  (setq cntr 1 ;; do not see the need of this variable
;; if it can be place as part of the
;; string prompt argument
;; of the GETPOINT function.
pt1
(getpoint
   (strcat
     "\nEnter point number "
     (rtos cntr 2 0) ;; wrong implementation/usage
      ;; if number is required here and it
      ;; is going to be an integer
      ;; then the ITOA function will be the best choice.
     " please: "
     )
   )
)
  (if pt1
    (progn
      (setq cntr (1+ cntr)) ;; again here if in advanced we know are
      ;; going to be two calls to
      ;; GETPOINT function - unnecessary
      (setq pt2 (getpoint pt1
  (strcat
    "\nEnter point number "
    (rtos cntr 2 0) ;; same as previous comment
    " please: "
    )
  )
    )
      )
    (progn
      (princ "\nYou have not entered a valid point; existing now.")
      (quit) ;; do not see very appropiate the use of QUIT
      )
    )
  (if pt2 ;; instead of using the QUIT function maybe will be better if
    ;; we use something like:
    ;; if (and pt1 p2) ...
    (command "_.line" pt1 pt2 "")
    (progn
      (princ "\nYou have not entered a valid point") ;; the message is not complete
      ;; it must mention that TWO points
      ;; are required.
      (quit) ;; better if we don't use it, and simple leave the above message
      ;; much cleaner with also including a (princ) at the end too.
      )
    )
  )

ronjonp

  • Needs a day job
  • Posts: 7529
Re: One up and why! (MyLine)
« Reply #17 on: August 23, 2006, 12:03:35 PM »
Here's my 2c.

Code: [Select]
;;
;; History:
;; 08.22.06 -- Se7en
;;
;; 2006.08.22 Tracey .. corrected User interface < Spelling >
;;
;; 2006.08.23 {AEST} kwb@theSwamp ..  documentation Update , reformat
;; 2006.08.23 {AEST} kwb@theSwamp .. add closing (princ)'s for less noise
;; 2006.08.23 Tracey ... added the c: to allow the user to use at the command line
;; 2006.08.23 DGC ... added recursive functionality (removed exiting quotes)
;; 2006.08.23 UnCoolPerson... added while, and associated fun. to keep DGC's idea in our lisp and not in the line command
;; 2006.08.23 ronjonp ... removed extra setq, replaced "command" with entmake, made all functions lowercase (OCD)

(defun c:myline (/ cntr pt1 pt2)
  (setq cntr 1
pt1
(getpoint
   (strcat "\nEnter point number "
   (rtos cntr 2 0)
   " please: "
   )
)
  )
  (while pt1
    (progn (setq cntr (1+ cntr)
pt2
      (getpoint
pt1
(strcat
  "\nEnter point number "
  (rtos cntr 2 0)
  " please: "
)
      )
   )
    )
    (if pt2
      (progn (entmake
       (list
(cons 0 "LINE")
(cons 10 pt1)
(cons 11 pt2)
       )
     )
     (setq pt1 pt2)
      )
      (progn (princ
       "\nYou have not entered a valid point; exiting now."
     )
     (setq pt1 nil)
      )
    )
    (princ)
  )
)
(princ)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: One up and why! (MyLine)
« Reply #18 on: August 23, 2006, 12:11:29 PM »
Code: [Select]
;;
;; History:
;; 08.22.06 -- Se7en
;;
;; 2006.08.22 Tracey .. corrected User interface < Spelling >
;;
;; 2006.08.23 {AEST} kwb@theSwamp ..  documentation Update , reformat
;; 2006.08.23 {AEST} kwb@theSwamp .. add closing (princ)'s for less noise
;; 2006.08.23 Tracey ... added the c: to allow the user to use at the command line
;; 2006.08.23 DGC ... added recursive functionality (removed exiting quotes)
;; 2006.08.23 UnCoolPerson... added while, and associated fun. to keep DGC's idea in our lisp and not in the line command
;; 2006.08.23 ronjonp ... removed extra setq, replaced "command" with entmake, made all functions lowercase (OCD)
;; 2006.08.23 T.Willey ... fixed the while statement (took out unnecessary stuff)

(defun c:myline (/ cntr pt1 pt2)
  (setq cntr 1
pt1
(getpoint
   (strcat "\nEnter point number "
   (rtos cntr 2 0)
   " please: "
   )
)
  )
  (while (setq cntr (1+ cntr)
pt2
      (getpoint
pt1
(strcat
  "\nEnter point number "
  (rtos cntr 2 0)
  " please: "
)
      )
   )
           (entmake
       (list
(cons 0 "LINE")
(cons 10 pt1)
(cons 11 pt2)
       )
     )
     (setq pt1 pt2)
    )
    (princ)
  )
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Re: One up and why! (MyLine)
« Reply #19 on: August 23, 2006, 01:21:37 PM »
Well, it's all nice & compact, but I prefer the option the (command .-line ... ) gives you and the personalization of the comments.
Although the way the code is manipulated in the last two posts are incredible.  I never new you could do stuff like that with some of those functions.  And thank you LE for putting in your comments of why you did what you did and how it's working.   Very Nice.  Keep going.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: One up and why! (MyLine)
« Reply #20 on: August 23, 2006, 03:01:07 PM »
Code: [Select]
;; History:
;; 08.22.06 -- Se7en
;;
;; 2006.08.22 Tracey .. corrected User interface < Spelling >
;;
;; 2006.08.23 {AEST} kwb@theSwamp ..  documentation Update , reformat
;; 2006.08.23 {AEST} kwb@theSwamp .. add closing (princ)'s for less noise
;; 2006.08.23 Tracey ... added the c: to allow the user to use at the command line
;; 2006.08.23 DGC ... added recursive functionality (removed exiting quotes)
;; 2006.08.23 UnCoolPerson... added while, and associated fun. to keep DGC's idea in our lisp and not in the line command
;; 2006.08.23 ronjonp ... removed extra setq, replaced "command" with entmake, made all functions lowercase (OCD)
;; 2006.08.23 T.Willey ... fixed the while statement (took out unnecessary stuff)
;; 2006.08.23 MP ... renamed vars to be self describing, and/or fit my
;;                      sensibilities (I know, subjective),
;;                   reformatted to expose logic (subjective x 2),
;;                   changed rtos calls to itoa,
;;                   eliminated redundant prompt defs by employing a
;;                      template technique (pmt),
;;                   puckettized entmake code,
;;                   sorry I've got one shot at this and am tied up
;;                      for the balance of the day as I just resigned
;;                      my job of 11 years. As you can well imagine LOTS
;;                      of tidying up to do.

(defun c:MyLine ( / i pmt pt1 pt2 )

    (setq
        i     1
        pmt  '(strcat "\nEnter point number " (itoa i) ": ")
        pt1   (getpoint (eval pmt))
    )
   
    (while
   
        (setq
            i   (1+ i)
            pt2 (getpoint pt1 (eval pmt))
        )

        (entmake
            (append
               '((0 . "line"))
                (mapcar 'cons '(10 11) (list pt1 pt2))
            )   
        )
       
        (setq pt1 pt2)
       
    )
   
    (princ)
   
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7529
Re: One up and why! (MyLine)
« Reply #21 on: August 23, 2006, 03:10:47 PM »


Code: [Select]
;;
;; History:
;; 08.22.06 -- Se7en
;;
;; 2006.08.22 Tracey .. corrected User interface < Spelling >
;;
;; 2006.08.23 {AEST} kwb@theSwamp ..  documentation Update , reformat
;; 2006.08.23 {AEST} kwb@theSwamp .. add closing (princ)'s for less noise
;; 2006.08.23 Tracey ... added the c: to allow the user to use at the command line
;; 2006.08.23 DGC ... added recursive functionality (removed exiting quotes)
;; 2006.08.23 UnCoolPerson... added while, and associated fun. to keep DGC's idea in our lisp and not in the line command
;; 2006.08.23 ronjonp ... removed extra setq, replaced "command" with entmake, made all functions lowercase (OCD) :)
;; 2006.08.23 T.Willey ... fixed the while statement (took out unnecessary stuff)
;; 2006.08.23 added (itoa cntr) per LE suggestion added echo last point to command line

(defun c:myline (/ cntr pt1 pt2)
  (setq cntr 1
pt1
(getpoint
   (strcat "\nEnter point number "
   (itoa cntr)
   " please: "
   )
)
  )
  (while (setq cntr (1+ cntr)
       pt2
    (getpoint
      pt1
      (strcat
"\n("
(rtos (car pt1))
","
(rtos (cadr pt1))
")<-last point - "
"Enter point number "
(itoa cntr)
": "
      )
    )
)
    (entmake
      (list
(cons 0 "LINE")
(cons 10 pt1)
(cons 11 pt2)
      )
    )
    (setq pt1 pt2)
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: One up and why! (MyLine)
« Reply #22 on: August 23, 2006, 03:11:32 PM »
Code: [Select]
;;
;; History:
;; 08.22.06 -- Se7en
;;
;; 2006.08.22 Tracey .. corrected User interface < Spelling >
;;
;; 2006.08.23 {AEST} kwb@theSwamp ..  documentation Update , reformat
;; 2006.08.23 {AEST} kwb@theSwamp .. add closing (princ)'s for less noise
;; 2006.08.23 Tracey ... added the c: to allow the user to use at the command line
;; 2006.08.23 DGC ... added recursive functionality (removed exiting quotes)
;; 2006.08.23 UnCoolPerson... added while, and associated fun. to keep DGC's idea in our lisp and not in the line command
;; 2006.08.23 ronjonp ... removed extra setq, replaced "command" with entmake, made all functions lowercase (OCD)
;; 2006.08.23 T.Willey ... fixed the while statement (took out unnecessary stuff)
;; 2006.08.23 ElpanovEvgeniy ... add Undo, Close. Has deleted superfluous variables

(defun c:myline (/ lst)
  (setq
    lst (cons (getpoint (strcat "\nEnter point number 1 please: "))
     lst
)
  )
  (while
    (and
      lst
      (cond
((not (cdr lst))
(setq lst
(cons (getpoint (car lst)
(strcat "\nEnter point number 2 please: ")
     )
     lst
)
)
)
((not (cdddr lst))
(initget "Undo")
(setq
  lst (cons
(getpoint (cadr lst)
  (strcat "\nEnter point number "
  (itoa (1+ (/ (1- (length lst)) 2)))
  " please or [Undo] "
  )
)
lst
      )
)
)
((cdddr lst)
(initget "Close Undo")
(setq
  lst (cons
(getpoint (cadr lst)
  (strcat "\nEnter point number "
  (itoa (1+ (/ (1- (length lst)) 2)))
  " please or [Close/Undo] "
  )
)
lst
      )
)
)
(t nil)
      )
    )
     (cond
       ((= (car lst) "Undo")
(entdel (cadr lst))
(setq lst (cdddr lst))
       )
       ((= (car lst) "Close")
(entmakex
 (list
   (cons 0 "LINE")
   (cons 10 (caddr lst))
   (cons 11 (last lst))
 )
)
(setq lst nil)
       )
       ((cdddr lst)
(setq
 lst (cons
(entmakex
 (list
   (cons 0 "LINE")
   (cons 10 (car lst))
   (cons 11 (caddr lst))
 )
)
lst
     )
)
       )
       ((cdr lst)
(setq
 lst (cons
(entmakex
 (list
   (cons 0 "LINE")
   (cons 10 (car lst))
   (cons 11 (cadr lst))
 )
)
lst
     )
)
       )
     )
  )
  (princ)
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: One up and why! (MyLine)
« Reply #23 on: August 23, 2006, 03:15:03 PM »
;; 2006.08.23 MP ... renamed vars to be self describing, and/or fit my
;;                      sensibilities (I know, subjective),
;;                   reformatted to expose logic (subjective x 2),
;;                   changed rtos calls to itoa,
;;                   eliminated redundant prompt defs by employing a
;;                      template technique (pmt),
;;                   puckettized entmake code,
;;                   sorry I've got one shot at this and am tied up
;;                      for the balance of the day as I just resigned
;;                      my job of 11 years. As you can well imagine LOTS
;;                      of tidying up to do.

Hope for good reasons, and that you can enjoy your next endeavor.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE

  • Guest
Re: One up and why! (MyLine)
« Reply #24 on: August 23, 2006, 03:59:49 PM »
I am sure it must be for good, good luck Michael.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: One up and why! (MyLine)
« Reply #25 on: August 23, 2006, 04:37:13 PM »
Code: [Select]
;; History:
;; 08.22.06 -- Se7en
;;
;; 2006.08.22 Tracey .. corrected User interface < Spelling >
;;
;; 2006.08.23 {AEST} kwb@theSwamp ..  documentation Update , reformat
;; 2006.08.23 {AEST} kwb@theSwamp .. add closing (princ)'s for less noise
;; 2006.08.23 Tracey ... added the c: to allow the user to use at the command line
;; 2006.08.23 DGC ... added recursive functionality (removed exiting quotes)
;; 2006.08.23 UnCoolPerson... added while, and associated fun. to keep DGC's idea in our lisp and not in the line command
;; 2006.08.23 ronjonp ... removed extra setq, replaced "command" with entmake, made all functions lowercase (OCD)
;; 2006.08.23 T.Willey ... fixed the while statement (took out unnecessary stuff)
;; 2006.08.23 MP ... renamed vars to be self describing, and/or fit my
;;                      sensibilities (I know, subjective),
;;                   reformatted to expose logic (subjective x 2),
;;                   changed rtos calls to itoa,
;;                   eliminated redundant prompt defs by employing a
;;                      template technique (pmt),
;;                   puckettized entmake code,
;;                   sorry I've got one shot at this and am tied up
;;                      for the balance of the day as I just resigned
;;                      my job of 11 years. As you can well imagine LOTS
;;                      of tidying up to do.
;; 2006.08.23 CAB ... revised mapcar & relocate setq i
(defun c:myline (/ i pmt pt1 pt2)

  (setq i   0
        pmt '(strcat "\nEnter point number " (itoa (setq i (1+ i))) ": ")
        pt1 (getpoint (eval pmt))
  )

  (while (setq pt2 (getpoint pt1 (eval pmt)))
    (entmake (mapcar 'cons '(0 10 11) (list "line" pt1 pt2)))
    (setq pt1 pt2)
  )

  (princ)

)
« Last Edit: August 23, 2006, 04:40:58 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: One up and why! (MyLine)
« Reply #26 on: August 23, 2006, 04:44:08 PM »
MP
With your talents & intellect your future will always be bright.
Try not to be stressed over it.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

deegeecees

  • Guest
Re: One up and why! (MyLine)
« Reply #27 on: August 23, 2006, 04:46:14 PM »
Should revise the file name to "My excruciating line" but thats just opinion and it would be alot to type.

 :-)

Ditto wut CAB sed.

uncoolperson

  • Guest
Re: One up and why! (MyLine)
« Reply #28 on: August 23, 2006, 05:22:04 PM »
..."My excruciating line"...

Code: [Select]
;; History:
;; 08.22.06 -- Se7en
;;
;; 2006.08.22 Tracey .. corrected User interface < Spelling >
;;
;; 2006.08.23 {AEST} kwb@theSwamp ..  documentation Update , reformat
;; 2006.08.23 {AEST} kwb@theSwamp .. add closing (princ)'s for less noise
;; 2006.08.23 Tracey ... added the c: to allow the user to use at the command line
;; 2006.08.23 DGC ... added recursive functionality (removed exiting quotes)
;; 2006.08.23 UnCoolPerson... added while, and associated fun. to keep DGC's idea in our lisp and not in the line command
;; 2006.08.23 ronjonp ... removed extra setq, replaced "command" with entmake, made all functions lowercase (OCD)
;; 2006.08.23 T.Willey ... fixed the while statement (took out unnecessary stuff)
;; 2006.08.23 MP ... renamed vars to be self describing, and/or fit my
;;                      sensibilities (I know, subjective),
;;                   reformatted to expose logic (subjective x 2),
;;                   changed rtos calls to itoa,
;;                   eliminated redundant prompt defs by employing a
;;                      template technique (pmt),
;;                   puckettized entmake code,
;;                   sorry I've got one shot at this and am tied up
;;                      for the balance of the day as I just resigned
;;                      my job of 11 years. As you can well imagine LOTS
;;                      of tidying up to do.
;; 2006.08.23 CAB ... revised mapcar & relocate setq i
;; 2006.08.23 UnCoolPerson... moved line drawing to it's own defun (because we should be able to reuse it right?), edited c:mypoint create a list of pts to pass



(defun c:mypoint (/ pt1 pt2 pt1list pt2list)
  (setq i   0
pmt '(strcat "\nEnter point number " (itoa (setq i (1+ i))) ": ")
pt1 (getpoint (eval pmt))
  )

  (while (setq pt2 (getpoint pt1 (eval pmt)))
    (setq pt1list (append pt1list (list pt1)))
    (setq pt2list (append pt2list (list pt2)))

    (setq pt1 pt2)

  )
  (My_excruciating_lines pt1list pt2list)
(princ)
)

(defun My_excruciating_lines (pt1list pt2list / pt1 pt2)

  (mapcar '(lambda (pt1 pt2)
     (entmake
       (mapcar 'cons '(0 10 11) (list "line" pt1 pt2))
     )
   )
  pt1list
  pt2list
  )
)
« Last Edit: August 23, 2006, 05:24:12 PM by uncoolperson »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: One up and why! (MyLine)
« Reply #29 on: August 23, 2006, 05:33:33 PM »
Humm. No visual feed back, I don't care for that. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.