Bryco 发表于 2008-2-12 12:02:09

BLockDef表和层

您好
我想知道是否有人能在不分解块的情况下告诉我一个块由哪些层组成
我有一个带有多个块的图形,我需要知道创建块时使用了哪些层,“而不是”该块所在的层。
我相信这些信息必须来自块定义表;不确定

Bryco 发表于 2008-2-12 12:45:00


嘿,布莱
,这真是太好了!谢谢你
它工作得很好。
虽然我了解什么是集合,因为我们每天对对象集合进行编程;
我从未创建过集合;因此我不太确定它在代码中的意图。
虽然它工作正常;但我的好奇心需要知道。
那么Bry,收藏的原因是什么呢?
谢谢
马克

Bryco 发表于 2008-2-12 12:54:06

有关阵列的更多信息,请参阅2D阵列帮助文章
但是集合是一种缓慢、高开销且非常容易存储对象的方法
这里需要集合来存储层名称,当每个层出现时,您可以检查它是否已经存在,如果已经存在
集合不需要变暗为特定的大小,您只需边添加边删除即可
您还可以将数组添加到集合中
然而,你看不到优秀的程序员像使用数组一样使用它们,因为它们速度较慢。

Bryco 发表于 2008-2-12 14:36:20

如果我们运气好,Mp会看到这一点,也许会对一个集合做一个简短的解释。

Bryco 发表于 2008-2-12 14:54:01

我不是VBA'er,所以把这篇文章当作那个....
但是,如果您说数组更快,为什么不使用最大限制绘图中层数的数组呢? 然后,您可以有一个计数变量,以便您知道将其放在数组中的位置,并且还知道何时停止将数组值打印到命令行?
还是我离基地太远了?

T.Willey 发表于 2008-2-12 14:56:06

是的,这是一个观众。我希望Ml能把它从这里拿走,然后这样做
他可能也想按字母顺序排列图层。

Bryco 发表于 2008-2-12 15:45:34

好的,谢谢。我只是沿着编程的思路思考,并认为这可能适用于C#(.Net),这就是我提出这个问题的原因。   

T.Willey 发表于 2008-2-12 16:04:29

对Bryco的数组代码做了一点修改代码1]

Joro-- 发表于 2008-2-12 18:51:54

Joro,这是一个很好的尝试,但您可能想看看您重新定位的方式
如果您对下面的代码感兴趣,请制作一个基准块,要插入绘图,然后运行tch,您可以检查每个方法的时间
我为您的方法获得0.2792969
0.1601563使用Blocklayerswith Col ent
Sub tch()
    Dim P
    Dim ent As AcadEntity
    ThisDrawing.Utility.GetEntity ent, P, "Pick a blockref"
      If Not TypeOf ent Is AcadBlockReference Then Exit Sub
      If ent Is Nothing Then Exit Sub
   
    Dim t As Single
    t = Timer
    Blocklayers ent
    'BlocklayerswithCol ent
    Debug.Print Timer - t
   
End Sub
Sub Blocklayers(ent As AcadEntity)
    Dim b As AcadBlock
    Dim UsedLayers() As String
    Dim N As Double
    Dim P
    Dim i As Double
    Dim Found As Boolean
    Dim msg As String
   
    Set b = ThisDrawing.Blocks(ent.Name)
   
    N = -1
    For Each ent In b
      If N = -1 Then
            N = N + 1
            ReDim UsedLayers(N)
            UsedLayers(N) = ent.Layer
            msg = msg & vbCr & ent.Layer
      Else
            Found = False
            For i = 0 To UBound(UsedLayers)
                If UsedLayers(i) = ent.Layer Then
                  Found = True
                  Exit For
                End If
            Next
            If Found = False Then
                N = N + 1
                ReDim Preserve UsedLayers(N)
                UsedLayers(N) = ent.Layer
                msg = msg & vbCr & ent.Layer
            End If
      End If
    Next
    'MsgBox "Layers used in the block:" & vbCr & msg
   
End Sub
Sub BlocklayerswithCol(ent As AcadEntity)
    Dim b As AcadBlock
    Dim LayerCol As New Collection
    Dim slayer As String
    Dim i As Integer
    Dim msg As String
   
    Set b = ThisDrawing.Blocks(ent.Name)
    For Each ent In b
      slayer = ent.Layer
      For i = 1 To LayerCol.count
            If LayerCol(i) = slayer Then GoTo skip
      Next
      LayerCol.Add slayer
skip:
    Next
    For i = 1 To LayerCol.count
      msg = msg & vbCr & LayerCol(i)
    Next
    'MsgBox "Layers used in the block:" & vbCr & msg
End Sub
Sub addblockandlayers()
    Dim b As AcadBlock
    Dim l As AcadLayer
    Dim ls As AcadLayers
    Dim bs As AcadBlocks
    Set ls = ThisDrawing.LAYERS
    Set bs = ThisDrawing.Blocks
    Set b = bs.Add(Zero, "b")
    Dim c As AcadCircle
    Dim i As Integer
    Dim cen(2) As Double
    For i = 1 To 250
      Set l = ThisDrawing.LAYERS.Add(i)
      l.Color = i
      cen(0) = i
      Set c = b.AddCircle(cen, 5)
      c.Layer = i
      Set c = b.AddCircle(cen, 3)
      c.Layer = i
    Next
End Sub
页: [1]
查看完整版本: BLockDef表和层