本帖最后由 moshouhot 于 2023-5-24 16:22 编辑
代码不错,参考写了个转移图层的命令。
- (defun K:MoveEntitiesToLayer (srcLayer tgtLayer)
- (setq ss (ssget "_X" (list (cons 8 (strcase srcLayer)))))
- (if (and ss (> (sslength ss) 0))
- (progn
- (sssetfirst nil ss)
- (while (setq en (ssname ss 0))
- (setq obj (vlax-ename->vla-object en))
- (vla-put-layer obj tgtLayer)
- (ssdel en ss)
- )
- (princ (strcat "Entities on " srcLayer " layer moved to " tgtLayer " layer."))
- )
- (princ (strcat "No entities found on " srcLayer " layer or source layer does not exist."))
- )
- (princ)
- )
- (defun K:MoveObjToLayer (srcLayer tgtLayer objName)
- (setq srcLayer (strcase srcLayer) tgtLayer (strcase tgtLayer))
- (setq ss (ssget "_X" (list (cons 8 srcLayer) (cons 0 objName))))
- (if (and ss (> (sslength ss) 0))
- (progn
- (sssetfirst nil ss)
- (while (setq en (ssname ss 0))
- (setq obj (vlax-ename->vla-object en))
- (vla-put-layer obj tgtLayer)
- (ssdel en ss)
- )
- (sssetfirst nil ss) ; 取消选择集
- (princ (strcat "Entities on " srcLayer " layer with object type " objName " moved to " tgtLayer " layer."))
- )
- (princ (strcat "No entities found on " srcLayer " layer with object type " objName " or source layer does not exist."))
- )
- (princ)
- )
|