przem_saw Posted October 22, 2014 Share Posted October 22, 2014 Hi, to everyone. I was looking the routine everywhere with no success witch can in block "bar_1" take two attributes "tag1" and "tag2" multiple the two values and put the result in the same block in "tag3" Anyone can help ? Quote Link to comment Share on other sites More sharing options...
SLW210 Posted October 22, 2014 Share Posted October 22, 2014 (edited) I created a new thread AutoLISP, Visual LISP & DCL>Add attribute values Edited October 22, 2014 by SLW210 Quote Link to comment Share on other sites More sharing options...
David Bethel Posted October 22, 2014 Share Posted October 22, 2014 It is definitely doable, but more info or a sample is needed. -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 22, 2014 Share Posted October 22, 2014 Use a formula field in tag3, referencing the values in tags 1 & 2 - there is no need for LISP. Quote Link to comment Share on other sites More sharing options...
przem_saw Posted October 22, 2014 Author Share Posted October 22, 2014 Thanks for reply. I used to do that But unfortunately, currently I'm using a ZwCAD 2014 and for now the program doesn't support mathematical operations in field. That's why I need move all my calculations into a lisp routine. The perfect code will have an easy settings in the beginning like block name, tag and clear idea how to make calculation to make it more universal. I attached an example of basic idea. example.dwg Quote Link to comment Share on other sites More sharing options...
przem_saw Posted October 31, 2014 Author Share Posted October 31, 2014 Thanks to Lee Mac website I made this: I used diferent attributes names but it is easy to change now ;;ver 1.0 ;; cfany 2014.10.31 (defun c:re3 ( / ) (regen3) ) (defun regen3 ( / idx lst2 ss1 zas roz mno dod ile zas_o roz_o mno_o dod_o ) (if (and (setq ss1 (ssget "X" '((0 . "INSERT") (2 . "BAR_T2") (66 . 1))));only BAR_T2 blcks (setq zas "ZASIEG" roz "ROZ" mno "MNOZNIK" dod "DODATKOWY" ile "BAM") (repeat (setq idx (sslength ss1)) (setq idx (1- idx)) (setq bname (ssname ss1 idx)) ; (princ idx) (princ bname) (setq zas_o (LM:getattributevalue bname zas)) (setq roz_o (LM:getattributevalue bname roz)) (setq mno_o (LM:getattributevalue bname mno)) (setq dod_o (LM:getattributevalue bname dod)) (setq lst2 (itoa (* (+ (/ (atoi zas_o) (atoi roz_o)) (atoi dod_o)) (atoi mno_o)))) (LM:setattributevalue bname ile lst2) ; (princ zas) (princ "\n") ) ) (princ "\nZaktualizowano") ) (princ) ) ;; Set Attribute Value - Lee Mac ;; Sets the value of the first attribute with the given tag found within the block, if present. ;; blk - [ent] Block (Insert) Entity Name ;; tag - [str] Attribute TagString ;; val - [str] Attribute Value ;; Returns: [str] Attribute value if successful, else nil. (defun LM:setattributevalue ( blk tag val / enx ) (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))) (if (= (strcase tag) (strcase (cdr (assoc 2 enx)))) (if (entmod (subst (cons 1 val) (assoc 1 enx) enx)) (progn (entupd blk) val ) ) (LM:setattributevalue blk tag val) ) ) ) ;; Get Attribute Value - Lee Mac ;; Returns the value held by the specified tag within the supplied block, if present. ;; blk - [ent] Block (Insert) Entity Name ;; tag - [str] Attribute TagString ;; Returns: [str] Attribute value, else nil if tag is not found. (defun LM:getattributevalue ( blk tag / enx ) (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))) (if (= (strcase tag) (strcase (cdr (assoc 2 enx)))) (cdr (assoc 1 enx)) (LM:getattributevalue blk tag) ) ) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.