Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 4
dicra
396 Views, 3 Replies

Precision

 

Hi everyone,

 

I just wrote a lisp routine which is calculating and marking Y values (2D elevations, if I can say so), based on a reference point.

The lisp is actually working, but I am having two problems.

 

1st. The values of elevation which are in block attributes are whit precision whit 15 decimal places (something like this                    0.0000000000000), 

       I would like precision whit only two places (like this 0.00). 

2nd. Like I sad the lisp is working but I am sure that there is more elegant solution whit this repeat part, 

        what I want is to repeat that part until user cancel it, maybe to put something like "pick another point, or exit".

 

 

 

(defun C:ikota (/ a razm RT yRT Hrel Haps PT yPT Hr1 Ha1)
   (setvar "attdia" 0)
   (setq razm (getreal "\nScale faktor: "))
   (setq RT (getpoint "\nReference point\n"))
   (setq yRT (nth 1 RT)) 
   (setq Hrel (getreal "\nElevation\n"))
   (setq Haps (getreal "\nApsolute elevation\n"))
  (setq pomr (abs Hrel) poma (abs Haps))
   (if (< Hrel 0) 
       (command "insert" "ikota-" RT razm "" "" poma pomr "")
      (command "insert" "ikota+" RT razm "" "" Haps Hrel ""))
   (repeat 100
   (progn
       (setq PT (getpoint "\nChoose point: "))
       (setq yPT (nth 1 PT))
       (setq Hr1 (+ Hrel (/ (- yPT yRT) 100)))
       (setq Ha1 (+ Haps (/ (- yPT yRT) 100)))
       (setq pomr1 (abs Hr1) poma1 (abs Ha1))
     (if (< Hr1 0)
       (command "insert" "ikota-" pt razm "" "" poma1 pomr1 "")
       (command "insert" "ikota+" pt razm "" "" Ha1 Hr1 ""))))
)

 

P.S I am in process of learning AutoLisp, so I would be wery thankful  for any suggestions, corrections etc.

 

At advance thanks for the answers

 

3 REPLIES 3
Message 2 of 4
stevor
in reply to: dicra

1. Check out the terms 'LUNITS, LUPREC, UNITS, and RTOS' here [search] or on Google with the word +autolisp... 2. Beware of excess elegance, as in the form of brevity or sophistication, since you may have to read your code later; and the progn just inside the repeat loop is not required.
S
Message 3 of 4
Kent1Cooper
in reply to: dicra


@dicra wrote:

....

2nd. Like I sad the lisp is working but I am sure that there is more elegant solution whit this repeat part, 

        what I want is to repeat that part until user cancel it, maybe to put something like "pick another point, or exit".

....

  (repeat 100

   (progn
       (setq PT (getpoint "\nChoose point: "))
....

One way to do a repeat for as long as the User wants to keep repeating is to replace the above-quoted lines with

....

  (while (setq PT (getpoint "\nChoose point: "))

.... 

[omitting the unnecessary (progn) as stevor mentioned].  As long as the User picks another point, it will go on and do what it should with it, but when they hit Escape or Enter or Space, the (getpoint) function will return nil, and it will stop.

Kent Cooper, AIA
Message 4 of 4
dicra
in reply to: Kent1Cooper

 


@Kent1Cooper wrote:


One way to do a repeat for as long as the User wants to keep repeating is to replace the above-quoted lines with

....

  (while (setq PT (getpoint "\nChoose point: "))

.... 

[omitting the unnecessary (progn) as stevor mentioned].  As long as the User picks another point, it will go on and do what it should with it, but when they hit Escape or Enter or Space, the (getpoint) function will return nil, and it will stop.


 

Thanks again Kent, whit "while" it  looks lot more beater.

 

 

 


 

@stevor wrote:
1. Check out the terms 'LUNITS, LUPREC, UNITS, and RTOS

 


Thanks stevor, I will try those functions.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost