AutoCAD R14 AutoLISP Error: Bad Argument Type

AutoCAD R14 AutoLISP Error: Bad Argument Type

Anonymous
Not applicable
433 Views
10 Replies
Message 1 of 11

AutoCAD R14 AutoLISP Error: Bad Argument Type

Anonymous
Not applicable
Hello, I am new in learning AutoLISP on AutoCAD R14. I tried to construct a 'catenary' curve: Y = 1/2[exp(X) + exp(-X)]. I can not figure out why the program listed below does not work. Please help: tell me why I got an Error : Bad Argument Type in the following program:


(defun C:SUSP () ; Suspension Bridge
(graphscr)
(setq L (getreal "\rPLEASE ENTER THE Bridge Span "))
(setq H (getreal "\rPLEASE ENTER THE Height of The Bridge "))
(setq X (- 0 (/ L 2)))
(setq P1 (list (- 0 (/ L 2)) (- H (* 0.548 H))) Q T)
(while Q
(setq A (EXP (* 2 X (/ 1.0 L))))
(setq B (EXP (- 0 (* 2 X (/ 1.0 L)))))
(setq Y (- (* 0.324 H (+ A B)) (* 0.548 H)))
(setq P2 (list X Y))
(command "LINE" P1 P2 "")
(setq P1 P2 X (+ X (/ L 50)))
(if (> X (/ L 2))(setq Q nil))
)
)

Thanks in advance,
Scott Chang
0 Likes
434 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
Bad news, Scott. I ran the program, and it drew a curve for me. There was
no error.

By the way, this should probably be posted in the "customization" ng rather
than the "r14general" ng (which is where it is as I reply).

Good luck.

Randy

shchang1 wrote in message ...
>Hello, I am new in learning AutoLISP on AutoCAD R14. I tried to construct a
'catenary' curve: Y = 1/2[exp(X) + exp(-X)]. I can not figure out why the
program listed below does not work. Please help: tell me why I got an Error
: Bad Argument Type in the following program:
>
>(defun C:SUSP () ; Suspension Bridge
>(graphscr)
> (setq L (getreal "\rPLEASE ENTER THE Bridge Span "))
> (setq H (getreal "\rPLEASE ENTER THE Height of The Bridge "))
> (setq X (- 0 (/ L 2)))
> (setq P1 (list (- 0 (/ L 2)) (- H (* 0.548 H))) Q T)
> (while Q
> (setq A (EXP (* 2 X (/ 1.0 L))))
> (setq B (EXP (- 0 (* 2 X (/ 1.0 L)))))
> (setq Y (- (* 0.324 H (+ A B)) (* 0.548 H)))
> (setq P2 (list X Y))
> (command "LINE" P1 P2 "")
> (setq P1 P2 X (+ X (/ L 50)))
> (if (> X (/ L 2))(setq Q nil))
> )
> )
>
>Thanks in advance,
>Scott Chang
>
>
0 Likes
Message 3 of 11

Anonymous
Not applicable
Thank you, Randy. Actually I ran the program on AutoCAD R14.01 on my C:\Drive (with AutoCAD R14 on the Windows 97 LAN System of our office). Do you have any clues why I got that error? Please help me again. Thanks again, Scott Chang
0 Likes
Message 4 of 11

Anonymous
Not applicable
Sometimes osnap settings will mess things up. If your osnap settings are
not zero, try setting them to zero and see if that helps.

Since it worked when I tried it, it is hard to find the error. That's why I
said "bad news" when it worked for me.

I suggest that you try it again. When the error occurs, highlight and copy
the information from the text screen, including the replies you gave to the
prompts, the error message, and the traceback information that follows.
Paste the information into your reply. If there is no traceback, try this
line before running the program:

(setq *error* nil)

Good luck.

-Randy

shchang1 wrote in message ...
>Thank you, Randy. Actually I ran the program on AutoCAD R14.01 on my
C:\Drive (with AutoCAD R14 on the Windows 97 LAN System of our office). Do
you have any clues why I got that error? Please help me again. Thanks again,
Scott Chang
>
0 Likes
Message 5 of 11

