VB如何获得AutoCAD文件中指定位置的文字
知道该AutoCAD中该文本的坐标,如何获得该文本的文字哪?
找了一些资料,全是AutoCAD VBA的,不值到如何用VB编写
可不可以像打开Excel文件一样,获得指定单元的内容
例如:
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, i).Value =“123”
可以,与excel操作类似,就是用cad本身的vba来操作的,引用cad的库之后,cad支持的vba在vb中就可以直接使用了。小学教师实习报告
大概6、7年前做过类似的开发,现在已经记不太清了autocad中的文字可不能通过坐标直接获取,只能遍历所有文字,判断这些文字中坐标与给定的坐标相同的,就是你要的文字对象,得到文字对象,内容自然也得到
Private Sub Test()
Dim objEnt As AcadEntity
Dim nCount As Long
Dim i As Long
Dim x, y As Double
Dim minPoint As Variant
Dim maxPoint As Variant
Dim objText As AcadMText
x = 230#: y = 542# '假设为指定点
nCount = ThisDrawing.ModelSpace.Count
For i = 1 To nCount
Set objEnt = ThisDrawing.ModelSpace.Item(i - 1)
Call objEnt.GetBoundingBox(minPoint, maxPoint)
Debug.Print "MinPoint:" & minPoint(0) & " " & minPoint(1) & " " & minPoint(2) & vbCr & "maxPoint:" & maxPoint(0) & " " & maxPoint(1)
If x >= minPoint(0) And y >= minPoint(1) And x <= maxPoint(0) And y <= maxPoint(1) Then
If objEnt.ObjectName = "AcDbMText" Then
Set objText = objEnt
MsgBox objText.TextString
End If
End If
Next
End Sub