Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cad blocks and automatic calculations on attributes 1

Status
Not open for further replies.

vbcad

Technical User
Jul 12, 2002
159
US
I have a block i would like to get attributes data from perform calculations on the attributes and then update an attribute with the result from the calculation. Is this possible with lisp or do i need to use visual basic with excel? I would prefer to keep the routine contained to Autocad.
 
Hi,
LISP is fine. You can do it in VBA too. Here is anippet to change an attribute:

;------------------------------------------------------------------------------
; ATT_UPD: Update the attributes of a block given by the eref according to the
; information in the <att_list>.
;
; - syntax: (att_upd <eref> <att_list>) -> T/nil
- returns nil if an error is detected, T otherwise
; - <att_list> is a list with format: ( (<att tag>.<att data>) (etc.)...)
;
; Note: no error occurs if the block's attributes don't match those in the
; <att_list>. Data is transferred between all matching attribute
; tag names - if there's a mismatch the program doesn't mind at all,
; but no data transfer will occur for that particular item.
;
; - no library dependencies
;
(defun att_upd (block_ref att_lst / ent_data)
; if the block_ref parameter is not an eref to a block insertion, the
; program will crash
(cond
( (= nil (entnext block_ref)) nil) ;no entities following
( (/= 1 (cdr (assoc 66 (setq ent_data (entget block_ref))))) nil) ; no attributes
( T
(while ; cycle through all attributes...
(= &quot;ATTRIB&quot; (cdr (assoc 0 (setq ent_data (entget (entnext (cdr (assoc -1 ent_data))))))))
(setq att_tag (cdr (assoc 2 ent_data)))
(cond
( (setq new_att (assoc att_tag att_lst)) ;mismatch filtering...
(entmod
(subst (cons 1 (cdr new_att) (assoc 1 ent_data) ent_data)
)
)
)
)
(entupd block_ref) ; regen the block
T
)
)
)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top