Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello there
How can I print the product of text files as square meters like in the example?
Solved! Go to Solution.
Hello there
How can I print the product of text files as square meters like in the example?
Solved! Go to Solution.
I assume you mean text objects, not files. In any case, what is the meaning of text content like 150/130 in relation to area?
150/30: window size, 90/210: door size. Unit : cm
* Area of (TEXT) fields of these values and automatic summing.
result : minha : xxxx m²
Perhaps this could help you.
(vl-load-com) (defun c:WindowArea ( / LM:str->lst s del) (defun LM:str->lst ( str / pos ) (if (setq del "/" pos (vl-string-search del str)) (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))))) (list str))) (if (setq s (ssget '((0 . "TEXT") (1 . "*/*")))) (princ (rtos (apply '+ (mapcar '(lambda (y) (apply '* (mapcar 'atof y))) (mapcar 'LM:str->lst (mapcar '(lambda (x) (getpropertyvalue x "TextString")) (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))))))))) (princ) )
Here's my approach to it:
(defun C:OAT ; = Opening Area Total
(/ ss oat n str)
(if (setq ss (ssget '((0 . "TEXT") (1 . "*#/#*"))))
(progn ; then
(setq oat 0)
(repeat (setq n (sslength ss))
(setq
str (cdr (assoc 1 (entget (ssname ss (setq n (1- n))))))
oat
(+
oat
(/
(*
(atoi (substr str 1 (vl-string-search "/" str)))
(atoi (substr str (+ (vl-string-search "/" str) 2)))
); *
10000.0 ; cm² to m²
); /
); + & oat
); setq
); repeat
(command "_.text" "_mc" pause "" 0 (strcat "Minha : " (rtos oat 2 2) " m²"))
); progn
); if
(princ)
); defun
It uses the current Text Style [assumed to not have a fixed height, as in the sample drawing] and height, on the current Layer; specifics for those could all be built into it if needed.
(Defun c:porridge (/ sss i sum pt str)
(if (and
(setq sum 0
sss (ssget '((0 . "TEXT") (1 . "*/*")))
)
(setq pt (getpoint "\nPick Text insertion point"))
)
(progn
(repeat (setq i (sslength sss))
(setq str (cdr (assoc 1 (entget (ssname sss (setq i (1- i)))))))
(setq sum
(+
sum
(eval
(read (strcat "( * " (vl-string-subst " " "/" str) ")")
)
)
)
)
)
(entmakex
(list (cons 0 "TEXT")
(cons 10 (trans pt 1 0))
(cons 7 (getvar 'Textstyle))
(cons 40 (getvar 'Textsize))
(cons 1
(strcat "Minha : " (rtos (* 0.0001 sum) 2 2) " m²")
)
)
)
)
)
(princ)
)
Another for fun:
(defun c:foo (/ a p r s v)
;; RJP » 2021-07-29
(cond ((setq s (ssget '((0 . "TEXT") (1 . "*#/#*"))))
(setq a (ssname s 0))
(setq r 0)
(foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
(setq v (read (strcat "(" (vl-string-translate "/" " " (cdr (assoc 1 (entget e)))) ")")))
(setq r (+ r (/ (apply '* v) 10000.)))
)
(if (setq p (getpoint "\nPick a point to place results: "))
(entmake (append (entget a)
(list (cons 10 p)
'(8 . "CERCEVE")
(cons 1 (strcat "Minha : " (rtos r 2 2) " m²"))
'(50 . 0.)
'(40 . 30.)
)
)
)
)
)
)
(princ)
)