Jump to content

Recommended Posts

Posted

I never had an issue with this on any other lisp. It seems if "c" is bigger then "b" it wants to give me a negitive number. No matter which order I pick it. Does any one have answer why? What also is weird is that the "e" is the correct number I need but it does not print that answer. When i run another routine similar to this one it works fine. i am using 2011 Cad

 

a=20

b=40'-5.25"

c=45'-10"

d=1852

e=37040

But it is giving me -28496 and putting that on the screen not 37040 which is what i am looking for.

 

 
(defun c:sr ()

 (setq a (getstring "16/20 for wind: ")) 
 (setq b (getdist "\nClick on 2 points to specify mean roof height: "))
 (setq c (getdist "\nClick on 2 points to specify building length: "))
 (setq d (fix (* (cvunit c "INCHES" "FEET") (cvunit b "INCHES" "FEET"))))

    (if (= a "20")    
    (progn    
     (setq e (* 20 d))
      (command "text" pause "6" "0" e)
     (princ)))
     (if (= a "16")    
    (progn    
     (setq e (* 16 d))
       (command "text" pause "6" "0" e)

     (princ))))

Posted

First thing I thought after reading this:

you want to list the answer as a text so you may have to change the variable e to a text with the function itos (integer to string).

 

Don't have AutoCAD access to test it at this moment...

Posted

for example:

(command "text" pause "6" "0" [color=red][b](itos[/b][/color] e[color=red][b])[/b][/color])

Posted

Nope it still gives me the negitive number.

Posted

Localize your variables and possibly look at the abs function.

Posted

alanjt

ok here is a newbe question. Why do I need to localize my variables? i am looking into and trying the abs.

Posted
alanjt

ok here is a newbe question. Why do I need to localize my variables? i am looking into and trying the abs.

Non-localized variables can have adverse effects on routines (same one run the second time or different ones with same defined variables).

 

eg.

(defun c:TEst (/)
 (if (setq n (getint "\nSpecify value to append to list: "))
   (print (setq l (cons n l)))
 )
 (princ)
)

(defun c:TEst2 (/ n l)
 (if (setq n (getint "\nSpecify value to append to list: "))
   (print (setq l (cons n l)))
 )
 (princ)
)

 

 

Command: test

Specify value to append to list: 5

(5)

Command:
Command:
TEST
Specify value to append to list: 25

(25 5)

Command:
Command: test2

Specify value to append to list: 4

(4)

Command:
Command:
TEST2
Specify value to append to list: 56

(56)

 

Notice, when I executed the first routine Test, when I typed in the first value, it appended it to the list, but the next time I ran the routine and appended the value to the list, it also had the first value I had typed in on the first run. Whereas, with the second routine Test2, it gave the value I wanted every time.

Posted

Have you tried values other than the ones you'v given here (i.e. b=40 c=35')? How do they affect the result?

 

I suspect someting's going wonky in the way its interpreting your distance values at b and c. How do the figures look coming out of your unit conversion? As a test routine I might be tempted to try something like this:

(defun c:sr2 ( / A B C D E Z Y X W)

 (SETQ
  a "20";(GETSTRING "16/20 for wind: ")
  b 485.25;(GETDIST "\nClick on 2 points to specify mean roof height: ")
  c 550;(GETDIST "\nClick on 2 points to specify building length: ")
  z (CVUNIT c "INCHES" "FEET")
  y (CVUNIT b "INCHES" "FEET")
 );SETQ
 
 (PRINC "\nMean Roof Height:    ")
 (PRINC y)
 (PRINC "\NBuilding Length:    ")
 (PRINC z)
 
 (SETQ x (* z y))
 (PRINC "\nfirst multiplication:     ")
 (PRINC x)
 
 (SETQ d (FIX x))
 (PRINC "\nAfter rounding: ")
 (PRINC d)

    (if (= a "20")    
    (progn    
     (setq e (* 20 d))
      (command "text" pause "6" "0" e)
     (princ)))
     (if (= a "16")    
    (progn    
     (setq e (* 16 d))
       (command "text" pause "6" "0" e)

     (princ)
     );PROGN
     );IF
);DEFUN

 

Note that I've localised my variables, as mentioned elsewhere in this thread to at least avoid that possibility.

 

Interestingly, that gives me a result of 37060, rather than the 37040 you were predicting.

 

Hope some of this helps,

 

dJE

Posted

Thanks alanjt,

I thought that is what you meant.

 

Thanks Lee,

I did read though that on your site. Have your site booked marked.

 

danellis,

It works fine in another drawing, so i am wondering if there is a setting in the drawing that got changed. I did go and localize my variables and I will start doing it from now on.

 

Thanks,

joey

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...