陨落
发表于 2016-7-12 16:37:25
本帖最后由 陨落 于 2016-7-12 16:39 编辑
曰微言薄论 发表于 2016-7-12 15:10 static/image/common/back.gif
炸开不慢,历遍也不慢,但是慢在处理么多对象的包围盒
(defun c:tt()
(vl-load-com)
(setq blk(car (entsel"\n选择块"))
bwb nil)
(foreach x(setq exploded(vlax-safearray->list (vlax-variant-value(vla-explode (vlax-ename->vla-object blk)))))
(if (not (wcmatch (cdr (assoc 0(entget(setq enx(vlax-vla-object->ename x))))) "*TEXT"))
(PROGN(vla-getboundingbox x 'pt1 'pt2)
(setq pt1 (vlax-safearray->list pt1)
pt2 (vlax-safearray->list pt2)
bwb(cons pt1 bwb)
bwb(cons pt2 bwb))
)
)
)
(foreach x exploded(entdel (vlax-vla-object->ename x)))
(setq bwb (vl-sort bwb'(lambda (e1 e2) (< (car e1) (car e2))))
x1 (car(car bwb))
x2 (car(last bwb)))
(setq bwb (vl-sort bwb'(lambda (e1 e2) (< (cadr e1) (cadr e2))))
y1 (cadr(car bwb))
y2 (cadr(last bwb)))
(setq box(list (list x1 y1)(list x2 y2)))
(command "rectangle" (car box)(cadr box))
(vla-put-color (vlax-ename->vla-object (entlast))1)
)
包括rectangle在内,处理一个动态块不到1s,应该比手动要快了,代码还有很大的优化空间
不知道楼主的20s是怎么写的
曰微言薄论
发表于 2016-7-12 16:52:06
陨落 发表于 2016-7-12 16:37 static/image/common/back.gif
(defun c:tt()
(vl-load-com)
(setq blk(car (entsel"\n选择块"))
不知道你用附件中的动态块尝试了没有。我这边用你的函数处理结果是,只能炸开块,不能够生成包围盒。
陨落
发表于 2016-7-12 16:56:24
曰微言薄论 发表于 2016-7-12 16:52 static/image/common/back.gif
不知道你用附件中的动态块尝试了没有。我这边用你的函数处理结果是,只能炸开块,不能够生成包围盒。
用的就是你的附件测试的
曰微言薄论
发表于 2016-7-12 17:26:25
我用你的代码,结果是上面的样子,有些准确有些错误。
曰微言薄论
发表于 2016-7-12 17:30:36
陨落 发表于 2016-7-12 16:56 static/image/common/back.gif
用的就是你的附件测试的
有没有不用炸开的方法能得到包围盒?或者思路?
陨落
发表于 2016-7-12 20:14:39
曰微言薄论 发表于 2016-7-12 17:26 static/image/common/back.gif
我用你的代码,结果是上面的样子,有些准确有些错误。
图再传上来看看
小菜123
发表于 2016-7-12 23:36:30
本帖最后由 小菜123 于 2016-7-13 08:39 编辑
可能是楼主的CAD有问题,不要用简化版,原盘安装
速度慢的一个原因是因为块中的文字都打碎成线了,实体数量过多
kozmosovia
发表于 2016-7-13 14:32:56
对于这种奇葩块,最快还是我之前说的,炸开只选择四个顶点的封闭多线段来求包围框最快。
头大无恼
发表于 2018-10-7 19:23:26
曰微言薄论 发表于 2016-7-12 17:30
有没有不用炸开的方法能得到包围盒?或者思路?
先把动态块在位复制一个,再用entmod重写,得到一个与之前动态块一样的匿名块,,去除动态块的属性,然后再计算包围框,再删除匿名块
头大无恼
发表于 2018-10-7 19:30:03
本帖最后由 头大无恼 于 2018-10-7 20:42 编辑
;;动态块改为普通快 By Gu_xl 2013.11.13
(defun c:DynBlk2blk (/ cnt)
(if (ssget (list '(0 . "INSERT") (cons 410 (getvar 'CTAB))))
(progn
(setq cnt 0)
(vlax-for obj
(vla-get-activeselectionset
(vla-get-activedocument (vlax-get-acad-object))
)
(if (and
(vlax-property-available-p obj 'isdynamicblock)
(eq :vlax-true (vla-get-isdynamicblock obj))
)
(progn
(setq cnt (1+ cnt))
(vla-ConvertToAnonymousBlock obj)
)
)
)
(princ (strcat "\n***共修改 " (itoa cnt) " 个动态块***"))
)
)
(princ)
)
;;动态块改为普通快 By Gu_xl 2013.11.13
(defun c:tt (/ lst name blkdef blkref cnt)
(if (ssget (list '(0 . "INSERT") (cons 410 (getvar 'CTAB))))
(progn
(setq cnt 0)
(vlax-for obj
(vla-get-activeselectionset
(vla-get-activedocument (vlax-get-acad-object))
)
(if (and
(vlax-property-available-p obj 'isdynamicblock)
(eq :vlax-true (vla-get-isdynamicblock obj))
)
(progn
(setq lst nil
cnt (1+ cnt)
)
(vlax-for a (vla-item (vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(vla-get-name obj)
)
(setq lst (cons a lst))
)
(setq blkdef
(vla-add
(vla-get-blocks
(vla-get-activedocument (vlax-get-acad-object))
)
(vlax-3d-point '(0 0 0))
"*U"
)
)
(vla-CopyObjects
(vla-get-activedocument (vlax-get-acad-object))
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbobject
(cons 0 (1- (length lst)))
)
lst
)
)
blkdef
)
(setq name (vla-get-name blkdef))
(setq blkref
(vla-InsertBlock
(vlax-get-property
(vla-get-activedocument (vlax-get-acad-object))
(if (= 1 (getvar 'CVPORT))
'PaperSpace
'ModelSpace
)
)
(vla-get-InsertionPoint obj)
Name
(vla-get-XScaleFactor obj)
(vla-get-YScaleFactor obj)
(vla-get-ZScaleFactor obj)
(vla-get-Rotation obj)
)
)
(vla-put-layer blkref (vla-get-layer obj))
(vla-delete obj)
)
)
)
(princ (strcat "\n***共修改 " (itoa cnt) " 个动态块***"))
)
)
(princ)
)
(defun c:tt (/ cnt)
(if (ssget (list '(0 . "INSERT") (cons 410 (getvar 'CTAB))))
(progn
(setq cnt 0)
(vlax-for obj
(vla-get-activeselectionset
(vla-get-activedocument (vlax-get-acad-object))
)
(if (and
(vlax-property-available-p obj 'isdynamicblock)
(eq :vlax-true (vla-get-isdynamicblock obj))
)
(progn
(setq cnt (1+ cnt))
(vla-ConvertToAnonymousBlock obj)
)
)
)
(princ (strcat "\n***共修改 " (itoa cnt) " 个动态块***"))
)
)
(princ)
)