lisp number types

lisp number types

GeryKnee
Advocate Advocate
745 Views
4 Replies
Message 1 of 5

lisp number types

GeryKnee
Advocate
Advocate

 

What is wrong here?


(defun c:xxx()
(command c:SetDocGlobalLtScale)
(setq DrawingScale (getreal "\nDim overall scale factor: "))
(setq GlobalLtScale (/ DrawingScale 1000.00))
(command "LtScale" GlobalLtScale)
(princ)
)

0 Likes
746 Views
4 Replies
Replies (4)
Message 2 of 5

GeryKnee
Advocate
Advocate

I think the next is OK

 


(defun c:xxx()
(setq DrawingScale (getreal "\nDim overall scale factor: "))
(setq GlobalLtScale (/ DrawingScale 1000.00))
(command "LtScale" GlobalLtScale)
(princ)
)

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

I think the next is OK


(defun c:xxx()
(setq DrawingScale (getreal "\nDim overall scale factor: "))
(setq GlobalLtScale (/ DrawingScale 1000.00))
(command "LtScale" GlobalLtScale)
(princ)
)


It looks like it ought to.  But I wouldn't bother with the GlobalLtScale variable if it's used only once -- just do the calculation right where it's used.  [If you do choose to use it, it's better to localize it.]  And for a System Variable setting it's a little shorter [and faster, if only by milliseconds] to use (setvar) instead of (command).  Also, since a (/) function will return a real number if either argument is a real number, and since (getreal) always returns a real number, the divisor can be an integer.  [If you choose to make it a real number, there's no point in having more than one zero after the decimal point, and in fact you don't even need one, but some find it visually clearer having one.]

 

  (defun c:xxx (/ DrawingScale)
    (setq DrawingScale (getreal "\nDim overall scale factor: "))
    (setvar 'ltscale (/ DrawingScale 1000))
    (princ)
  )

 

You could go even shorter, with no variables at all:

 

  (defun c:xxx ()
    (setvar 'ltscale (/ (getreal "\nDim overall scale factor: ") 1000))
    (princ)
  )

 

Kent Cooper, AIA
0 Likes
Message 4 of 5

Sea-Haven
Mentor
Mentor

It looks like your working in metric so its not that hard, as you have hinted 1000/250 = 4 so LTSCALE 4.

 

There is only a limited number of  normal metric drafting scales so you should be able to remember the numbers 1 2 4 5 10.  0.5=1:2000

 

May even just type  LTSCALE (/ 1000 250)  

0 Likes
Message 5 of 5

john.uhden
Mentor
Mentor

@GeryKnee 

To learn what anything is in AutoLisp, use the (type) function.

For example...

Command: (type 3) INT
Command: (type pi) REAL
Command: (type "A") STR
Command: (type '(1 2 3)) LIST
Command: (type (entlast)) ENAME

If you want to know if a variable is any kind of number, use (numberp)

If you want to know if A is a real...

(= (type A) 'REAL) ;; notice the single quote

  If it is, it returns T.  If not, it returns nil.

 

BTW, is that K silent?  Where are you located?  I don't mean "the kitchen" or "Murphy's Pub" but town and country.

John F. Uhden

0 Likes