Sem rodeios: ponto médio entre dois pontos... sim é so isso
; calcula o ponto médio entre dois pontos
(defun media (p1 p2 / x y)
(mapcar '(lambda (x y) (/ (+ x y) 2)) p1 p2))
também uso pra caramba
fnum
Quando vamos escrever um número via autolisp, precisamos que ele esteja formatado com separadores de milhar essas coisas...
;|formata um numero real em uma string com f casas decimais
e com separador de milhar, exemplo:
(fnum 123456789.123456789 3)|;
(defun fnum (num f / int pos fp)
(setq int (rtos num 2 f)
pos (vl-string-search "." int)
pos (if pos pos (strlen int))
fp (substr int (+ pos 2) (strlen int))
int (substr int 1 pos))
(while (< (strlen fp) f) (setq fp (strcat fp "0")))
(repeat (/ pos 3)
(setq int (strcat (substr int 1 (- pos 3))
"."
(substr int (- pos 2) (strlen int)))
pos (- pos 3)))
(vl-string-left-trim "."
(if (zerop f) int (strcat int "," fp))))
Com esta rotina pode-se fazer esta formatação... também serve de exemplo de como usar a função "vl-string-left-trim"
para desfazer a formatação acima, use:
;(unformatnum str):
;converte numeros do tipo 123.456.789,00 para 123456789.0
(defun unformatnum (str / v p)
(setq v (vl-string-search "," str)
p (vl-string-search "." str))
(atof
(cond ((and v p)
(vl-string-subst "." ","
(while (vl-string-search "." str)
(setq str (vl-string-subst "" "." str)))))
(v (vl-string-subst "." "," str))
(p str)
(t str))))
;|formata um numero real em uma string com f casas decimais
e com separador de milhar, exemplo:
(fnum 123456789.123456789 3)|;
(defun fnum (num f / int pos fp)
(setq int (rtos num 2 f)
pos (vl-string-search "." int)
pos (if pos pos (strlen int))
fp (substr int (+ pos 2) (strlen int))
int (substr int 1 pos))
(while (< (strlen fp) f) (setq fp (strcat fp "0")))
(repeat (/ pos 3)
(setq int (strcat (substr int 1 (- pos 3))
"."
(substr int (- pos 2) (strlen int)))
pos (- pos 3)))
(vl-string-left-trim "."
(if (zerop f) int (strcat int "," fp))))
Com esta rotina pode-se fazer esta formatação... também serve de exemplo de como usar a função "vl-string-left-trim"
para desfazer a formatação acima, use:
;(unformatnum str):
;converte numeros do tipo 123.456.789,00 para 123456789.0
(defun unformatnum (str / v p)
(setq v (vl-string-search "," str)
p (vl-string-search "." str))
(atof
(cond ((and v p)
(vl-string-subst "." ","
(while (vl-string-search "." str)
(setq str (vl-string-subst "" "." str)))))
(v (vl-string-subst "." "," str))
(p str)
(t str))))
draw-text
exemplo de como desenhar um TEXT com o entmakex:
(defun get-alh-alv ()
(setq ali (vl-position
(strcase ali)
'("L" "C" "R" "A" "M" "F" "TL" "TC"
"TR" "ML" "MC" "MR" "BL" "BC" "BR"))
alh (nth ali '(0 1 2 3 4 5 0 1 2 0 1 2 0 1 2))
alv (nth ali '(0 0 0 0 0 0 3 3 3 2 2 2 1 1 1))))
; desenha texto
(defun draw-text (str pt lay rot alt st ali / sts alh alv)
(if (not (tblsearch "style" st)) (setq st "standard"))
(get-alh-alv)
(dxf 5 (entmakex
(mapcar 'cons '(0 8 10 40 1 50 7 72 11 73)
(list "TEXT" lay
(if (= alv 0) pt '(0 0 0))
alt str rot st alh pt alv)))))
será util daqui pra frente...
(defun get-alh-alv ()
(setq ali (vl-position
(strcase ali)
'("L" "C" "R" "A" "M" "F" "TL" "TC"
"TR" "ML" "MC" "MR" "BL" "BC" "BR"))
alh (nth ali '(0 1 2 3 4 5 0 1 2 0 1 2 0 1 2))
alv (nth ali '(0 0 0 0 0 0 3 3 3 2 2 2 1 1 1))))
; desenha texto
(defun draw-text (str pt lay rot alt st ali / sts alh alv)
(if (not (tblsearch "style" st)) (setq st "standard"))
(get-alh-alv)
(dxf 5 (entmakex
(mapcar 'cons '(0 8 10 40 1 50 7 72 11 73)
(list "TEXT" lay
(if (= alv 0) pt '(0 0 0))
alt str rot st alh pt alv)))))
será util daqui pra frente...
Assinar:
Postagens (Atom)