GetAttributes?

Discussion in 'AutoCAD' started by RMD, May 20, 2004.

  1. RMD

    RMD Guest

    I tyring to write a routine to change the text values of specific attributes
    in a specific block named "BORDER". I can'y past the "Set blockRef = Block"
    line without a type mismatch. Can someone tell me what I'm doing wrong?

    Public Sub Test2()

    Dim blockRef As AcadBlockReference
    Dim Attribs As Variant
    Dim Block As AcadBlock
    Dim i As Integer

    Set Block = ThisDrawing.Blocks.Item("BORDER")
    Set blockRef = Block

    Attribs = blockRef.GetAttributes
    End Sub

    TIA Rick
     
    RMD, May 20, 2004
    #1
  2. RMD

    Joe Sutphin Guest

    Here's something that should help.

    Joe
    --
    'DXF Group Code Constants
    Const ENTITY = 0 'an entity

    Public Sub ListBlockRefs()
    Dim objSS As AcadSelectionSet
    Dim BlockRef As AcadBlockReference
    Dim Index As Long
    Dim Attribs As Variant
    Dim AttributeRef As AcadAttributeReference
    Dim Count As Long

    On Error Resume Next
    ThisDrawing.SelectionSets("Inserts").Delete
    On Error GoTo 0

    Set objSS = ThisDrawing.SelectionSets.Add("Inserts")

    If CreateSelectionSet(objSS, ENTITY, "INSERT") Then
    For Index = 0 To objSS.Count - 1
    Set BlockRef = objSS(Index)
    If BlockRef.HasAttributes Then
    Debug.Print "BlockName: " & BlockRef.Name
    Attribs = BlockRef.GetAttributes
    For Count = 0 To UBound(Attribs)
    Set AttributeRef = Attribs(Count)
    Debug.Print "AttributeTagString: " & AttributeRef.TagString & _
    ", AttributeValue: " & AttributeRef.TextString
    Next Count
    End If
    Next Index
    End If
    End Sub

    Public Function CreateSelectionSet(SelectionSet As AcadSelectionSet, _
    FilterCode As Integer, _
    FilterValue As String) As Boolean
    Dim intFilterCode(0) As Integer
    Dim varFilterValue(0) As Variant

    'assume success
    CreateSelectionSet = True

    intFilterCode(0) = FilterCode
    varFilterValue(0) = FilterValue

    SelectionSet.Select acSelectionSetAll, , , intFilterCode, varFilterValue

    If SelectionSet.Count < 1 Then
    CreateSelectionSet = False
    End If
    End Function
     
    Joe Sutphin, May 20, 2004
    #2
  3. The problem here is that Block and blockRef are two different object
    types. An AcadBlock, the object you get when referencing
    ThisDrawing.Blocks("BORDER"), is a block definition.

    GetAttributes is a method of the AcadBlockReference class which is the
    VBA representation of a block insert, the item on the screen.

    You can't assign an AcadBlock object to a variable designed to hold a
    reference an AcadBlockReference.

    Use a selection set to grab the BORDER block from the screen or have the
    user select it directly.
     
    Frank Oquendo, May 20, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.