Jump to content

Recommended Posts

Posted

would anybody please suggest me a lisp routine with which i can add the attributes of blocks i can choose through window polygon or through close plygon,

thanks

Posted

While it is certianly doable, a program to meet your needs would probably have to be fairly specific.

 

Are all of the attribute formatted in decimal, imperial, scientific etc

Do you want use all attributes or just certian tag names

Where and how are the results to be displayed or outputted.

Selecting INSETS via ssget accepts various inputs:

 

Command: (ssget)
Expects a point or 
Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/P
revious/Undo/AUto/SIngle

How much error checking is required

 

Lots of little things that make a program truely useful. -David

Posted

Here is a generic routine for adding ATTRIB values. -David

 

;;;ADD NUMERIC VALUES OF AN ATTRIB TAG IN SELECTED INSERTS
(defun c:combav (/ tm ss i en an ad at av vl)
 (setq tm (strcase (getstring "\nATTRIB Tag To Add:   ")))
 (and (setq ss (ssget (list (cons 0 "INSERT")
                            (cons 66 1)
                            (cons 67 (if (= (getvar "TILEMODE") 1) 0 1)))))
       (setq i (sslength ss))
       (while (not (minusp (setq i (1- i))))
              (setq en (ssname ss i)
                    an (entnext en))
              (while (= "ATTRIB" (cdr (assoc 0 (entget an))))
                     (setq ad (entget an)
                           at (strcase (cdr (assoc 2 ad)))
                           av (atof (cdr (assoc 1 ad))))
                     (if (= at tm)
                         (setq vl (cons (if (= (fix av) av)
                                            (fix av) av) vl)))
                     (setq an (entnext an)))))
(apply '+ vl))


  • 11 years later...
Posted

Hello! :) This lisp how about putting the resulting sum into other attribute in other block, instead of printing ito commandline??

When the lisp already sums up desired attribute values, could it just insert field formula into a selected attribute of another selected block? (or into a predefined TAG of selected block). Best regards to You all!

Posted

I am like David its an open ended question to sum all block attributes is the simplest, I would look at a universal method, but rather than ask for tag names use the order of the attributes. I want 1,2 & 5 summed. using VL-get-attribute just means cross checking against your requested attributes.

 

Msanddune where is the result to go ?

Posted (edited)

Testing something now.

 

Done this is a bit rough but shows a method of one code fits all. It needs a few If's so incorrect objects don,t crash it. It does need attributes as strings this could be checked for. If you enter a position twice it will add it to the total. The order is creation order not visual, again nentsel would help.

 

The attributes start with 1st as 0 not 1 hence the - 1 on entries but from a user point of view 1 is easier to recognise.

 

It only does 1 at a time but the original post is a bit vauge in what is required.

 

; test for summing attributes 
; By Alan H July 2017

(defun findatt (totnew x y obj / ) 
(foreach att (vlax-invoke obj 'getattributes)
(if (= y x)
(setq tot (+ (atof (vla-get-textstring att )) totnew))
)
(setq y (+ Y 1))
)
)

(defun sumatts ( / obj x y  ans tot totnew )
(setq lst '())
(while (/= nil (setq ans  (getint "Enter attribute order <Cr> to exit")))
(setq lst (cons (- ans 1) lst))
)

(setq tot 0)
(setq obj (vlax-ename->vla-object (ssname (ssget (list (cons 0 "insert"))) 0))) ; pick a block
(repeat (setq k (length lst))
(setq y 0)
(setq x (nth (setq k (- k 1)) lst))
(findatt tot x y obj)
)
(alert (rtos tot 2 2 ))
)

(sumatts)

Edited by BIGAL
Posted

 

Hi! I appreciate a lot the Lee Mac's routines, I use them a lot, thanks to Lee! I have a problem with sumattributes.lsp though, the table very often displays #### in result, after a while. Really I do not know what is the couse, for attributes deffinitons do not change, only the contents of attribute might update as those are fields linked to objects polylines area.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...