AutoCad VBA查找现有块的X和Y位置

我正在试图在特定的图层上查找AutoCad文档中已经存在的块的x和y位置。 目前代码只是返回X位置和ent.InsertionPoint(0)和ent.InsertionPoint(1)什么都没有返回。 任何帮助将是伟大的!

Dim blk As AcadBlockReference Dim atts As Variant Dim att As AcadAttributeReference Dim sset As AcadSelectionSet Dim ent As AcadEntity Dim obj As AcadObject 'Select all that are on the dup layer On Error Resume Next ACAD.ActiveDocument.SelectionSets.Item("Park-Dup").Delete Set sset = ACAD.ActiveDocument.SelectionSets.Add("Park-Dup") sset.Select acSelectionSetAll Dim tryBlockRef As AcadBlockReference For Each ent In sset If TypeOf ent Is AcadBlockReference Then Sheet1.Cells(i, 4) = ent.InsertionPoint End If Next 

我能够使用它来得到它的工作。 您需要将插入点设置为variablesvariables,以便可以访问x / y / z数组。 由于这是插入点数组中的内容,所以不能确定X位置是什么意思。

 Public Sub test() Dim sset As AcadSelectionSet Dim ent As AcadEntity Dim Book1 As Object Dim Sheet1 As Object Dim xlApp As Object Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set Book1 = xlApp.Workbooks.Add() Set Sheet1 = Book1.worksheets(1) Dim i As Integer 'Select all that are on the dup layer On Error Resume Next ThisDrawing.SelectionSets.Item("Park-Dup").Delete On Error GoTo 0 Set sset = ThisDrawing.SelectionSets.Add("Park-Dup") sset.Select acSelectionSetAll Dim inPt As Variant i = 1 For Each ent In sset If TypeOf ent Is AcadBlockReference Then If InStr(ent.EffectiveName, "$") = 0 Then inPt = ent.InsertionPoint Sheet1.Cells(i, 1) = inPt(0) Sheet1.Cells(i, 2) = inPt(1) i = i + 1 End If End If Next End Sub 

注意:我在Autocad中使用VBA,而不是在Excel中。