bwencadtutor 发表于 2022-7-6 14:46:31

如何识别块实例

需要帮助!
在模型空间中,有许多块实例具有一个块参照的不同属性值,如何识别每个实例?
 
我试图列出这一块引用的每个实例的所有属性值。
 
谢谢
 
必应

Lee Mac 发表于 2022-7-6 15:00:46

我会用这样的东西:
 

(defun c:getatts(/ bdef blk ss att aLst attLst)
(vl-load-com)
(setq bdef (getvar "INSNAME"))
(while (not blk)
   (setq blk (getstring t (strcat "\nSpecify Block to be Searched <" bdef ">: ")))
   (cond ((eq "" blk)
          (setq blk bdef))
         ((and (snvalid blk)
               (tblsearch "BLOCK" blk)))
         (T (setq blknil bdef ""))))
(if (setq ss (ssget "X" (list (cons 0 "INSERT")
                               (cons 2 blk)
                               (cons 66 1)
                               (if (getvar "CTAB")
                                 (cons 410 (getvar "CTAB"))
                                 (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
   (foreach x(mapcar 'cadr (ssnamex ss))
       (setq att (entnext x))
       (while (not (eq "SEQEND" (cdadr (setq aLst (entget att)))))
         (setq attLst (cons (cons (cdr (assoc 2 aLst))
                                  (cdr (assoc 1 aLst))) attLst)
               att    (entnext att))))
   (alert (vl-princ-to-string (reverse attLst))))
   (princ "\n<!> No Blocks Found <!>"))
(princ))

 
将以以下格式将所有属性列为关联列表:
 
(.)

Patrick_35 发表于 2022-7-6 15:08:56

你好
 
你可以替换这个
(foreach x(mapcar 'cadr (ssnamex ss))
       (setq att (entnext x))
       (while (not (eq "SEQEND" (cdadr (setq aLst (entget att)))))
         (setq attLst (cons (cons (cdr (assoc 2 aLst))
                                  (cdr (assoc 1 aLst))) attLst)
               att    (entnext att))))
   (alert (vl-princ-to-string (reverse attLst)))
+

Lee Mac 发表于 2022-7-6 15:18:06

很好,帕特里克-谢谢

bwencadtutor 发表于 2022-7-6 15:26:54

VBA可以接受吗?

Lee Mac 发表于 2022-7-6 15:36:29

我认为VBA也可以做到这一点,是的。

bwencadtutor 发表于 2022-7-6 15:38:27

我尝试了几种方法,但都没有成功。

Lee Mac 发表于 2022-7-6 15:47:04

我相信这里有人很乐意提供代码,但是我对VBA知之甚少。。。
页: [1]
查看完整版本: 如何识别块实例