Jump to content

Recommended Posts

Posted

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.

 

Posted

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.

Posted

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.

  • Like 1
Posted (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 by mhupp
  • Like 1
Posted

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!"))
						)
					)
				)
			)
		)
	)

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...