Jump to content

Add attribute values


przem_saw

Recommended Posts

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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...

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)
       )
   )
)

Link to comment
Share on other sites

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...