本帖最后由 llsheng_73 于 2023-3-13 16:10 编辑
- (defun ingroup(e f / a);;如果图元e在编组里边,f为真返回编组对象及组内图元名,f为nil返回编组名及组内图元名,否则返回nil
- (or(=(type e)'ename)(setq e(vlax-vla-object->ename e)))
- (if(and(setq e(member'(102 . "{ACAD_REACTORS")(entget e)))
- (setq e(member'(102 . "}")(reverse e))))
- (vl-remove'nil(mapcar'(lambda(x / e a)(if(member'(0 . "GROUP")(setq e(entget(cdr x))))
- (cons(if f(vlax-ename->vla-object(cdar e))(cdar e))(mapcar'cdr (vl-remove-if'(lambda(x)(/=(car x)340))e)))))
- (vl-remove-if-not'(lambda(x)(=(car x)330))e)))))
- (defun removefromgroup(ens)
- (vl-some(function(lambda(x)(vl-some(function(lambda(y)(VL-CATCH-ALL-APPLY'vla-RemoveItems(list(car y)(l2array(list x))))nil))(INGROUP x t))nil))
- (setq ens(if(listp ens)(vl-remove'nil ens)(list ens)))))
- (defun addtogroup(ob ens);;;图元编组ob编组对象,ens要加入该编组的图元,ob为nil或者非编组对象时,ens加入到一个未命名编组l2arra自定义图元转对象数组函数
- (or(=(VL-CATCH-ALL-APPLY'vla-get-ObjectName(list ob))"AcDbGroup")
- (setq ob(vla-add(vla-get-groups(vla-get-ActiveDocument(vlax-get-acad-object)))"*")))
- (vla-AppendItems ob(l2array ens)))
- (defun l2array(l / A);;;图元(或对象)表转为对象数组
- (vlax-safearray-fill(vlax-make-safearray 9(cons 0(1-(length l))))
- (mapcar(function(lambda(x / a)(setq a(type x))(cond((='ename a)(vlax-ename->vla-object x))((='VLA-OBJECT a)x))))l)))
我个人基本就用这三个收拾组。。。
如果需要查所有组名,可以查当前文档的GROUPS对象然后获取,个人用以下函数
- (defun ObjItems(Obj Sets item / l a)
- (if item(defun a(x)(if(vl-catch-all-error-p(setq x(vl-catch-all-apply'vlax-get-property(list x item))))nil x))(defun a(x)x))
- (if(not(vl-catch-all-error-p(vl-catch-all-apply'vlax-get-property(list Obj Sets))))
- (setq Sets(if Sets(vl-catch-all-apply'vlax-get-property(list Obj Sets))Obj))
- (if(vlax-method-applicable-p obj(strcat"get"(VL-PRINC-TO-STRING sets)))
- (setq sets(eval(list(read(strcat"vla-get"(VL-PRINC-TO-STRING sets)))obj)))))
- (if(=(type sets)'variant)(mapcar'a(vlax-safearray->list(variant-value sets)))
- (vlax-for x Sets(setq l(cons(a x)l)))))
(ObjItems(vlax-get-property(vlax-get-acad-object)'activedocument)'groups 'name)
编组虽然方便,但很脆弱,跨图复制组就散了,比较麻烦,另外,同一图元对象可能同时处于多个不同的组,出现这种情况也比较麻烦,当然可以通过
ingroup查出图元或对象所在的所有编组,再考虑怎么收拾
|