乐筑天下

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

脚本字典帮助

[复制链接]

1

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2005-10-14 13:59:04 | 显示全部楼层 |阅读模式
我正在尝试根据块属性信息创建一个列表。我现在有一个具有4个属性的块。我希望能够创建一个列表(或列表,取决于块属性标签)。下面是我到目前为止的代码。我还附上了一张图片来帮助演示我最终想做什么。左边的8个块具有相同的名称:TEMP。属性标签是ID、NUMBER、LOCATION和COLOR。
左边的2个列表最终是我想要创建的,但在Excel中。
我现在需要帮助的是获取信息并对其进行排序。
任何帮助都将不胜感激!
  1. Option Explicit
  2. Public objKeys As Variant
  3. Public objItems As Variant
  4. Public objDict As Dictionary
  5. Public Sub DPW()
  6.     Dim ent1 As AcadEntity
  7.     Dim ent2 As AcadEntity
  8.     Dim entXref As AcadExternalReference
  9.     Dim entBlock As AcadBlock
  10.     Dim entNestedBlock As AcadBlockReference
  11.     Dim varAtts() As AcadAttributeReference
  12.     Dim objBlock As AcadBlockReference
  13.     Dim ssSet As AcadSelectionSet
  14.     Dim FilterType(1) As Integer
  15.     Dim FilterData(1) As Variant
  16.     Dim obj As AcadEntity
  17.     Dim i, x As Integer
  18.    
  19.     Set objDict = New Dictionary
  20.     Set ssSet = vbdPowerSet("TEMP")
  21.         
  22.     FilterType(0) = 0
  23.     FilterData(0) = "Insert"
  24.     FilterType(1) = 2
  25.     FilterData(1) = "*TEMP*"
  26.    
  27.     ssSet.Select acSelectionSetAll, , , FilterType, FilterData
  28.     x = 1
  29.     If ssSet.Count = 0 Then
  30.         MsgBox "No blocks were found in this drawing!", vbInformation + vbOKOnly, "Quick Report"
  31.         Exit Sub
  32.     Else
  33.         For Each obj In ssSet
  34.             Set objBlock = obj
  35.             If obj.HasAttributes Then
  36.                 varAtts = obj.GetAttributes
  37.                 For i = LBound(varAtts) To UBound(varAtts)
  38.                
  39.                     If UCase$(varAtts(i).TagString) = "ID" Then
  40.                         If objDict.Exists(varAtts(i).TextString) = False Then
  41.                             objDict.Add varAtts(i).TextString, 1
  42.                         Else
  43.                             objDict.Item(varAtts(i).TextString) = objDict.Item(varAtts(i).TextString) + 1
  44.                         End If
  45.                     End If
  46.                     
  47.                     If UCase$(varAtts(i).TagString) = "NUMBER" Then
  48.                         If objDict.Exists(varAtts(i).TextString) = False Then
  49.                             objDict.Add varAtts(i).TextString, 1
  50.                         Else
  51.                             objDict.Item(varAtts(i).TextString) = objDict.Item(varAtts(i).TextString) + 1
  52.                         End If
  53.                     End If
  54.                     
  55.                     If UCase$(varAtts(i).TagString) = "LOCATION" Then
  56.                         If objDict.Exists(varAtts(i).TextString) = False Then
  57.                             objDict.Add varAtts(i).TextString, 1
  58.                         Else
  59.                             objDict.Item(varAtts(i).TextString) = objDict.Item(varAtts(i).TextString) + 1
  60.                         End If
  61.                     End If
  62.                     
  63.                     
  64.                     If UCase$(varAtts(i).TagString) = "COLOR" Then
  65.                         If objDict.Exists(varAtts(i).TextString) = False Then
  66.                             objDict.Add varAtts(i).TextString, 1
  67.                         Else
  68.                             objDict.Item(varAtts(i).TextString) = objDict.Item(varAtts(i).TextString) + 1
  69.                         End If
  70.                     End If
  71.                     On Error GoTo 0
  72.                 Next i
  73.             End If
  74.         Next obj
  75.         i = 0
  76.         
  77.         objKeys = objDict.Keys
  78.         BubbleSort objKeys
  79.         objItems = objDict.Items
  80.         
  81.         Dim filenum As Integer
  82.         Dim strLine1 As String
  83.         
  84.         For x = 0 To UBound(objKeys)
  85.             Debug.Print objKeys(x) & vbTab & vbTab & objDict(objKeys(x))
  86.             i = i + objItems(x)
  87.         Next
  88.     End If
  89. End Sub
  90. Public Function vbdPowerSet(strName As String) As AcadSelectionSet
  91.     Dim objSelSet As AcadSelectionSet
  92.     Dim objSelCol As AcadSelectionSets
  93.    
  94.     Set objSelCol = ThisDrawing.SelectionSets
  95.     For Each objSelSet In objSelCol
  96.         If objSelSet.Name = strName Then
  97.             objSelSet.Delete
  98.             Exit For
  99.         End If
  100.     Next
  101.     Set objSelSet = ThisDrawing.SelectionSets.Add(strName)
  102.     Set vbdPowerSet = objSelSet
  103. End Function
  104. Sub BubbleSort(arr As Variant, Optional descending As Boolean, Optional numEls As Variant)
  105. ' Bubble Sort an array of any type
  106. ' Author: The VB2TheMax Team
  107. ' BubbleSort is especially convenient with small arrays (1,000
  108. ' items or fewer) or with arrays that are already almost sorted
  109. '
  110. ' NUMELS is the index of the last item to be sorted, and is
  111. ' useful if the array is only partially filled.
  112. '
  113. ' Works with any kind of array, except UDTs and fixed-length
  114. ' strings, and including objects if your are sorting on their
  115. ' default property. String are sorted in case-sensitive mode.
  116. '
  117. ' You can write faster procedures if you modify the first two lines
  118. ' to account for a specific data type, eg.
  119. ' Sub BubbleSortS(arr() As Single, Optional descending As Boolean, Optional numEls As Variant)
  120. '   Dim value As Single
  121.     Dim Value As Variant
  122.     Dim Index As Long
  123.     Dim firstItem As Long
  124.     Dim indexLimit As Long, lastSwap As Long
  125.     ' account for optional arguments
  126.     If IsMissing(numEls) Then numEls = UBound(arr)
  127.     firstItem = LBound(arr)
  128.     lastSwap = numEls
  129.     Do
  130.         indexLimit = lastSwap - 1
  131.         lastSwap = 0
  132.         For Index = firstItem To indexLimit
  133.             Value = arr(Index)
  134.             If (Value > arr(Index + 1)) Xor descending Then
  135.                 ' if the items are not in order, swap them
  136.                 arr(Index) = arr(Index + 1)
  137.                 arr(Index + 1) = Value
  138.                 lastSwap = Index
  139.             End If
  140.         Next
  141.     Loop While lastSwap
  142. End Sub

