cg-Cad

Lisp »Tips 'n Tricks »Funzioni varie (2)

Nnum() mostra un numero con N decimali.

(defun nNum ( num larg dec / str un sp l dif)
   (setq un (getvar "luprec"))
   (setvar "luprec" dec)
   (setq str (rtos num))
   (setvar "luprec" un)
   (setq sp "")
   (setq l (strlen str))
   (setq dif (- larg l))
   (repeat dif
      (setq sp (strcat sp " "))
   )
   (setq str (strcat sp str))
)

Sdec() imposta 1 o 0 decimali nelle quote.

(defun sdec ( p1 p2 / dist dif tdim)
   (setq dist (distance p1 p2))
   (setq dif ( - dist (fix dist)))
   (if (= dif 0)
      (setvar "luprec" 0)
      (setvar "luprec" 1)
   )
   (setq tdim (rtos dist))
)

mlay() definisce un nuovo layer.

(defun mlay (n c lt) 
  (if (tblsearch "LAYER" n)
    (command "_LAYER" "_S" n "")
    (progn
      (setq regen (getvar "REGENMODE"))
      (setvar "REGENMODE" 0)
      (command "_LAYER" "_M" n)
      (if c (command "_C"  c n))
      (if lt (command "_LT" lt n))
      (command "")
      (setvar "REGENMODE" regen)
    )
  )
  (princ)
)
Esempio:
Command: (mlay "pippo" 3 "dashdot")
_LAYER
Current layer:  "pippo"
Enter an option 
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight
/Plot/Freeze/Thaw/LOck/Unlock]: _S
Enter layer name to make current : 
pippo Enter an option 
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight
/Plot/Freeze/Thaw/LOck/Unlock]:
Command:

Udist() User interface distance function.

(defun udist (msg def / inp)
  (if def
    (setq msg
      ; String'em with default
      (strcat "\n" msg "<" (rtos def) ">: ")  
    )
    ; Without default
    (setq msg (strcat "\n" msg ": "))
  )
  ; Use the GET function
  (setq inp (getdist msg))   
  (if inp inp def) ;| Compare the results, 
               return appropriate value |;
)
Esempio:
Command: (udist "prova messaggio" 3)

prova messaggio<3>:
3

Lisp »Tips 'n Tricks