AutoCAD/lsp to reload and unload an xref
Expert: Bill DeShawn - 10/28/2010
Question(defun c:XX ()
(if (or (or (= xref "") (= xref "none")) (= xref nil))
(alert "set xref name"))
(if (or (or (= xref "") (= xref "none")) (= xref nil))
(progn
(prompt (strcat "\n<-none->"))
(setq xref (getstring " xref name: "))))
(if (= a1 nil) (setq b1 0) (setq b1 a1))
(setq a1 b1)
(setq c1 (if (= 0 b1) (setq a1 1) (setq a1 0)))
(if (= a1 1) (progn (command "XREF" "u" XREF)))
(if (= a1 0) (progn (command "XREF" "r" XREF))))
i cant seem to make this work.. and this lsp requires me to type the name of the xref. what would be more convenient is if i could select the xref and unload/reload it by using one shortkey command. i am hoping you could help me with this.. thank you so much..
AnswerMich:
Try these out:
;XUNLOAD.LSP V.1.0 10-8-07
;By Bill DeShawn bdeshawn@sterling.net
;This is freeware
;Permission granted to distribute
;Permission denied to modify. Inform me. I'll do it.
;Not responsibile for any damage to anybody or anything.
;If you don't get it from me, it isn't mine.
(defun xulerr (msg)
(if c:r (c:r) redraw)
(setq ent nil elist nil xrefname nil)
(setq *error* olderr)
(princ msg)
(prompt ". Please try again.")
(princ)
)
(defun c:xunload (/ ent elist xrefname fname)
(setq olderr *error*)
(setq *error* xulerr)
(setq ent (entsel "\nSelect the Xref to unload: "))
(setq elist (entget (car ent)))
(setq xrefname (cdr (assoc 2 elist)))
(command "xref" "u" xrefname)
(setq fname (findfile (strcat xrefname ".dwg")))
(if (not (null fname ))
(prompt (strcat "\nFile used - " (findfile (strcat xrefname ".dwg"))))
(prompt "\nFile not found. ")
)
(setq *error* olderr)
(princ)
)
AND:
;XRELOAD.LSP V.1.3 8-2-00
;By Bill DeShawn bdeshawn@prodigy.net
;This is freeware
;Permission granted to distribute
;Permission denied to modify. Inform me. I'll do it.
;Not responsibile for any damage to anybody or anything.
;If you don't get it from me, it isn't mine.
(defun xreerr (msg)
(if c:r (c:r) redraw)
(setq ent nil elist nil xrefname nil)
(setq *error* olderr)
(princ msg)
(prompt ". Please try again.")
(princ)
)
(defun c:xreload (/ ent elist xrefname fname)
(setq olderr *error*)
(setq *error* xreerr)
(setq ent (entsel "\nSelect the Xref to reload: "))
(setq elist (entget (car ent)))
(setq xrefname (cdr (assoc 2 elist)))
(command "xref" "r" xrefname)
(setq fname (findfile (strcat xrefname ".dwg")))
(if (not (null fname ))
(prompt (strcat "\nFile used - " (findfile (strcat xrefname ".dwg"))))
(prompt "\nFile not found. ")
)
(setq *error* olderr)
(princ)
)
Also, if your XREF dwg is in a place that is not in the Support file Search Path or in the same folder as the working drawing, this is not likely to work. The path is not part of the name.
Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn