Получение постоянных атрибутов вставки блока при помощи VBA

Автор Тема: Получение постоянных атрибутов вставки блока при помощи VBA  (Прочитано 3945 раз)

0 Пользователей и 1 Гость просматривают эту тему.


Онлайн Алексей Кулик

  • Administrator
  • *****
  • Сообщений: 1096
  • Карма: 172
А зачем так сложно идти? Ведь можно использовать штатные средства - GetConstantAttributes:
Цитировать
Signature

RetVal = object.GetConstantAttributes()

Object

BlockRef, ExternalReference, MInsertBlock
The objects this method applies to.

RetVal

Variant (array of Attribute objects)
The array of Attribute objects that are constant for the block reference.
Ну и пример:
Код - Visual Basic [Выбрать]
  1. Sub Example_GetConstantAttributes()
  2.     ' This example creates a constant attribute definition on a block.
  3.    ' It then queries the block to return the attribute.
  4.    
  5.     ' Create the block to hold the attribute
  6.    Dim blockObj As AcadBlock
  7.     Dim insertionPnt(0 To 2) As Double
  8.     insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
  9.     Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "New_Block")
  10.    
  11.     ' Define the attribute definition
  12.    Dim attributeObj As AcadAttribute
  13.     Dim height As Double
  14.     Dim mode As Long
  15.     Dim prompt As String
  16.     Dim tag As String
  17.     Dim value As String
  18.     height = 1#
  19.     mode = acAttributeModeConstant
  20.     prompt = "Constant Prompt"
  21.     insertionPnt(0) = 5#: insertionPnt(1) = 5#: insertionPnt(2) = 0#
  22.     tag = "Constant Tag"
  23.     value = "Constant Value"
  24.    
  25.     ' Create the attribute definition object on the block
  26.    Set attributeObj = blockObj.AddAttribute(height, mode, prompt, insertionPnt, tag, value)
  27.     ZoomAll
  28.    
  29.     ' Insert the block into the drawing
  30.    Dim blockRefObj As AcadBlockReference
  31.     insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0
  32.     Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "New_Block", 1#, 1#, 1#, 0)
  33.    
  34.     ' Get the constant attribute definition from the block
  35.    Dim queryAttribute As Variant
  36.     queryAttribute = blockRefObj.GetConstantAttributes
  37.    
  38.     Dim count As Integer
  39.     count = UBound(queryAttribute) - LBound(queryAttribute)
  40.     MsgBox "The block reference has " & count & " constant attributes."
  41. End Sub
Все из штатной справки.
P.S. Сугубо ИМХО: намного проще получить коллекцию указателей на атрибуты и потом по ней проходить, чем "шерстить" весь блок целиком.
Все, что сказано - личное мнение.

Правила форума существуют не просто так!

Приводя в сообщении код, не забывайте про его форматирование!