以下代码应循环遍历图形中的每一行并获取起始点x,y和z值,但我得到
错误451
我从其他有效的东西复制了这段代码,所以我在这里不知所措。
Sub Get_Points()
Dim ent As AcadEntity
Dim name As String
Dim x As Double
Dim y As Double
Dim z As Double
For Each ent In ThisDrawing.ModelSpace
If TypeOf ent Is AcadLine Then
name = ent.Handle
x = ent.StartPoint(0)
y = ent.StartPoint(1)
z = ent.StartPoint(1)
End If
Next
End Sub
答案 0 :(得分:1)
您需要首先将通用实体类型转换为特定的实体类型,如下所示:
Sub Get_Points()
Dim ent As AcadEntity
Dim acLine As AcadLine
Dim name As String
Dim x As Double
Dim y As Double
Dim z As Double
For Each ent In ThisDrawing.ModelSpace
If TypeOf ent Is AcadLine Then
Set acLine = ent
name = acLine.Handle
x = acLine.StartPoint(0)
y = acLine.StartPoint(1)
z = acLine.StartPoint(2)
End If
MsgBox name & vbCr & x & vbCr & y & vbCr & z
Next
End Sub
(另外,您的z
正在使用索引1,就像y
一样,所以我也解决了这个问题)