Author Topic: bad prompt  (Read 5074 times)

0 Members and 1 Guest are viewing this topic.

rude dog

  • Guest
bad prompt
« on: March 06, 2004, 08:30:09 AM »
unusual prompt maybe one of you could explain it to me...before the fix :)
Code: [Select]

(defun c:DIL ()
(prompt "\npick line for length inquiry ")
(setq e1 (car (entsel)))
(setq e2 (cdr (assoc 10 (entget e1))))
(setq e3 (cdr (assoc 11 (entget e1))))
(princ "\nLine length is: ")
(setq d1 (rtos (distance e2 e3)))
)
(princ)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
bad prompt
« Reply #1 on: March 06, 2004, 10:41:02 AM »
Not sure what you are asking, maybe the error you get if
picked is not a line.

You need some error checking..

Code: [Select]
(defun c:dil (/ e1 d1)
  (prompt "\npick line for length inquiry ")
  (if (setq e1 (entsel)); if something selected
    (progn
      (setq e1 (entget(car e1)))
      (if (= (cdr (assoc 0  e1)) "LINE")
        (progn
          (setq d1 (rtos (distance (cdr (assoc 10 e1)) (cdr (assoc 11 e1)))))
          (prompt (strcat "\nLine length is: " d1)
          d1 ; return value
        )
        (prompt "\nSelected was not a Line."); returns nil
      )
    )
    (prompt "\nNothing selected."); returns nil
  )
  ;;(princ) ;use this if you don't want to return a value
) ; end defun
(princ)
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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
bad prompt
« Reply #2 on: March 07, 2004, 04:43:45 PM »
I concur CAB, there is no flaw in the original code other than there is no error checking.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

SMadsen

  • Guest
bad prompt
« Reply #3 on: March 07, 2004, 08:03:02 PM »
Rude Dog, if it's because it doesn't print d1 to the screen then enclose it in a PROMPT as CAB do - or just use PRINC:
(princ (setq d1 (rtos (distance e2 e3))))

- do consider some error checking as suggested, though

rude dog

  • Guest
bad prompt
« Reply #4 on: March 07, 2004, 09:43:26 PM »
I agree with the error checking comments....but here is how the program reads when initiated...the program is supposed to prompt a lines length once chosen....
Code: [Select]

Command: dil
pick line for length inquiry
Select object:
[b]Line length is: "10'-6\""[/b] this is what I dont understand

Serge J. Gianolla

  • Guest
bad prompt
« Reply #5 on: March 07, 2004, 10:31:31 PM »
Is this what you are after!

Command: (rtos (distance e2 e3) 1 2)
"6.46E+02"

Command: (rtos (distance e2 e3) 2 2)
"646.34"

Command: (rtos (distance e2 e3) 3 2)
"53'-10.34\""

Command: (rtos (distance e2 e3) 4 2)
"53'-10 1/4\""

Command: (rtos (distance e2 e3) 5 2)
"646 1/4"

rude dog

  • Guest
bad prompt
« Reply #6 on: March 08, 2004, 11:28:18 AM »
(prompt (strcat "\nLine length is: " d1)


Code: [Select]

this did it thanks all

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
bad prompt
« Reply #7 on: March 08, 2004, 11:40:29 AM »
:?:
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

SMadsen

  • Guest
bad prompt
« Reply #8 on: March 08, 2004, 11:47:17 AM »
Meaning that the "bad prompt" was an echo of a return value and not a prompt.

umm .. right?

rude dog

  • Guest
bad prompt
« Reply #9 on: March 08, 2004, 02:17:49 PM »
echo of a return value and not a prompt.

ya got me :)