啊,我只是误读了代码,认为pth参数什么都没有。我的错误。
后来我发现我想在外部参照路径中查找并替换,然后将引用名称重命名为新建立的路径(这样我就不必乱用rename命令),然后重新加载所有引用以显示结果。为了做到这一点,我非常笨拙地拼凑了三段独立的代码,并取得了成功——至少在我的具体案例中是这样。没有错误捕捉和一些潜在的有缺陷的逻辑,但这里是:
- (defun c:fixpath4 ( / new old pth )
-
- (setq old (getstring t "\nSpecify string to find: "))
- (setq new (getstring t "\nSpecify string to replace: "))
-
- (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
- (if
- (and
- (= :vlax-true (vla-get-isxref blk))
- (vl-string-search old (vl-filename-base (setq pth (vla-get-path blk))))
- )
- (vla-put-path blk
- (strcat
- (vl-filename-directory pth) "\"
- (vl-string-subst new old (vl-filename-base pth)) ".dwg"
- )
- )
- )
- )
- (vlax-for bo (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
- (if (= (vla-get-IsXref bo) :vlax-true)
- (progn
- (setq name (vla-get-Path bo))
- (while (wcmatch name "*\\*")
- (setq name (substr name (+ (vl-string-search "\" name) 2)))
- )
- (while (wcmatch name "*.[dD][wW][gG]")
- (setq name (substr name 1 (- (strlen name) 4)))
- )
- (vl-catch-all-apply 'vla-put-Name (list bo name))
- )
- )
- )
- (setvar "modemacro" "Reloading loaded xrefs......please wait......")
- (setvar "cmdecho" 0)
- (setq cObj(tblnext "BLOCK" T))
- (while cObj
- (setq cName(cdr(assoc 2 cObj)))
- (if
- (and
- (=(logand(cdr(assoc 70 cObj))32)32)
- (=(logand(cdr(assoc 70 cObj))4)4)
- ); end and
- (progn
- (vl-cmdf "_.xref" "_unload" cName)
- (vl-cmdf "_.xref" "_reload" cName)
- ); end progn
- ); wnd if
- (setq cObj(tblnext "BLOCK"))
- ); end while
- (setvar "modemacro" ".")
- (setvar "cmdecho" 1)
- (prompt "\n--- Xref change finished! ---")
- (princ)
- )
- (vl-load-com) (princ)
借用此线程:http://www.cadtutor.net/forum/showthread.php?62998-更改“引用名称”以匹配外部参照文件名&
在花了6-8个小时深夜研究代码片段和大量建议之后,我不得不说,这种lisp语言令人耳目一新。很遗憾,我很难找到它的文档,而且沼泽不接受新成员! |