乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 59|回复: 2

[编程交流] 将多段线内部文本导出到

[复制链接]

1

主题

1

帖子

0

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 21:46:44 | 显示全部楼层 |阅读模式
大家好!


我正在搜索一个宏,该宏可以找到图形中的所有多段线,并将其中的文本导出到excel中

我有一个建筑平面图(见附件),其中多段线包围了每个房间,多段线内有相应的房间文本编号。我正在寻找一个宏,可以导出到excel这样的表格:

[table][tr][td]多段线内文字[td][td]多段线面积(m2)[/td][tr][tr][td]1.1][td][td]51.34 m2][td][tr][tr][tr][td]1.2][td][td]28.75 m2][td][tr tr tr][td]1.3][td]14.41 m2][td][tr tr tr tr td]1.1,1.2,1.3[td][td]100.75平方米[td][tr][table]
[size][color][align]
多段线和房间文字编号位于不同的层中。

其中一条多段线(表中的最后一行)包围了整个建筑,这意味着其中有多个文本。

没有文本编号的
多段线也应出现在表中[size][align]

我是VBA新手,非常感谢您的帮助!

[左对齐][颜色=#666666][大小=14px]提前感谢!
回复

使用道具 举报

2

主题

261

帖子

20

银币

初来乍到

Rank: 1

铜币
8
发表于 2022-7-6 22:33:21 | 显示全部楼层
  1. Sub selEntByPline()
  2. On Error Resume Next
  3. Dim objCadEnt As AcadEntity
  4. Dim vrRetPnt As Variant
  5. Dim gpCode(0) As Integer
  6. Dim dataValue(0) As Variant
  7. Dim ntexts As Integer, iText As Integer
  8. Dim myText As AcadText
  9. ThisDrawing.Utility.GetEntity objCadEnt, vrRetPnt
  10. If objCadEnt.ObjectName = "AcDbPolyline" Then
  11.     Dim objLWPline As AcadLWPolyline
  12.     Dim objSSet As AcadSelectionSet
  13.     Dim dblCurCords() As Double
  14.     Dim dblNewCords() As Double
  15.     Dim iMaxCurArr, iMaxNewArr As Integer
  16.     Dim iCurArrIdx, iNewArrIdx, iCnt As Integer
  17.     Set objLWPline = objCadEnt
  18.     dblCurCords = objLWPline.Coordinates
  19.     iMaxCurArr = UBound(dblCurCords)
  20.     If iMaxCurArr = 3 Then
  21.         ThisDrawing.Utility.Prompt "The selected polyline should have minimum 2 segments..."
  22.         Exit Sub
  23.     Else
  24.         iMaxNewArr = ((iMaxCurArr + 1) * 1.5) - 1
  25.         ReDim dblNewCords(iMaxNewArr) As Double
  26.         iCurArrIdx = 0: iCnt = 1
  27.         For iNewArrIdx = 0 To iMaxNewArr
  28.             If iCnt = 3 Then
  29.                 dblNewCords(iNewArrIdx) = 0
  30.                 iCnt = 1
  31.             Else
  32.                 dblNewCords(iNewArrIdx) = dblCurCords(iCurArrIdx)
  33.                 iCurArrIdx = iCurArrIdx + 1
  34.                 iCnt = iCnt + 1
  35.             End If
  36.         Next
  37.         Set objSSet = ThisDrawing.SelectionSets.Add("SELENT")
  38.         gpCode(0) = 0:  dataValue(0) = "TEXT"
  39.         objSSet.SelectByPolygon acSelectionSetWindowPolygon, dblNewCords, gpCode, dataValue
  40.         ntexts = objSSet.Count
  41.         For iText = 0 To ntexts - 1
  42.             ' do your stuff here
  43.             ' for instance I'm listing all textstrings of the found objects
  44.             Set myText = objSSet.Item(iText)
  45.             MsgBox ("Found :" & myText.TextString & " - " & objLWPline.Area & "m2")
  46.         Next iText
  47.         objSSet.Delete
  48.     End If
  49. Else
  50.     ThisDrawing.Utility.Prompt "The selected object is not a 2D Polyline...."
  51. End If
  52. If Err.Number <> 0 Then
  53.     MsgBox Err.Description
  54.     Err.Clear
  55. End If
  56. End Sub
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 23:10:03 | 显示全部楼层
Lisp版本注释编码2013。
 
  1. (defun getcoords (ent)
  2.   (vlax-safearray->list
  3.     (vlax-variant-value
  4.       (vlax-get-property
  5.     (vlax-ename->vla-object ent)
  6.     "Coordinates"
  7.       )
  8.     )
  9.   )
  10. )
  11.  
  12. (defun co-ords2xy ()
  13. ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
  14. (setq numb (/ (length co-ords) 2))
  15. (setq I 0)
  16. (repeat numb
  17. (setq xy (list (nth I co-ords)(nth (+ I 1) co-ords) ))
  18. (setq coordsxy (cons xy coordsxy))
  19. (setq I (+ I 2))
  20. ) ; end repeat
  21. ) ; end defun
  22. ; program starts here
  23. ; choose output file change acdatemp to what you want
  24. (setq fname (strcat "c:/acadtemp/" (getstring "\nEnter file name ")))
  25. (setq fout (open fname "w"))
  26. (setq plobjs (ssget (list (cons 0 "lwpolyline"))))
  27. (setq numb1 (sslength plobjs))
  28. (setq x numb1)
  29. (repeat numb1
  30. (setq obj (ssname plobjs (setq x (- x 1))))
  31. (setq co-ords (getcoords obj))
  32. (co-ords2xy)
  33. ; write pline co-ords here
  34. (setq numb3 (length co-ords))
  35. (setq z numb3)
  36. (setq ansco-ords "")
  37. (repeat numb3 
  38. (setq ansco-ords (strcat ansco-ords (rtos (nth (setq z (- z 1)) co-ords) 2 3 ) " " ))
  39. )
  40. (setq ans (strcat "Pline " ansco-ords))
  41. (write-line ans fout)
  42. (setq ansco-ords "")
  43. (setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ; selection set of text within polygon
  44. (if (= ss nil) 
  45. (princ "\nnothing inside")
  46. (progn 
  47. (setq coordsxy nil) ; reset for next time
  48. (setq numb2 (sslength ss))
  49. (setq y numb2)
  50. (repeat numb2
  51. (setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring"))
  52. (princ anstext) ; change to write text to file
  53. (write-line (strcat "text " anstext) fout)
  54. (princ "\n")
  55. ) ; end repeat2
  56. (setq ss nil) ; reset for next poly
  57. )
  58. )
  59. ) ; end repeat1
  60. (close fout)
  61. (princ)

 
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 14:45 , Processed in 0.589579 second(s), 58 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表