这么多代码啊,看看下面这个,论坛里面找来的,具体谁的忘了,时间有点久了- ;;;;参照图块路径改为“相对路径” 且 自动重载XREF
- (defun C:Tools-BLK-XrefPathAutoLoad (/ ssg xpath i obj enl elist blkdef path n)
- (setq ssg (ssget "x" '((0 . "insert"))))
- (setq XPath (getvar "dwgprefix")) ;_取得当前文档路径
- (setq i 0)
- (setq n 0)
- (if ssg
- (repeat (sslength ssg)
- (setq obj (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (cdr (assoc 2 (setq enl (entget (ssname ssg i)))))))
- (if (= (vla-get-isxref obj) :vlax-true) ;_判断给定的图块是否为XRef图块
- (progn
- ;;(vla-put-path obj (strcat xpath (vla-get-name obj) ".dwg"));_参照图块路径改为“绝对路径
- (setq elist (entget (tblobjname "block" (cdr (assoc 2 enl))))) ;_获取参照图块的图元表
- (setq blkdef (vlax-ename->vla-object (cdr (assoc 330 elist))))
- (setq path (vla-get-path blkdef)) ;_取得外部参照的路径
- (setq path (vl-filename-base path)) ;_去掉文件的路径和扩展名,返回文件的名称
- (vla-put-path blkdef (strcat ".\" path ".dwg")) ;_参照图块路径改为“相对路径”
- (setq n (1+ n))
- )
- )
- (setq i (1+ i))
- )
- )
- (if (> n 0)
- (progn
- (command "_xref" "r" "*")
- (princ "\n**** Xref路径已改为“相对路径”****")
- )
- (princ "\n**** 没有外部参照 或 外部参照没有加载 ****")
- )
- (princ)
- )
|