XRefDatabase Example

Using Programming Languages other than VBA

Sub Example_XRefDatabase()
	' This example adds an external reference to the current drawing.
	' It then cycles through each Block object in the drawing
	' and determines the style of each Block by accessing the
	' IsLayout and IsXRef properties of the Block. If the Block is an
	' XRef Block, you obtain a reference to the external Database object
	' for that Block and display the number of Blocks the Database contains.

	Dim InsertPoint(0 To 2) As Double
	Dim insertedBlock As AcadExternalReference
	Dim tempBlock As AcadBlock
	Dim msg As String, PathName As String

	' Define external reference to be inserted
	InsertPoint(0) = 1: InsertPoint(1) = 1: InsertPoint(2) = 0
	PathName = "c:\program files\autocad\sample\city map.dwg"

	' Add the external block to model space
	Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference(PathName, "XREF_IMAGE", InsertPoint, 1, 1, 1, 0, False)

	msg = vbCrLf & vbCrLf

	For Each tempBlock In ThisDrawing.Blocks
		If tempBlock.IsXRef Then
			' Block is an external reference, so add it to list
			msg = msg & tempBlock.name & " contains " & _
			tempBlock.XRefDatabase.Blocks.count & " blocks"
			msg = msg & vbCrLf	' Insert line
		End If
	' Display Block information for the XRefDatabase
	MsgBox "Externally referenced blocks attached to this drawing have the following block counts: " & msg

End Sub