- 积分
- 2376
- 明经币
- 个
- 注册时间
- 2021-12-13
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2022-11-18 17:23:06
|
显示全部楼层
修改了下,之前块名有问题
本帖最后由 wosiguwozai0830 于 2022-11-18 17:24 编辑
;批量建块,参考http://bbs.mjtd.com/forum.php?mo ... %E9&_dsign=d48aa375,作者:htlaser
(defun c:pljk( / ss qianzui blkname)
(setq qianzui(getstring"\n请输入块名的前缀:"))
(while (setq ss(ssget))
(setq blkname (vl-string-subst qianzui "华星切割" (menucmd "M=$(edtime,$(getvar,date),华星切割YYYY-MO-DD-HH-MM-SS)")))
(emkblk ss (car(ss:boundingbox ss)) blkname)
(setq ss nil)
)
(alert "批量建块完成。")
(princ)
)
;生成普通块,来源于明经论坛
(defun emkblk (ss pt name / i)
(entmake (list '(0 . "block") (cons 2 name) '(70 . 0) (cons 10 pt)))
(repeat (setq i (sslength ss)) (entmake (cdr (entget (ssname ss (setq i (1- i)))))) )
(entmake '((0 . "ENDBLK")))
(command "_.erase" ss "")
(entmake (list '(0 . "INSERT") (cons 2 name) (cons 10 pt)))
)
;选择集的包围盒,返回左上角和右下角
(defun ss:boundingbox(ss / ptb minx miny maxx maxy)
(setq ptb(mapcar '(lambda(x)(list (last(LM:boundingbox x))(cadr(LM:boundingbox x))))(sstolistf ss)))
(setq minx(apply 'min (mapcar 'caar ptb)))
(setq miny(apply 'min (mapcar '(lambda(x)(cadr(cadr x))) ptb)))
(setq maxx(apply 'max (mapcar '(lambda(x)(car(cadr x))) ptb)))
(setq maxy(apply 'max (mapcar '(lambda(x)(cadr(car x))) ptb)))
(list (list minx maxy 0)(list maxx miny))
)
;; Bounding Box - Lee Mac
;; Returns the point list describing the rectangular frame bounding the supplied object.
;; obj - [vla] VLA-Object
;图形的包围点,对矩形来说,第一点为左下角点,输入参数为图元名
(defun LM:boundingbox ( ent / obj a b lst )
(setq obj(vlax-ename->vla-object ent))
(if
(and
(vlax-method-applicable-p obj 'getboundingbox)
(not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'a 'b))))
(setq lst (mapcar 'vlax-safearray->list (list a b)))
)
(mapcar '(lambda ( a ) (mapcar '(lambda ( b ) ((eval b) lst)) a))
'(
(caar cadar)
(caadr cadar)
(caadr cadadr)
(caar cadadr)
)
)
)
)
;将选择集转换成图元名表,参数选择集
(defun sstolistf(ss)
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
)
|
|