Community
@taisenberg wrote:
..... Now I've got to fill the number ( ( quantity=roundup(density*area) ) but as I've got thousands of blocks I was hoping to use a quick Lisp routine. Thanks Tal
(defun c:Maav (/ _number ss data i area density) ;;; multiply and assign value ;;; pBe Feb2014 ;;; (setq _number (lambda (n) (if (numberp (setq n (read n))) n 0 ) ) ) (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "BLK1")))) (repeat (setq i (sslength ss)) ;(setq e (ssname ss (setq i (1- i)))) (setq data (mapcar '(lambda (v) (list (strcase (vla-get-tagstring v)) (_number (vla-get-textstring v)) v ) ) (vlax-invoke (vlax-ename->vla-object (ssname ss (setq i (1- i))) ) 'Getattributes ) ) ) (if (and (vl-every '(lambda (a) (setq cv (assoc a data))) '("ATT1" "ATT2" "ATT3") ) (> (setq area (cadr (assoc "ATT1" data))) 0) (> (setq density (cadr (assoc "ATT2" data))) 0) ) (vla-put-textstring (last (assoc "ATT3" data)) (itoa (1+ (fix (* area density ) ) ) ) ) (princ "\nInvalid Data") ) ) ) (princ) )
You many need to change a couple of items on the code depending on the actual block and TAG names
HTH
@taisenberg wrote:
Hey pbejse and thanks for responding ! I'm not sure why but I'm not able to run it on my blocks ?! First I tried changing the names in the routine to the real attribute names and after that didn't work I changed the name of the attributes in my block to ATT1, ATT2, ATT3 as well as the block name. So not sure what I'm missing ?!? or is there anything else I need to chance in the block apart from the tag and block names ? I've attached the actual block I'm trying to run this on I need to multiply values from tags: AREA * DENSITY and assign it to PLANTCOUNT Block name is WATG_AREATAG_A Thanks again Tal
Works here on my end. Tell me, Is there any error message?
does it show "Invalid Data" at the end when you invoke MAAV?
is PLANTCOUNT a dynamic block?
BTW: I dont see any atachment.
I change the values on the attached code and modify to account for DBlocks
@taisenberg wrote:
the 'roundup' method you used can get the wrong aswer if both numbers are integer (e.g. (+1 fix ( 2*3 ))=7 instead of 6... I added a 0.9999999999 in the multiplication which sort of sorts it for 99.999% of the time. (i.e. (+1 fix ( 2 * 3 * 0.99999999 )) = 6),
I see, change this
(itoa (1+ (fix (* area density ))))
to
(itoa (fix (if (zerop (rem (setq num (* area density)) (fix num))) num (1+ num))))
HTH