Anonymous
Not applicable
Hi, Randy. (1) I copied the traceback information and pasted here for you to look at:
Command: _appload
Initializing... APPLOAD loaded.
Loading C:\ACAD14\AutoLISP\Susp.lsp ...
Command: susp
PLEASE ENTER THE Bridge Span 500
PLEASE ENTER THE Height of The Bridge 200
error: bad argument type
(SETQ Y (- (* 0.324 H (+ A B))) (* 0.548 H))
(WHILE Q (SETQ A (EXP (* 2 X (/ 1.0 L)))) (SETQ B (EXP (- 0 (* 2 X (/ 1.0
L))))) (SETQ Y (- (* 0.324 H (+ A B))) (* 0.548 H)) (SETQ P2 (LIST X Y))
(COMMAND "LINE" P1 P2 "") (SETQ P1 P2 X (+ X (/ L 50))) (IF (> X (/ L 2)) (SETQ
Q nil)))
(C:SUSP)
*Cancel*
(2)What is the starting value of "Q" in the "while" do loop, if I set L=500 and H=200? (3) I copied this set of codes from a book. There is "T" after the "Q" and I do not know what "T" means in the AutoLISP? Please help me in solving the problem and telling me the starting value of "Q" and the meaning of "T" in the AutoLISP. Thanks, Scott Chang
0 Likes
Message 6 of 11

Anonymous
Not applicable
I used the same inputs you used, and it worked. If I were you, my next step
would be to insert the following statement

(SETQ
LX L
HX H
XX X
P1X (CONS P1 P1X)
AX (CONS A AX)
BX (CONS B BX)
)

just before the line that begins "(setq y..."
It definitely won't fix your problem, but it might help to diagnose it.
After you try running the program again, type the following at the command
prompt:

!LX
!HX
!XX
!P1X
!AX
!BX
!EXP

Copy and paste the results into a new post. If this does not generate a
lead, I don't know what else to try.

To answer questions 2 & 3:

The "setq" function sets the value of Q to T, so the initial value of Q in
the loop is T. T means "true." The statement (= 3 4) returns nil because
the statement is false, but the statement (= 3 3) returns T because the
statement is true.

Good luck.

shchang1 wrote in message ...
>Hi, Randy. (1) I copied the traceback information and pasted here for you
to look at:
>Command: _appload
>Initializing... APPLOAD loaded.
>Loading C:\ACAD14\AutoLISP\Susp.lsp ...
>Command: susp
>PLEASE ENTER THE Bridge Span 500
>PLEASE ENTER THE Height of The Bridge 200
>error: bad argument type
>(SETQ Y (- (* 0.324 H (+ A B))) (* 0.548 H))
>(WHILE Q (SETQ A (EXP (* 2 X (/ 1.0 L)))) (SETQ B (EXP (- 0 (* 2 X (/ 1.0
>L))))) (SETQ Y (- (* 0.324 H (+ A B))) (* 0.548 H)) (SETQ P2 (LIST X Y))
>(COMMAND "LINE" P1 P2 "") (SETQ P1 P2 X (+ X (/ L 50))) (IF (> X (/ L 2))
(SETQ
>Q nil)))
>(C:SUSP)
>a.. Cancel* (2)What is the starting value of "Q" in the "while" do loop, if
I set L=500 and H=200? (3) I copied this set of codes from a book. There is
"T" after the "Q" and I do not know what "T" means in the AutoLISP? Please
help me in solving the problem and telling me the starting value of "Q" and
the meaning of "T" in the AutoLISP. Thanks, Scott Chang
>
0 Likes
Message 7 of 11

