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

Adding up attribute values

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
479 Views, 3 Replies

Adding up attribute values

Hi All,

 

Does anyone have a routine where I could keep picking on my exit arrow blocks (showing how many persons exiting from each space) one-by-one and the program would add up the numbers.  For example I pick on blocks with numbers of 2, 4 & 3 and I would get 9.

 

Thank you,

 

GS

3 REPLIES 3
Message 2 of 4
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... 

Does anyone have a routine where I could keep picking on my exit arrow blocks (showing how many persons exiting from each space) one-by-one and the program would add up the numbers.  For example I pick on blocks with numbers of 2, 4 & 3 and I would get 9.

....


I don't, but maybe something like this:
 

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/LISP-to-Extract-Attribute-Tag-Value-and-Total-the-Occurences/m-p/2855678/highlight/true#M293665

 

has something already at least close to what you want, with some things you could forgo [writing out to a file, for instance].  You may find something even closer if you do some Searching -- that's just one close to the top of the list when I put "total attributes" into the Search window.

Kent Cooper, AIA
Message 3 of 4
Hallex
in reply to: Anonymous

Try this one from my storage, change attribute tags

within the code

(defun C:sumat (/  acsp adoc blk blkname blkobj blkset en objlst summ)

  (vl-load-com)
  (setq adoc (vla-get-activedocument
              (vlax-get-acad-object))
	      acsp (vla-get-block
		     (vla-get-activelayout adoc)))
  (vla-startundomark adoc)
  
  (setq blkname (getstring T "\Enter the block name (case-sensitive): "))
  
  (princ "\nSelect blocks one by one:")
  
  (while (setq en (entsel))
    (setq blkobj (vlax-ename->vla-object (car en)))
    (if (and (eq blkname (vla-get-effectivename blkobj))
	     (eq :vlax-true(vla-get-hasattributes blkobj)))
      (setq objlst (cons blkobj objlst)))
    )

(setq summ 0)
  (foreach blkobj objlst
    (foreach at (vlax-invoke blkobj 'getattributes)
      (if (eq (strcase (vla-get-tagstring at)) "KP");<-- source attribute tag
	(setq summ (+ summ (atof (vla-get-textstring at))))
	)
      )
    )
 
  (princ "\nSelect a single block to write sum:")
(setq blkset (ssget ":S" (list (cons 0 "insert")(cons 66 1))))
  (setq blk (vlax-ename->vla-object (ssname blkset 0)))
  (foreach at  (vlax-invoke blk 'getattributes)
    (if	(eq (strcase (vla-get-tagstring at)) "KP");<-- resulting attribute tag, may be another then source tag
      (vla-put-textstring at (rtos summ 2 0))))
 (vla-regen adoc acActiveViewport)

  (vla-endundomark adoc)
  (princ)
    )
(princ "\n\t\t---\tStart with command SUMAT... \t---")
(prin1)
(or (vl-load-com)
(princ))

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 4
3wood
in reply to: Anonymous

Please try attached routine, the number is shown at the bottom of the dialogue box.

 

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

Post to forums  

Autodesk Design & Make Report

”Boost