如start4444 ' 原地踏步 所说,目前无法利用块名,直接得块的长跟宽
只能通过先插入块,得块的长跟宽
如程式本身是先输入得到块名与块座标点
插入第一个块后,得到长跟宽,再去插入第二个块
可以利用以下 Gu_xl 版主 的 函数
;;参数 pt = 点 blockname = 块名
(defun getinertBypt(pt BlockName / h p1ss sl en ll ur)
(setq h (getvar 'viewsize)) ;_ 屏幕高
(setq p1 (list (car pt) (+ (cadr pt) (* 0.5 h)) 0))
(setq ss (ssget "F"
(list pt p1)
(list (cons 0 "insert") (cons 2 BlockName))))
(if ss
(progn
(repeat (setq i (sslength ss))
(setq sl (cons (ssname ss (setq i (1- i))) s))
)
(setq sl
(vl-sort sl
'(lambda (a b)
(< (distance pt (cdr (assoc 10 (entget a))))
(distance pt (cdr (assoc 10 (entget b))))
)
)
)
)
;;得到点位置处的块图元名
(setq en (car sl))
(vla-getboundingbox (vlax-ename->vla-object en) 'll 'ur)
(setq ll (vlax-safearray->list ll)
ur (vlax-safearray->list ur);得到长跟宽
)
(if (<= (cadr ll) (cadr pt) (cadr ur))
(progn
(redraw en 3) ;_ 亮显
;;返回值
en
)
)
)
)
)
(defun c:tt (/ blk enname minp maxp xlst ylst i)
(setq blk (tblsearch "block" "test"))
(setq enname (cdr (last blk)))
(minpmaxp enname)
(setq xlst (list (car minp) (car maxp)))
(setq ylst (list (cadr minp) (cadr maxp)))
(while (setq enname (entnext enname))
(minpmaxp enname)
(setq xlst (cons (car minp) xlst))
(setq ylst (cons (cadr minp) ylst))
(setq xlst (cons (car maxp) xlst))
(setq ylst (cons (cadr maxp) ylst))
)
(princ (strcat "高:"(rtos(- (apply 'max ylst) (apply 'min ylst))2 2)))
(princ (strcat "宽:"(rtos(- (apply 'max xlst) (apply 'min xlst))2 2)))
(princ)
)
(defun minpmaxp (ent / obj P1 P2)
(setq obj (Vlax-Ename->Vla-Object ent))
(Vlax-Invoke-Method obj 'GetBoundingBox 'P1 'P2)
(setq minp (vlax-safearray->list P1)
maxp (vlax-safearray->list P2)
)
) gaics 发表于 2020-7-3 09:28
(defun c:tt (/ blk enname minp maxp xlst ylst i)
(setq blk (tblsearch "block" "test"))
(setq e ...
Error: 参数类型错误: enamep: nil
还请大侠指导指导
页:
1
[2]