前辈早就写过了
- ;| (xo-infdo fname vcol func) = dbx技术对文件内集合进行操作
- 参数: fname = cad文件(*.dwg格式)
- vcol = 集合列表.如'(modelspace paperspace)
- func = 操作函数名, 如: 'xx 或 '(lambda(x)....)
- 操作函数必须含一个变量(集合内实体). 如: (defun xx (x) ...)
- 返回: 分别操作的表(表内容根据函数来定义).
- 说明: vcol可以是如下集合:
- All Collection Objects(所有的集合实体:)
- Blocks Dictionaries DimStyles funccuments FileDependencies Groups
- Hyperlinks Layers Linetypes MenuBar MenuGroups ModelSpace
- PaperSpace PlotConfigurations PopupMenu PopupMenus
- RegisteredApplications SelectionSets TextStyles Toolbar
- Toolbars UCSs Viewports Views
- |;
- (defun xo-infdo (fname vcol func / doc CNAME RET
- VERKEY DOC E ENT I REGKEY SS
- SSBLK ATTS BLKS CDOC CNAMES DOCS llays
- )
- (setq fname (strcase fname))
- (print fname)
- (setq cdoc (vla-get-activedocument (vlax-get-acad-object)))
- (setq cname (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")))
- ;; 当前文件名.
- (vlax-for x (vlax-get (vlax-get-acad-object) 'documents)
- (setq docs (cons x docs))
- )
- (setq cnames
- (mapcar
- '(lambda (x)
- (strcase (strcat (vla-get-path x) "\\" (vla-get-name x))
- )
- )
- docs
- )
- )
- ;(setq fname cname)
- (if (member fname cnames)
- (progn
- ;; v1.5加入,锁定图层解锁.>>可放入为xo-infdo的参数.后补>>
- (evaldo cdoc
- (vla-get-layers cdoc)
- '(lambda (x)
- (if (= :vlax-true (vla-get-lock x))
- (progn (setq llays (cons x llays))
- (vla-put-lock x :vlax-false)
- )
- )
- )
- )
- (evalcur
- (setq
- doc (nth (- (length docs) (length (member fname cnames)))
- docs
- )
- )
- ) ;处理当前文件,evalcur函数
- (mapcar '(lambda (x) (vla-put-lock x :vlax-true)) llays)
- )
- ;; 处理非当前文件.
- (progn
- (setq verkey (if (> (atoi (getvar "AcadVer")) 15)
- ".16"
- ""
- )
- *DBXDOC (vla-getinterfaceobject
- (vlax-get-acad-object)
- (strcat "ObjectDBX.AxDbDocument" verkey)
- )
- )
- (vla-open *dbxdoc fname :vlax-false) ;open
- ;; v1.5加入,锁定图层解锁.>>可放入为xo-infdo的参数.后补>>
- (evaldo *dbxdoc
- (vla-get-layers *dbxdoc)
- '(lambda (x)
- (if (= :vlax-true (vla-get-lock x))
- (progn (setq llays (cons x llays))
- (vla-put-lock x :vlax-false)
- )
- )
- )
- )
- ;;
- (setq
- ret (mapcar '(lambda (x)
- (evaldo *dbxdoc (vlax-get *dbxdoc x) func)
- ;evaldo 函数
- )
- vcol
- )
- ) ;(vlax-dump-object *dbxdoc T)
- ;; v1.5加入,锁定图层解锁恢复>>
- (mapcar '(lambda (x) (vla-put-lock x :vlax-true)) llays)
- ;;
- (vlax-invoke *dbxdoc 'saveas fname)
- (vlax-release-object *dbxdoc)
- )
- )
- ret
- )
|