乐筑天下

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

[编程交流] LIST命令的VBA代码

[复制链接]

29

主题

519

帖子

477

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-6 23:08:43 | 显示全部楼层
或者,如果您想在VBA中使用它:
 
  1. Sub ListProps()
  2.    
  3.    Dim ssPolys     As AcadSelectionSet
  4.    Dim ssName      As String
  5.    Dim intCodes()  As Integer
  6.    Dim varValues   As Variant
  7.    Dim objEnt      As AcadEntity
  8.    Dim objLWPoly   As AcadLWPolyline
  9.    Dim objPoly     As AcadPolyline
  10.    
  11.    Dim strName     As String
  12.    Dim strLayer    As String
  13.    Dim strHandle   As String
  14.    Dim strClosed   As String
  15.    Dim dblWidth    As Double
  16.    Dim dblArea     As Double
  17.    Dim dblPerim    As Double
  18.    Dim dblCoords() As Double
  19.    
  20.    On Error Resume Next
  21.    
  22.    ssName = "ssPolys"
  23.    
  24.    ' try to set the selection set
  25.    Set ssPolys = ThisDrawing.SelectionSets(ssName)
  26.    
  27.    ' if it does not exist an error will occur - so add it
  28.    If Err Then
  29.        Set ssPolys = ThisDrawing.SelectionSets.Add(ssName)
  30.    End If
  31.    
  32.    ' clear all data from selection set
  33.    ssPolys.Clear
  34.    
  35.    ' set the filter
  36.    ReDim intCodes(5): ReDim varValues(5)
  37.    
  38.    intCodes(0) = -4: varValues(0) = "<and"
  39.    intCodes(1) = -4: varValues(1) = "<or"
  40.    intCodes(2) = 0:  varValues(2) = "PolyLine"
  41.    intCodes(3) = 0:  varValues(3) = "LwPolyLine"
  42.    intCodes(4) = -4: varValues(4) = "or>"
  43.    intCodes(5) = -4: varValues(5) = "and>"
  44.    
  45.    ssPolys.Select acSelectionSetAll, , , intCodes, varValues
  46.    
  47.    ' now make your connection to Excel
  48.    
  49.    ' now you have all the polylines in a selection set iterate it to get the properties
  50.    For Each objEnt In ssPolys
  51.        strClosed = "Open"
  52.        If objEnt.ObjectName = "AcDbPolyline" Then
  53.            strName = "Polyline2D"    'objLWPoly.ObjectName
  54.        Else
  55.            strName = "LWPolyline"     'objPoly.ObjectName
  56.        End If
  57.       
  58.        ' extract the properties
  59.        strName = objEnt.ObjectName
  60.        strLayer = objEnt.Layer
  61.        strHandle = objEnt.Handle
  62.        If objEnt.Closed = True Then strClosed = "Closed"
  63.        dblWidth = objEnt.ConstantWidth
  64.        dblArea = objEnt.Area
  65.        dblPerim = objEnt.Length
  66.        dblCoords = objEnt.Coordinates
  67.       
  68.        ' send the above properties to Excel
  69.       
  70.        ' iterate through the coords array and send the coordinates to Excel
  71.       
  72.    Next objEnt
  73.    
  74.    ' close your connection to Excel
  75.    
  76. End Sub
回复

使用道具 举报

14

主题

28

帖子

14

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 23:15:17 | 显示全部楼层
太好了,这就是我想要的。
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-6 23:17:29 | 显示全部楼层
 
你忽略了吗?
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 11:18 , Processed in 0.941300 second(s), 56 queries .

© 2020-2025 乐筑天下

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