Anonymous
Not applicable
Hi, Randy, Thanks. Here are the things I got according to your instructions:
Command: _appload
Initializing... APPLOAD loaded.
Loading C:\ACAD14\AutoLISP\Susp.lsp ...
Command: susp
PLEASE ENTER THE Bridge Span 500
PLEASE ENTER THE Height of The Bridge 200
error: bad argument type
(SETQ Y (- (* 0.324 H (+ A B))) (* 0.548 H))
(WHILE Q (SETQ A (EXP (* 2 X (/ 1.0 L)))) (SETQ B (EXP (- 0 (* 2 X (/ 1.0
L))))) (SETQ LX L HX H XX X P1X (CONS P1 P1X) AX (CONS A AX) BX (CONS B BX))
(SETQ Y (- (* 0.324 H (+ A B))) (* 0.548 H)) (SETQ P2 (LIST X Y)) (COMMAND
"LINE" P1 P2 "") (SETQ P1 P2 X (+ X (/ L 50))) (IF (> X (/ L 2)) (SETQ Q nil)))
(C:SUSP)
*Cancel*
Command: !LX 500.0
Command: !HX
200.0
Command: !!XX
nil
Command: !P1X
((-250.0 90.4))
Command: !AX
(0.367879)
Command: !BX
(2.71828)
Command: !EXP
<>
Hope you find what you are looking for. Thanks again, Scott Chang
0 Likes
Message 8 of 11

Anonymous
Not applicable
Randy, One correction to my last Post Reply: Command: !XX
-250.0 Sorry about that. Scott Chang
0 Likes
Message 9 of 11

Anonymous
Not applicable
Apparantly what happened is that the code you posted was slightly different
from the code that you were running. You apparantly made a change and then
it wouldn't work, but instead of posting the changed code, you posted the
original code (or vice versa, I don't know). Here is the offending line:

(setq Y (- (* 0.324 H (+ A B)))(* 0.548 H)); wrong
(setq Y (- (* 0.324 H (+ A B))(* 0.548 H))); right
0 Likes
Message 10 of 11

Anonymous
Not applicable
Thanks, Randy. Yes, the codes I posted was slightly diffrent because I picked/copied the wrong one to post - sorry about it. I learned from this program several valuable things about AutoLISP programing. In this SUSP.lsp, (1) it is not clear how and why P1 is set up and (2)it is cleaver to set up 'Q' and 'While' - it is beyond my ability to understand how Q starts (by what value ?) and what the condition of 'while Q'to generate many values of P1 and P2 in the 'while Q' to draw "LINE" many times!!?? I tried several days to comprehend these key codes in vain- AutoLISP programing is quite diffrent from BASIC (or Visual BASIC) programing. Randy, please enlight me more and tell me the key logic in the codes (setq P1 (list (- 0 (/ L 2)) ((-H (* 0.548 H))) Q T);(setq Y (- (* 0.324 H (+ A B))(* 0.548 H))); and (setq P1 P2 X (+ x (/ L 50))). Thanks in advance, Scott Chang
0 Likes
Message 11 of 11

Anonymous
Not applicable
The line

(setq P1 (list (- 0 (/ L 2)) (- H (* 0.548 H))) Q T)

is setting two variables, P1 and Q. The setq function can be used to set
any number of variables. This line could have been expressed in two lines
thusly:

(setq P1 (list (- 0 (/ L 2)) (- H (* 0.548 H))))
(setq Q T)

Q is being set to the value of T, or true.

Here is an alternate version of how to set P1, although it is more verbose,
perhaps the logic will be clearer to you.

(setq half_of_L (/ L 2))
(setq negative_half_of_L (- 0 half_of_L))
(setq 54point8%_of_H (* 0.548 H))
(setq 45point2%_of_H (- H trpoint8%_of_H))
(setq P1 (list negative_half_of_L 45point2%_of_H))

Similarly, the line

(setq Y (- (* 0.324 H (+ A B))(* 0.548 H)))

Is setting the value of Y, which is the difference between the product of
0.324, H, and the sum of A and B and the product of 0.548 and H.

The line

(setq P1 P2 X (+ x (/ L 50)))

Sets two values, P1 and X. P1 is set to the value of P2, and X is set to be
the sum of X and one-fiftieth of L.

The loop works by saying that, as long as the value Q is defined, which it
was initially when it was set to T, to do the stuff in the while loop. It
stops after Q becomes undefined. There is a statement in the program that,
when a certain condition is fulfilled, Q is set to nil--in other words, Q is
undefined, and this stops the loop because it depends on Q being defined.
This is what the line

(if (> X (/ L 2))(setq Q nil))

does. It says "if X is greater than half of L, undefine variable Q.

Hope this helps.
0 Likes