不知道你用什么版本的CAD,不推荐你在用VBA了, 方便的有LISP,高级些的有.NET,再高级的有ARX。
下面是VBA的代码,获取OLD POLYLINE 的顶点的XDATA
 - Sub GetXDataFromVertexOfPLine()
- Dim objEnt As AcadEntity
- Dim objCopy As AcadEntity
- Dim objPl As AcadPolyline
- Dim varPick As Variant
- Dim xdataOut As Variant
- Dim xtypeOut As Variant
- Dim strAppNames As String
- Dim i, j As Integer
- Dim num As Integer
- Dim strHandle As String
- Dim lonHandle As Long
- On Error Resume Next
- ThisDrawing.Utility.GetEntity objEnt, varPick, "Select an old Polyline: "
- If objEnt Is Nothing Then
- MsgBox "Nothing selected."
- Exit Sub
- Else
- If objEnt.ObjectName = "AcDb2dPolyline" Then 'an old 2d polyline
- Set objCopy = objEnt.Copy
- objEnt.Delete
- Set objEnt = Nothing
- Set objEnt = objCopy
- Set objCopy = Nothing
- objEnt.GetXData "", xtypeOut, xdataOut
- If VarType(xtypeOut) = vbEmpty Then
- MsgBox "No XDATA for polyline header."
- Else
- strAppNames = ""
- For i = LBound(xtypeOut) To UBound(xtypeOut) Step 1
- If xtypeOut(i) = 1001 Then
- strAppNames = strAppNames & xdataOut(i) & vbCrLf
- End If
- Next
- If strAppNames <> "" Then
- MsgBox "XDATA App names:" & vbCrLf & vbCrLf & strAppNames
- End If
- End If
- Else
- MsgBox "Non old polyline selected!"
- Exit Sub
- End If
- Set objPl = objEnt
- objEnt = Nothing
- num = (UBound(objPl.Coordinates) - LBound(objPl.Coordinates) + 1) / 3
- strHandle = objPl.Handle
- Set objPl = Nothing
- lonHandle = Val("&H" & strHandle) + 1
- strHandle = Hex(lonHandle)
- Set objEnt = ThisDrawing.Database.HandleToObject(strHandle)
- For j = 1 To num Step 1
- objEnt.GetXData "", xtypeOut, xdataOut
- If VarType(xtypeOut) = vbEmpty Then
- MsgBox "No XDATA for No. " & j & " vertex."
- Else
- strAppNames = ""
- For i = LBound(xtypeOut) To UBound(xtypeOut) Step 1
- If xtypeOut(i) = 1001 Then
- strAppNames = strAppNames & xdataOut(i) & vbCrLf
- End If
- Next
- If strAppNames <> "" Then
- MsgBox "XDATA App names of vertex " & j & " :" & vbCrLf &
- vbCrLf & strAppNames
- End If
- End If
- strHandle = objEnt.Handle
- lonHandle = Val("&H" & strHandle) + 1
- strHandle = Hex(lonHandle)
- Set objEnt = ThisDrawing.Database.HandleToObject(strHandle)
- Next
- End If
- End Sub
|