乐筑天下

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

[编程交流] VBA - information on selection

[复制链接]

14

主题

28

帖子

14

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 21:49:50 | 显示全部楼层 |阅读模式
Hello,
 
 
Q1: How do I get the number of entities in a selection using VBA?
Q2: What is the command/method to find the type of each entity in a selection using VBA?
 
 
Thank you
回复

使用道具 举报

12

主题

175

帖子

77

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
149
发表于 2022-7-6 22:17:54 | 显示全部楼层
A1: use .Count method of SelectionSet object
A2: you could use typeOf() like:
  1. If typeOf acEnt Is AcadLine then
...
and the likes where acEnt is some AcadEntity type variable you're looping through SelectionSet with
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-6 22:33:45 | 显示全部楼层
Heres my example-attempt:
 
  1. Sub test() 'define a named function  'Filter for circles - I don't know how to implement this type of filtering: 'Dim gpCode(0) As Integer 'Dim dataValue(0) As Variant 'gpCode(0) = 0 'dataValue(0) = "Circle"    Dim SS As AcadSelectionSet 'Declare "SS" variable as local Set SS = ThisDrawing.SelectionSets.Add("NewSS") 'create a new selection set object [include it in the "SelectionSets" collection] SS.SelectOnScreen 'select the objects to change (invoke the "SelectOnScreen" method) For Each Entity In SS 'iterate over the selection set     If Entity.ObjectName = "AcDbCircle" Then 'Filter for circles by objectname     Entity.color = 1 'change entity's colour   End If      Next 'process the next entity MsgBox SS.Count 'alert the total selected amount of objects SS.Delete 'delete the selection set object [exclude it from the "SelectionSets" collection]End Sub
 
I'm just starting to learn about VBA, so any inputs are appreciated.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 22:45:27 | 显示全部楼层
Grr this may be usefull
 
  1. Dim FilterDXFCode(0) As IntegerDim FilterDXFVal(0) As VariantFilterDXFCode(0) = 0FilterDXFVal(0) = "INSERT"'FilterDXFCode(1) = 2'FilterDXFVal(1) = "SCHEDTEXT"Set SS = ThisDrawing.SelectionSets.Add("pit1sel")SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFValfor circleFilterDXFVal(0) = "CIRCLE"lisp (0 . "Insert")
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-6 23:02:39 | 显示全部楼层
Thanks BIGAL!
 
This second shot worked:

[code]Sub test() 'define a named function  Dim FilterDXFCode(0) As Integer Dim FilterDXFVal(0) As Variant FilterDXFCode(0) = 0 FilterDXFVal(0) = "CIRCLE" Dim SS As AcadSelectionSet 'Declare "SS" variable as local Set SS = ThisDrawing.SelectionSets.Add("NewSS") 'create a new selection set object [include it in the "SelectionSets" collection] 'SS.Select acSelectionSetWindow , , , FilterDXFCode, FilterDXFVal '
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 14:04 , Processed in 0.598673 second(s), 62 queries .

© 2020-2025 乐筑天下

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