试试这个,伙计:
(我正在学习这个ObjectDBX的东西,所以有点碰运气……)
- ;; ObjectDBX Tester by Lee McDonnell (Lee Mac)
- ;; Credit to Tony Tanzillo for Directory Browser, Tim Willey
- (defun c:MacDwg (/ refLst *error* *acad Shell fDir Dir dbx lay Tag)
- (vl-load-com)
- (setq refLst '(
- ("FOO-BAR-E" . "FOO-BAR-N")
- ("FOO-CAR-E" . "FOO-CAR-N")
- )
- )
- (defun *error* (e)
- (if ov (mapcar 'setvar vl ov))
- (ObjRel (list Shell dbx *acad))
- (if (not (wcmatch (strcase e) "*CANCEL*,*EXIT*"))
- (princ (strcat "\n<< Error: " e " >>")))
- (princ))
- (setq *acad (vlax-get-acad-object)
- Shell (vla-getInterfaceObject *acad "Shell.Application")
- fDir (vlax-invoke-method Shell 'BrowseForFolder
- (vla-get-HWND *acad) "Select Directory: " 0))
- (if fDir
- (progn
- (setq Dir
- (vlax-get-property
- (vlax-get-property fDir 'Self) 'Path))
- (if (not (eq "\" (substr Dir (strlen Dir))))
- (setq Dir (strcat Dir "\")))
- (if (< (atoi (setq acVer (substr (getvar "ACADVER") 1 2))) 16)
- (setq acVer "") (setq acVer (strcat (chr 46) acVer)))
- (setq dbx (vla-getInterfaceObject
- *acad (strcat "ObjectDBX.AxDbDocument" acVer)))
- (princ "\nProcessing...")
- (foreach dwg (setq dwLst
- (mapcar
- (function
- (lambda (x)
- (strcat Dir x)))
- (vl-directory-files Dir "*.dwg" 1)))
- (vla-open dbx dwg)
- (vlax-for Lay (vla-get-layouts dbx)
- (vlax-for Obj (vla-get-Block lay)
- (if (setq Tag (assoc (vla-get-layer Obj) refLst))
- (vla-put-layer Obj (cdr Tag)))))
-
- (vla-saveas dbx dwg)
- (princ (chr 46)))
- (princ (strcat "\n<< " (rtos (length dwLst) 2 0) " Drawings Processed >>"))))
-
- (ObjRel (list Shell dbx *acad))
- (gc)
- (princ))
-
- (defun ObjRel (lst)
- (mapcar
- (function
- (lambda (x)
- (if (and (eq (type x) 'VLA-OBJECT)
- (not (vlax-object-released-p x)))
- (vl-catch-all-apply
- 'vlax-release-object (list x))))) lst))
|