Resize Attribute

Discussion in 'AutoCAD' started by Robert Plummer, Apr 28, 2004.

  1. I have a library of blocks with 1/8" Attributes. I want to process the
    library grabbing the attribute with tag value "ID" and resize that attribute
    text to 3/32" and adjust its textallignment. How do I pick a specific
    attirbute in a block and modify it?
     
    Robert Plummer, Apr 28, 2004
    #1
  2. Robert Plummer

    Perion Guest

    Walk through the collection of objects (entities).
    Use the GetAttributes method (object.GetAttributes) which returns an array of
    the attribute references attached to a block, along with their current values.
    As it says in Help - "simply iterate the array of attribute references, using
    the TagString and TextString properties of the attribute reference to examine
    the attribute information.

    The TagString property represents the individual tag for the attribute
    reference. The TextString property contains the value for the attribute
    reference."

    It could be done sorta like this {but don't hold me to it eactly :-]


    Dim objAutoCad As Object
    Dim objModelSpace As Object
    Dim objEntity As Object
    Dim attData As Variant
    Dim iCount As Long


    Set objAutoCad = ThisDrawing.Application
    Set objModelSpace = objAutoCad.ActiveDocument.ModelSpace()

    ' Iterate through all the drawing entities looking for block
    ' references with attributes.
    ' [Note that the ModelSpace object is a collection
    ' of entity objects]

    For Each objEntity In objModelSpace
    With objEntity
    'Is it a block reference?
    If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
    'Does it have attached attributes?
    If .HasAttributes Then
    'store the block's attributes in attData array
    'attData(0) -> 1st attribute
    'attData(1) -> 2nd attribute
    'etc...........

    attData = .GetAttributes ' <<<<---------

    'Process the array
    For iCount = LBound(attData) To UBound(attData)
    'Make sure it's an attribute
    If StrComp(attData(iCount).EntityName, _
    "AcDbAttribute", 1) = 0 Then
    '[Add code to do whatever you want with
    each attribute using the attData(iCount).TagString
    property]
    End If
    Next iCount
    End If
    End If
    End With
    Next objEntity

    Maybe helps - maybe not.
    Perion
     
    Perion, Apr 29, 2004
    #2
  3. Robert Plummer

    Michel Guest

    You could loop through your directory with blocks, open each drawing and search for attribute definitions.

    Code:
    Dim SS As AcadSelectionSet
    Dim gpCode(0) As Integer
    Dim Filter(0) As Variant
    Dim i As Integer
    
    On Error Resume Next
    Set SS = ThisDrawing.SelectionSets.Add("ATT")
    If Err.Number <> 0 Then
    ThisDrawing.SelectionSets("ATT").Delete
    Set SS = ThisDrawing.SelectionSets.Add("ATT")
    End If
    
    gpCode(0) = 2
    Filter(0) = "ID"
    
    SS.Select acSelectionSetAll, , , gpCode, Filter
    
    For i = 0 To SS.Count - 1
    If SS(i).ObjectName = "AcDbAttributeDefinition" Then
    'do your thing
    
    End If
    Next i
    
    SS.Delete
     
    Michel, Apr 29, 2004
    #3
  4. Robert Plummer

    Perion Guest

    BTW - once you have a reference to a particular block's attributes using the
    GetAttributes method you can change the text height by simply changing its the
    reference object's Height property. In the code I listed, attData is an array of
    attribute references for each block. Once you've determined which element of the
    array is the particular attribute whose text height you want to modify, just
    assign a new value to the attData(n).Height (where n is the index of that
    attribute). The Height property is a Double so you'd change it to 3/32 by:

    attData(n).Height = 0.09375 'The decimal eqiv. of 3/32

    You may have to play with the value - not sure this really gives the desired
    result exactly

    Perion
     
    Perion, Apr 29, 2004
    #4
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.