感谢李的网站,我做到了这一点:
我使用了不同的属性名称,但现在很容易更改
- ;;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)
- )
- )
- )
|