AutoCAD macro to Extract Coordinates of AutoCAD Blocks

Macro for Extracting Details of AutoCAD Block

Join online Course on AutoCAD VBA Programming

Following is the VBA code to extract Coordinates of Blocks in an AutoCAD Drawing.

Sub ExtractDetailsOfAutoCADBlocks()
Open “E:ExtractDetailsOfAutoCADBlockExtractedDetails.txt” For Output As 1
Dim X, y, z As Double
Dim XLnCADObject As AcadObject
Dim XLnCADBlock As AcadBlockReference
Dim XLnCADSelection As AcadSelectionSet
MsgBox “Select Objects”, , “XL n CAD”
On Error Resume Next
Set XLnCADSelection = ThisDrawing.SelectionSets.Add(“XLnCAD_SelectionSet”)
Set XLnCADSelection = ThisDrawing.SelectionSets(“XLnCAD_SelectionSet”)
For Each XLnCADObject In ThisDrawing.SelectionSets(“XLnCAD_SelectionSet”)
If XLnCADObject.ObjectName = “AcDbBlockReference” Then
Set XLnCADBlock = XLnCADObject
X = XLnCADBlock.InsertionPoint(0)
y = XLnCADBlock.InsertionPoint(1)
z = XLnCADBlock.InsertionPoint(2)
Print #1, X; y; z; XLnCADObject.Name&; ” ” & XLnCADBlock.Layer
End If
Close (1)
End Sub

Join online Course on Scripting in AutoCAD

Macros (VBA for AutoCAD)

Scripting in AutoCAD

Tips & Tricks in AutoCAD