Redefine Block Attributes with VBA

Discussion in 'AutoCAD' started by Sean, Sep 22, 2005.

  1. Sean

    Sean Guest

    Hello,

    I'm trying to change the text attribute, within a number of blocks, to
    fit. At first I built a selection set to select all the blocks and
    then change the textalignment to fit, however this won't redefine the
    blocks in the drawing.

    Here's the code I currently have to find the associated blocks and
    change the text alignment to fit. This doesn't work either as the fit
    does not work correctly. What is the best way to set the boundaries
    for a text fit?:

    Public Sub UpdateAttribute()
    Dim sset As AcadSelectionSet
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Variant

    Set sset = ThisDrawing.SelectionSets.Add("SS1")
    ' Set your criteria
    FilterType(0) = 2 'Looks for Block Name
    FilterData(0) = "MFDG0624" 'Looks for MFDG0624 block in the dwg

    sset.Select acSelectionSetAll, , , FilterType, FilterData

    Dim x As Integer
    Dim i As Integer
    Dim objBlock As AcadBlockReference
    Dim obj As AcadEntity
    Dim varAtts() As AcadAttributeReference

    x = 1
    For Each obj In sset
    Set objBlock = obj
    If obj.HasAttributes Then
    varAtts = obj.GetAttributes
    For i = LBound(varAtts) To UBound(varAtts)
    If Len(varAtts(i).TextString) = 4 Then
    varAtts(i).Alignment = acAlignmentFit
    End If
    Next i
    obj.Update
    Next obj

    ThisDrawing.SelectionSets.Item("SS1").Delete

    End Sub

    Would a better solution be to redefine all the blocks (approx. 15) in
    the model using vba? In order to do this I would need to build a
    selection set for each block, explode the block, change the text
    alignment to fit, and then reinsert the block to redefine all similar
    blocks in the drawing, correct?

    Thanks, Sean
     
    Sean, Sep 22, 2005
    #1
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.