本帖最后由 llsheng_73 于 2022-12-10 13:45 编辑
- (defun GetFolder(msg / WinShell shFolder path catchit);选取文件夹
- (setq shFolder(vlax-invoke-method (vlax-create-object "Shell.Application")'BrowseForFolder 0 msg 1))
- (setq catchit(vl-catch-all-apply'(lambda()(setq shFolder(vlax-get-property shFolder'self))
- (setq path(vlax-get-property shFolder'path)))))
- (if(vl-catch-all-error-p catchit)nil path))
- (defun xdirectory(folder)
- (setq folder(list(list folder)))
- (while(car(setq folder(cons(apply'append(mapcar'(lambda(x)(mapcar'(lambda(y)(strcat x"\\"y))(cddr(vl-directory-files X nil -1))))
- (car folder)))folder))))(apply'append folder))
- (defun getpath(msg ext / path paths files)
- (and(setq path(GETFOLDER msg))
- (setq paths(XDIRECTORY path))
- (setq files(apply'append(mapcar'(lambda(x)(mapcar'(lambda(y)(strcat x "\\"y))(VL-DIRECTORY-FILES x ext 1)))paths)))
- )(list paths files))
- (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)))
- (defun c:tt(/ files acad layers *DBX *Dbmdl blk doc blkname acVer)
- (vl-load-com)
- (setq acad(vlax-get-acad-object)
- doc(vlax-get-property acad'activedocument)
- acVer(atoi(getvar "ACADVER"))
- *DBX(vla-GetInterfaceObject *ACAD(if(< acVer 16)"ObjectDBX.AxDbDocument"(strcat"ObjectDBX.AxDbDocument."(itoa acVer))))
- *Dbmdl(vla-get-ModelSpace *dbxobj)
- blk(vlax-invoke-method(vlax-get-property doc'blocks)'add(vlax-3d-point 0 0)"*U")
- blkname(vlax-get-property blk'name))
- (and(setq files(cadr(GETPATH"指定要合并的Excel文件夹""*.dwg")))
- (vl-some(function(lambda(x / lays la lay)
- (vlax-for x blk(vlax-invoke-method x 'delete))
- (and(not(VL-CATCH-ALL-ERROR-P(VL-CATCH-ALL-APPLY(function vlax-invoke-method)(List(*DBX"open"x)))))
- (vlax-for x(vlax-get-property *DBX'layers)(setq lays(cons(list(vlax-get-property x 'name))lays)))
- (vlax-for x *Dbmdl
- (setq la(assoc(vlax-get-property x'layer)lays)lays(cons(vl-list*(car la)x(cdr la))(vl-remove la lays))))
- (vl-some(function(lambda(a)
- (and(cadr a)
- (vlax-invoke-method doc'wblock(strcat(VL-FILENAME-DIRECTORY x)(VL-FILENAME-base x)(car a)".dwg")
- (vlax-invoke-method *DBX'CopyObjects(l2array(cdr a))))
- nil)))lays))))
- files))
- (vlax-invoke-method blk 'delete))
未来得及测试
|