乐筑天下

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

[编程交流] 插入层';Dr中的列表

[复制链接]

30

主题

96

帖子

66

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
150
发表于 2022-7-6 22:42:20 | 显示全部楼层 |阅读模式
大家好,
不久前,我编写了一些VBA代码,将图层列表插入绘图区域。它在每个层中绘制一条线,旁边放置一个文本,数据字段链接到该线的层。可以给我一个Lisp版本的吗?我试着用我有限的Lisp知识和投降。。。
这是VBA代码。。。
 
  1. Public Sub LAYERLIST()
  2. On Error Resume Next
  3. Dim TextStr As String
  4. Dim Lay As AcadLayer
  5. Dim MTxt As AcadMText
  6. Dim SP(0 To 2), EP(0 To 2), Width As Double
  7. Dim n As Double
  8. Dim LayName As String
  9. Dim lineObj As AcadLine
  10. Dim startPoint(0 To 2) As Double
  11. Dim endPoint(0 To 2) As Double
  12. Dim TxtInsertPoint(0 To 2) As Double
  13. Dim IPoint(0 To 2) As Double
  14. Dim VarPoint As Variant
  15. Dim LayID As String
  16. Dim m As Integer
  17. Dim Counter As Integer
  18. Dim TotalLayCount As Integer
  19. Dim RowCount As Integer
  20. Dim ColumnIndex As Integer
  21. Dim TextId As String
  22. ThisDrawing.ActiveLayer = ThisDrawing.Layers.Item("0")
  23. TotalLayCount = ThisDrawing.Layers.Count
  24. Width = 0
  25. VarPoint = ThisDrawing.Utility.GetPoint(IPoint, "Select a Point:")
  26. If Err Then End
  27. m = 0
  28. Counter = 0
  29. RowCount = InputBox("There are " & TotalLayCount & " layers in this drawing." & vbCrLf & "Enter Number of Rows in the layer list:", "Enter Number of Rows")
  30. For Each Lay In ThisDrawing.Layers
  31. Counter = Counter + 1
  32. If Counter > RowCount Then
  33.    ColumnIndex = ColumnIndex + 1
  34.    Counter = 0
  35.    n = 0
  36. End If
  37. n = n + 8
  38.    startPoint(0) = VarPoint(0) + (ColumnIndex * 70)
  39.    startPoint(1) = VarPoint(1) - n
  40.    startPoint(2) = VarPoint(2)
  41.    
  42.    endPoint(0) = VarPoint(0) + 25 + (ColumnIndex * 70)
  43.    endPoint(1) = VarPoint(1) - n
  44.    endPoint(2) = VarPoint(2)
  45.    
  46.    ThisDrawing.ActiveLayer = Lay
  47.    LayID = Lay.ObjectID
  48.    Set lineObj = ThisDrawing.ActiveLayout.Block.AddLine(startPoint, endPoint)
  49.    TextId = lineObj.ObjectID
  50.    TextStr = "%<\AcObjProp Object(" & TextId & ").Layer>%"
  51.    TxtInsertPoint(0) = VarPoint(0) + (ColumnIndex * 70) + 30
  52.    TxtInsertPoint(1) = 2 + (VarPoint(1) - n)
  53.    TxtInsertPoint(2) = VarPoint(2)
  54.    Set MTxt = ThisDrawing.ModelSpace.AddMText(TxtInsertPoint, Width, TextStr)
  55.    MTxt.Height = 2
  56.    MTxt.AttachmentPoint = acAttachmentPointMiddleLeft
  57.    ZoomExtents
  58. Next
  59. Update
  60. ZoomExtents
  61. MsgBox "Done..."
  62. End Sub
  63. Public Sub TXTLIST()
  64. Dim MTxt  As AcadMText
  65. Dim TxtStyle As AcadTextStyle
  66. Dim startPoint(0 To 2) As Double
  67. Dim VarPoint As Variant
  68. Dim n As Integer
  69. Dim Str As String
  70. Dim Width As Double
  71. VarPoint = ThisDrawing.Utility.GetPoint(, "Select a Point:")
  72. n = 0
  73. For Each TxtStyle In ThisDrawing.TextStyles
  74.    If Not TxtStyle.Name = "" Then
  75.        ThisDrawing.ActiveTextStyle = TxtStyle
  76.       
  77.        n = n + 1
  78.        startPoint(0) = VarPoint(0)
  79.        startPoint(1) = VarPoint(1) + (n + 1)
  80.        startPoint(2) = VarPoint(2)
  81.       
  82.        Str = TxtStyle.Name
  83.        Width = 0
  84.        Set MTxt = ThisDrawing.ModelSpace.AddMText(startPoint, Width, Str)
  85.        MTxt.AttachmentPoint = acAttachmentPointMiddleLeft
  86.        MTxt.Height = 1
  87.       
  88.    End If
  89. Next
  90. Update
  91. MsgBox "Done..."
  92. End Sub
  93. Public Sub DIMLIST()
  94. Dim DimObj  As AcadDimAligned
  95. Dim DimStyle As AcadDimStyle
  96. Dim startPoint(0 To 2) As Double
  97. Dim endPoint(0 To 2) As Double
  98. Dim TxtPosition(0 To 2) As Double
  99. Dim VarPoint As Variant
  100. Dim n As Integer
  101. VarPoint = ThisDrawing.Utility.GetPoint(, "Select a Point:")
  102. n = 0
  103. For Each DimStyle In ThisDrawing.DimStyles
  104.    If Not DimStyle.Name = "" Then
  105.        ThisDrawing.ActiveDimStyle = DimStyle
  106.       
  107.        n = n + 4
  108.        startPoint(0) = VarPoint(0)
  109.        startPoint(1) = VarPoint(1) + (n + 1)
  110.        startPoint(2) = VarPoint(2)
  111.       
  112.        endPoint(0) = VarPoint(0) + 1
  113.        endPoint(1) = VarPoint(1) + (n + 1)
  114.        endPoint(2) = VarPoint(2)
  115.                        
  116.        TxtPosition(0) = VarPoint(0) + (n + 0.5)
  117.        TxtPosition(1) = VarPoint(1) + (n + 2)
  118.        TxtPosition(2) = VarPoint(2)
  119.                
  120.       
  121.        Set DimObj = ThisDrawing.ModelSpace.AddDimAligned(startPoint, endPoint, TxtPosition)
  122.       
  123.    End If
  124. Next
  125. Update
  126. MsgBox "Done..."
  127. End Sub
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 11:38 , Processed in 0.777084 second(s), 54 queries .

© 2020-2025 乐筑天下

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