wzj23020723 发表于 2007-4-10 14:07:00

用VBA怎么得到文字的一些属性

本帖最后由 作者 于 2007-4-10 14:08:05 编辑 <br /><br /> <p></p><p></p><p>在CAD图中有一些文字记录的是当前点的高程数字,我现在想提取所有的这些文字对象的信息保存到EXCEL中,请问怎样才能得到这些文字对象,然后怎样根据文字对象得到文字对象的属性(坐标X,Y,和文字内容),谢谢大家了!</p>

yulijin608 发表于 2007-4-10 15:21:00

Sub test()<br/>&nbsp;&nbsp;&nbsp; Dim selSet As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; Dim txtObj As AcadText<br/>&nbsp;&nbsp;&nbsp; Dim entObj As AcadEntity<br/>&nbsp;&nbsp;&nbsp; Dim i As Integer<br/>&nbsp;&nbsp;&nbsp; Dim fType(0 To 0) As Integer<br/>&nbsp;&nbsp;&nbsp; Dim fData(0 To 0) As Variant<br/>&nbsp;&nbsp;&nbsp; Dim j As Integer<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; For i = ThisDrawing.SelectionSets.Count - 1 To 0 Step -1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ThisDrawing.SelectionSets.Item(i).Name = "SS1" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.Item(i).Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit For<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Next i<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim xlApp As New Excel.Application<br/>&nbsp;&nbsp;&nbsp; Dim xlBook As New Excel.Workbook<br/>&nbsp;&nbsp;&nbsp; Dim xlSheet As New Excel.Worksheet<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; fType(0) = 0: fData(0) = "TEXT"<br/>&nbsp;&nbsp;&nbsp; Set selSet = ThisDrawing.SelectionSets.Add("SS1")<br/>&nbsp;&nbsp;&nbsp; selSet.Select acSelectionSetAll, , , fType, fData<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set xlBook = xlApp.Workbooks.Add()<br/>&nbsp;&nbsp;&nbsp; Set xlSheet = xlBook.ActiveSheet<br/>&nbsp;&nbsp;&nbsp; xlSheet.Cells(1, 1) = "X"<br/>&nbsp;&nbsp;&nbsp; xlSheet.Cells(1, 2) = "Y"<br/>&nbsp;&nbsp;&nbsp; xlSheet.Cells(1, 3) = "Z"<br/>&nbsp;&nbsp;&nbsp; j = 2<br/>&nbsp;&nbsp;&nbsp; For Each entObj In selSet<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set txtObj = entObj<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlSheet.Cells(j, 3) = txtObj.TextString&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '高程<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlSheet.Cells(j, 1) = txtObj.InsertionPoint(1)&nbsp; 'X坐标<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xlSheet.Cells(j, 2) = txtObj.InsertionPoint(0)&nbsp; 'Y坐标<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = j + 1<br/>&nbsp;&nbsp;&nbsp; Next entObj<br/>&nbsp;&nbsp;&nbsp; xlBook.SaveAs "C:\xyz.xls"<br/>&nbsp;&nbsp;&nbsp; xlBook.Close<br/>&nbsp;&nbsp;&nbsp; Set xlBook = Nothing<br/>&nbsp;&nbsp;&nbsp; xlApp.Quit<br/>&nbsp;&nbsp;&nbsp; Set xlApp = Nothing<br/>End Sub

wzj23020723 发表于 2007-4-10 19:13:00

<p>真的非常感谢你,非常好使!呵呵,送个鲜花。</p><p>其实小弟是这样个意思,我的这个图中有好多点,这个点的高程信息是写在他旁边的文字中的,有没有办法,把点旁边的文字内容读出来写到那个点的Z属性中啊?</p><p>我看了下,一般的点和标注文字的位置关系是定的。是不是在这个点周围一定范围中搜索文字,然后读取值写到这个点的Z属性中呢!</p><p></p>

jsxygshh 发表于 2012-7-25 08:09:49

做个标记,以待学习

njyulei 发表于 2012-7-27 08:48:42

学习了

rensd 发表于 2012-8-31 13:20:08

不就是cass7.0中的格式?

徐书远 发表于 2012-9-6 13:56:08

学习学习

sscylh 发表于 2012-9-10 20:47:22

学习了!!!               

xhk32067 发表于 2015-10-10 18:13:05

学习了,谢谢yulijin608
页: [1]
查看完整版本: 用VBA怎么得到文字的一些属性