Aftertouch Posted April 5 Posted April 5 Hi all, i am looking for a way to check if there is a XREF present in the DWG that has the 'Attachment' status. i found a lot of solutions to check for loaded/unloaded, but not very much to check for overlay/attachement. My check needs to be quite simple... If there is a attached XREF present. then give an alert. Quote
Steven P Posted April 5 Posted April 5 Just doing a quick bit of thinking, You can use ssget with a filter '((2 . "xyz")) where XYZ is the xref name, if the xref is being used it should be selected. As you say there are plenty online to show which xrefs are loaded, you could get a list of loaded xrefs and loop through them with ssget to find which ones are being used. Quote
CyberAngel Posted April 5 Posted April 5 Just when you think you can't find anything weirder in AutoCAD... Xrefs are defined as blocks in AutoCAD. There may be an easier way to do it, but this one is guaranteed. Get the entity that defines the xref from the the block table. DXF code 70 defines the type of block it is (even though it's not a block). If the value of code 70 includes the value 8 (it's bitwise, that is, you add values together), it's an overlay, while a 4 is an attachment. Apparently, you can have 4 and 8 at the same time, which means xref with overlay. In other words, the 4 (bit 3) means it's an xref, the 8 (bit 4) means it's also an overlay. So you would check for bit 3 on and bit 4 off. There is a VBA command, vla-get-IsXref, but that only tells you whether the block is an xref, not whether it's an overlay or an attachment. 1 Quote
mhupp Posted April 5 Posted April 5 (edited) This is a simple counter of the block definitions not the blocks in the drawing. "There are 0 XREF's in this drawing" or "There are 16 XREF's in this drawing" ;;--------------------------------------------------------------------------------;; ;; displays a message of how many xref files are in the drawing ;; https://www.cadtutor.net/forum/topic/83071-check-if-there-are-attachment-xrefs-in-dwg/ (defun c:XREF-CHECK (/ i) (vl-load-com) (setq i 0) (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (if (= (vla-get-isxref blk) :vlax-true) (setq i (1+ i) ) ) (alert strcat("\nThere are " (rtos i 2 0) " XREF in this drawing")) (princ) ) You could modify this to build a list to of names and check to see if those blocks are in the drawing. (overlay ?) Edited April 5 by mhupp 1 Quote
Aftertouch Posted April 5 Author Posted April 5 Hi all, thanks for all hints! This seems to work: (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (if (= (vla-get-isxref blk) :vlax-true) (progn (setq xreflist (cons (vla-get-name blk) xreflist)) ) ) ) (if xreflist (progn (foreach x xreflist (setq xrefdata (tblsearch "BLOCK" x)) (if xrefdata (progn (setq xrefstate (cdr (assoc 70 xrefdata))) (if (= xrefstate 36) (alert (strcat "block " x " is an attachment!")) ) ) ) ) ) ) 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.