Ahankhah Posted 7 hours ago Posted 7 hours ago Hi, I need to check in AutoLISP whether an attached Xref in the current drawing creates a circular reference (refers to itself or a parent Xref). Is there a way, using AutoLISP or ActiveX, to detect this before attaching or reloading the Xref? Ideally, a function that takes the Xref name and returns True/False for circular reference. Any sample code or approach would be greatly appreciated. Quote
mhupp Posted 5 hours ago Posted 5 hours ago Use CLASSICXREF will display a window for you to look thought. for the ones that you suspect to be circular switch to overlay. 1 Quote
Steven P Posted 5 hours ago Posted 5 hours ago AutoCAD is very bad at running a LISP in one file to read another file, it is not something I have looked at with xrefs, however this might give you a starter, listing any xrefs in the current file - I was looking at this to do something different and is in the folder "finish this one day"... so the code might not be 100%. ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/grab-all-xref-names-and-paths/td-p/1661552 ;;(defun filepfil ( / Doc LayoutCol EndList) ;; Returns a list of list of all the Xrefs and Images with their paths within a drawing. (defun c:xreffilepaths ( / ) (defun xreftype ( str / ) ;; (setq lst (list "abcd.dwg" "1234.dwg" "sample drawing with space in file name.dwg" "5566.dwg") ) ;; (mapcar '(lambda (x) ;; (substr x 1 (- (strlen x) 4)) ;; ) ;; lst ;; ) (setq MyLen (strlen str)) (setq MyType (substr str (- MyLen 3) )) ) (setq Doc (vla-get-ActiveDocument (vlax-get-Acad-Object))) (setq LayoutCol (vla-get-Layouts Doc)) (vlax-for i LayoutCol (vlax-for Obj (vla-get-Block i) (cond ((= (vla-get-ObjectName Obj) "AcDbRasterImage") (if (not (assoc (vla-get-Name Obj) EndList)) (setq EndList (cons (cons (vla-get-Name Obj) (vla-get-ImageFile Obj)) EndList)) ) ) ((and (= (vla-get-ObjectName Obj) "AcDbBlockReference") (vlax-property-available-p Obj 'Path)) (if (not (assoc (vla-get-Name Obj) EndList)) (setq EndList (cons (cons (vla-get-Name Obj) (vla-get-Path Obj)) EndList)) ) ) ) ) ) EndList (princ "\nContains Xrefs: ") (princ EndList) (foreach n EndList (if (findfile (cdr n)) () (progn (princ "\nMissing XREF: ") (princ (car n)) ;; (princ n) ) ; end progn ) ; end if ) ; end foreach (setq MyPath (cdr (nth 0 EndList)) ) (setq MyFileType (xreftype (cdr (nth 0 EndList)) )) (setq MyFile (strcat (car (nth 0 EndList)) MyFileType) ) (setq NewPath (strcat (getvar "dwgprefix") (vl-string-trim ".\\\\" MyPath ) )) (if (findfile NewPath) ; find file : if file exists (progn (setq MyPath (vl-string-right-trim MyFile MyPath )) ; take off file from file path (setq NewPath (vl-string-right-trim MyFile NewPath )) ; take off file from file path ) ; end progn (progn ) ; end progn ) ; end if ) Not sure if this is something you can use? https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/Determining-whether-a-drawing-is-referenced-as-an-xref-in-other-drawings.html 1 Quote
Ahankhah Posted 58 minutes ago Author Posted 58 minutes ago 4 hours ago, mhupp said: Use CLASSICXREF will display a window for you to look thought. for the ones that you suspect to be circular switch to overlay. mhupp, I want AutoLISP code to do that. Quote
Ahankhah Posted 54 minutes ago Author Posted 54 minutes ago 4 hours ago, Steven P said: AutoCAD is very bad at running a LISP in one file to read another file, it is not something I have looked at with xrefs, however this might give you a starter, listing any xrefs in the current file - I was looking at this to do something different and is in the folder "finish this one day"... so the code might not be 100%. ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/grab-all-xref-names-and-paths/td-p/1661552 ;;(defun filepfil ( / Doc LayoutCol EndList) ;; Returns a list of list of all the Xrefs and Images with their paths within a drawing. (defun c:xreffilepaths ( / ) (defun xreftype ( str / ) ;; (setq lst (list "abcd.dwg" "1234.dwg" "sample drawing with space in file name.dwg" "5566.dwg") ) ;; (mapcar '(lambda (x) ;; (substr x 1 (- (strlen x) 4)) ;; ) ;; lst ;; ) (setq MyLen (strlen str)) (setq MyType (substr str (- MyLen 3) )) ) (setq Doc (vla-get-ActiveDocument (vlax-get-Acad-Object))) (setq LayoutCol (vla-get-Layouts Doc)) (vlax-for i LayoutCol (vlax-for Obj (vla-get-Block i) (cond ((= (vla-get-ObjectName Obj) "AcDbRasterImage") (if (not (assoc (vla-get-Name Obj) EndList)) (setq EndList (cons (cons (vla-get-Name Obj) (vla-get-ImageFile Obj)) EndList)) ) ) ((and (= (vla-get-ObjectName Obj) "AcDbBlockReference") (vlax-property-available-p Obj 'Path)) (if (not (assoc (vla-get-Name Obj) EndList)) (setq EndList (cons (cons (vla-get-Name Obj) (vla-get-Path Obj)) EndList)) ) ) ) ) ) EndList (princ "\nContains Xrefs: ") (princ EndList) (foreach n EndList (if (findfile (cdr n)) () (progn (princ "\nMissing XREF: ") (princ (car n)) ;; (princ n) ) ; end progn ) ; end if ) ; end foreach (setq MyPath (cdr (nth 0 EndList)) ) (setq MyFileType (xreftype (cdr (nth 0 EndList)) )) (setq MyFile (strcat (car (nth 0 EndList)) MyFileType) ) (setq NewPath (strcat (getvar "dwgprefix") (vl-string-trim ".\\\\" MyPath ) )) (if (findfile NewPath) ; find file : if file exists (progn (setq MyPath (vl-string-right-trim MyFile MyPath )) ; take off file from file path (setq NewPath (vl-string-right-trim MyFile NewPath )) ; take off file from file path ) ; end progn (progn ) ; end progn ) ; end if ) Not sure if this is something you can use? https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/Determining-whether-a-drawing-is-referenced-as-an-xref-in-other-drawings.html Steven, thank you very much. I will review it and get back to you. I truly appreciate your help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.