Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating one block attribute based on other attributes in the same block

7 REPLIES 7
Reply
Message 1 of 8
taisenberg
530 Views, 7 Replies

Updating one block attribute based on other attributes in the same block

Hi, Have been scratching my head for a couple of day and as I'm not great at Lisp I'm bit stuck, I need a Lisp routine that reads two attribute values (say ATT1 and ATT2) from a block (say named BLK1), and write the multiplication value of the two numbers in a third attribute (say ATT3). Essentially I have a massive planting plan where I've tagged each polyline, the tag automatically assigns the area and I've manually put the density. 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. The routine ideally should go over ALL the blocks with the name BLK1 in the drawings or selection set and calculate the quantity for them. I also need to note that possibly the values in the attributes (area + density) might have been written as a string. Any help would be immensely appreciated, Thanks Tal
Tags (2)
7 REPLIES 7
Message 2 of 8
pbejse
in reply to: taisenberg


@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

 

Message 3 of 8
taisenberg
in reply to: pbejse

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
Message 4 of 8
pbejse
in reply to: taisenberg


@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

Message 5 of 8
taisenberg
in reply to: pbejse

Yup, works perfect now ! I think the dynamic block did it although I did try it yesterday just with a simple block, not sure why, anyhow, works now. My eternal gratitude for that, saved me manually going through thousands of blocks and doing that for my next week deadline, b.t.w. 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), although I'm sure there's a more accurate way of doing that. Anyway, its not a problem. Cheers again, Tal
Message 6 of 8
pbejse
in reply to: taisenberg


@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

 

Message 7 of 8
taisenberg
in reply to: pbejse

Thanks again, works perfectly !!!



Tal



Tal Aisenberg, CMLI | Senior Landscape Architect
WATG | designing destinations
Boston House | 36-38 Fitzroy Square
London W1T 6EY UK
+44 (0) 20 7906 6600 tel
watg.com

Wimberly Allison Tong & Goo (UK) Limited
Registered in England and Wales | Company Number 5663701
Message 8 of 8
pbejse
in reply to: taisenberg


@taisenberg wrote:
Thanks again, works perfectly !!!
Tal

You are welcome Tal, Glad it helps.

 

pBe

 

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

Post to forums  

Autodesk Design & Make Report

”Boost