przem_saw 发表于 2022-7-5 22:16:22

添加属性值

大家好。
我到处寻找例程,但没有成功,它可以在块“bar_1”中取两个属性“tag1”和“tag2”乘以这两个值,并将结果放在“tag3”的同一块中
有人能帮忙吗?

SLW210 发表于 2022-7-5 22:35:35

我创建了一个新线程
AutoLISP、Visual LISP和DCL>添加属性值

David Bethel 发表于 2022-7-5 22:43:01

这肯定是可行的,但需要更多的信息或样本-大卫

Lee Mac 发表于 2022-7-5 23:03:02

使用标记3中的公式字段,引用标记1和2中的值-不需要LISP。

przem_saw 发表于 2022-7-5 23:15:01

谢谢你的回复。
我过去经常这么做
但不幸的是,目前我使用的是ZwCAD 2014,目前该程序不支持现场数学运算。
这就是为什么我需要将所有计算转移到lisp例程中。
完美的代码在开始时会有一个简单的设置,如块名、标记和如何进行计算以使其更通用的清晰想法。
我附上了一个基本想法的例子。
实例图纸

przem_saw 发表于 2022-7-5 23:23:53

感谢李的网站,我做到了这一点:
我使用了不同的属性名称,但现在很容易更改
;;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))));onlyBAR_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 - Block (Insert) Entity Name
;; tag - Attribute TagString
;; val - Attribute Value
;; Returns: 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 - Block (Insert) Entity Name
;; tag - Attribute TagString
;; Returns: 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)
       )
   )
)
页: [1]
查看完整版本: 添加属性值