Matt W
"成为红袜队球迷就像成为最高安全监狱中的120磅重的人。"

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

0

主题

7

帖子

5

银币

初来乍到

Rank: 1

铜币
9
发表于 2005-10-17 08:40:54 | 显示全部楼层
好。。。看起来也许我没有正确发布图像或其他东西。 有时我看到,有时我不知道。
以下是图像的外观:
================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
01 03 04 01, 右, 右
, 黄色 右中 右 03, 中心
, 青色黄色 青色黄色 04, 右, 黄色
==========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
我不确定我是否可以用一本字典做到这一点,或者我是否需要两个或更多?!?! 如果有人能为我指出正确的方向,我将不胜感激。
再次感谢!
马特·
回复

使用道具 举报

0

主题

12

帖子

6

银币

初来乍到

Rank: 1

铜币
13
发表于 2005-10-17 12:43:24 | 显示全部楼层
我很想帮你,但我是洋基队的球迷。
不过,说真的,如果你能等到今晚,我会仔细看看,看看我所做的比较,如果适用的话,我会把它贴出来。在此期间,我相信我们众多常驻天才中的一位能够比我更好地帮助你。
回复

使用道具 举报

0

主题

11

帖子

3

银币

初来乍到

Rank: 1

铜币
11
发表于 2005-10-20 17:38:37 | 显示全部楼层
很像ALCS,对扬基队的球迷来说,这看起来是一个漫长的夜晚。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-5 17:50 , Processed in 0.482015 second(s), 60 queries .

© 2020-2025 乐筑天下

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