Hello everyone! It's nice to find a good resource for lisp on the net! I'm glad to be a part of this community!
I am working on a lisp that can repath a relative path for multiple xrefs in a drawing (I have all details, tb, and plans all xref'd into a sheet).
This is what I have now:
(defun
c:wds_relative_path (/ AP:SYSVARS AP:UNDOCTL AP:0LD-ERROR)
(setvar "cmdecho" 0)
(ap-push-error ap-error)
(ap-exit-transparent)
(ap-push-undo nil)
(ap-push-vars '(("osmode") ("orthomode")))
(ap-push-command)
(defun
filename (/ xPathControl2)
(setq xPathControl1 nil
xPathControl2
(strlen xrefPath)
xFileName1 xrefPath
)
(if (wcmatch xFilename1 "*\\*")
(while xPathControl2
(setq xPathControl1 (substr xFilename1 xPathControl2 1))
(if (= xPathControl1 "\\")
(setq xFilename1
(strcat (substr xFilename1 (1+ xPathControl2)))
xPathControl2 nil
)
(setq xPathControl2 (1- xPathControl2))
)
)
)
(if (wcmatch (strcase xFilename1) "*.DWG")
(setq xFilename1 (substr xFilename1 1 (- (strlen xFilename1) 4)))
)
(eval xFilename1)
)
(defun
xrefpathmod ()
(setq relativePath xrefPath)
(if (wcmatch (strcase relativePath) "*.DWG")
(setq relativePath (substr relativePath 1 (- (strlen relativePath) 4)))
)
(setq relativePath
(substr
relativePath
1
(- (strlen relativePath) (strlen xrefFilename))
)
)
(if (wcmatch relativePath "*:*")
(setq relativePath (substr relativePath 3))
)
(if (wcmatch (substr dwgPath (strlen dwgPath) 1) "\\")
(setq dwgPath (substr dwgPath 1 (1- (strlen dwgPath))))
)
(if (wcmatch relativePath "*ws-div1*")
(progn (setq flag 0)
(while (= flag 0)
(if (wcmatch (substr relativePath 1 7) "ws-div1")
(progn (setq relativePath (substr relativePath 9))
(setq flag 1)
)
(setq relativePath (substr relativePath 2))
)
)
)
)
(if (wcmatch (strcase dwgPath) "*ws-div1*")
(progn (setq flag 0)
(while (= flag 0)
(if (wcmatch (strcase (substr dwgPath 1 7)) "ws-div1")
(progn (setq dwgPath (substr dwgPath 8)) (setq flag 1))
(setq dwgPath (substr dwgPath 2))
)
)
)
)
(setq control1 0
control2 nil
count 0
x dwgPath
)
(while (/= control1 (strlen x))
(setq control1 (1+ control1)
control2 (substr x control1 1)
)
(if (= control2 "\\")
(setq count (1+ count))
)
)
(repeat count (setq relativePath (strcat ".." (chr 92) relativePath)))
)
(defun
wds_relative_path_main ()
(setq xref 1
flag 0
)
(while xref
(if (= flag 0)
(setq xref (tblnext "block" t))
(setq xref (tblnext "block"))
)
(setq flag 1)
(if xref
(progn
(setq dwgPath (getvar "dwgprefix"))
(if (member (cdr (assoc 70 xref)) '(36 44))
(progn
(setq xrefPath
(strcase (cdr (assoc 1 xref)))
xrefFilename
(filename)
xrefName
(strcase (cdr (assoc 2 xref)))
)
(if (and (= (strcase (substr xrefPath 1 1))
(strcase (substr dwgPath 1 1))
)
(wcmatch (strcase xrefPath) "*:*")
)
(progn (if (wcmatch (strcase xrefPath) "*:*")
(progn (xrefpathmod)
(if relativePath
(progn (setq relativePath
(strcase
(strcat
relativePath
xrefFilename
".dwg"
)
t
)
)
(if (findfile relativePath)
(progn (command
"xref"
"path"
xrefName
relativePath
)
)
)
)
)
)
)
)
)
)
)
)
)
)
(princ)
)
(wds_relative_path_main)
(ap-pop-command)
(ap-pop-vars)
(ap-pop-undo)
(ap-pop-error)
(princ)
)
;|«Visual LISP© Format Options»
(80 3 1 2 nil "end of " 80 5 0 0 0 T nil nil T)
;*** DO NOT add text below the comment! ***|;
I am new to lisp (know enough to be dangerous) and I can't get this to work. I would like to click a button on the toolbar to invoke the command for this lisp and have it automatically change all the xref paths to relative and repath to the folder in the job file.
My file structure is:
Job Folder
-CAD
-XREFS
The sheet where everything is referenced into is located in the CAD folder and the Xrefs are located in the XREFS folder.
I am using a modified version of AutoCAD LT 2008 that can run lisp files and such.
If anyone could help me, it would be greatly appreciated.
Let me know if anything needs clarification.
Thanks,
Mike