本帖最后由 kucha007 于 2023-5-9 17:20 编辑
求助出处:http://bbs.mjtd.com/forum.php?mo ... 762&fromuid=7329538
- ;找到属性文字标记含"灯"的块并计数
- (defun C:FB (/ SS i obj AttLst Flag Count STR p1 p2)
- (if (setq SS (ssget '((0 . "INSERT")(66 . 1)))) ;只选属性块
- (progn
- (setq Count 0) ;计数归零
- (repeat (setq i (sslength SS))
- (setq obj (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
- (setq AttLst (vlax-safearray->list
- (vlax-variant-value (vla-GetAttributes Obj))
- )
- ) ;收集块内属性成表
- (setq Flag T)
- (while (and Flag AttLst)
- (if (wcmatch (vla-get-TextString (car AttLst)) "*灯*") ;判断标记是否有"灯"
- (progn
- (setq Count (1+ Count))
- (setq Flag nil) ;找到一次就停止循环
- )
- (setq AttLst (cdr AttLst))
- )
- )
- )
- (if (eq Count 0)
- (princ "\n——★★★ 未找到符合条件的属性块 ★★★——")
- (if
- (and
- (setq STR (strcat "共选择了" (rtos Count 2 0) "个符合条件的属性块"))
- (setq p1 (getpoint "\n→请指定文字插入点:"))
- (setq p2 (getpoint p1 "\n→请指定第二点确定文字高度:"))
- )
- (entmake
- (list
- '(0 . "TEXT")
- (cons 1 STR) ;文字内容
- (cons 8 (getvar "Clayer")) ;图层名称
- (cons 10 p1) ;插入点
- (cons 40 (distance p1 p2)) ;文字高度
- )
- )
- )
-
- )
- (command "redraw")
- (princ)
- )
- )
- )
|