VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA Edit Attributes in Nested Blocks

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Jedimaster
1833 Views, 4 Replies

VBA Edit Attributes in Nested Blocks

I have a VBA routine that finds an replaces text. It will work on Text, Mtext and Attributes. It works as long as the Attributes are not nested. I was able to change the attributes in the block reference, but this only shows up when you reinsert the child block. I would rather not explode the parent block.

 

Any input would be appreciated.

 

4 REPLIES 4
Message 2 of 5

Hi,

 

scan through all blockdefinition in the blocktable and see if there are blockreferences in blockdefinitions, if so look to attributereferences within the blockreferences.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 5

I can find the attibutes and update the block deffinitions, but unless they are reinserted or updated somehow the changes are not made to the existing blocks. This changes the block definition only not the nested block.

 

    For i = 0 To ThisDrawing.Blocks.Count - 1
        Set CBlock = ThisDrawing.Blocks.Item(i)
        If CBlock.IsLayout = False And CBlock.IsXRef = False Then
            SubCount = CBlock.Count
            If SubCount > 0 Then
                For j = 0 To SubCount - 1
                    Set CItem = CBlock.Item(j)
                    If TypeOf CItem Is AcadAttribute Then
                        OldString = CItem.TextString
                        NewString = Replace(OldString, Find, Replace, 1, -1, 1)
                        CItem.TextString = NewString
                    End If
                Next
            End If
        End If
    Next

 

The code below is what I am using now. It does not work on nested attributes.

 

        FilterType(0) = 0
        FilterData(0) = "INSERT"
        FilterType(1) = 66
        FilterData(1) = 1
        ThisDrawing.SelectionSets("GetText").Delete
        Set sset = ThisDrawing.SelectionSets.Add("GetText")
        sset.Select acSelectionSetAll, , , FilterType, FilterData
        For Each ent In sset
            If ent.HasAttributes = True Then
                attrib = ent.GetAttributes
                For Each Att In attrib
                    AttValue = Att.TextString
                        NewText = Replace(AttValue, OldString, NewString, 1, -1, 1)
                    If AttValue <> NewText Then
                        Att.TextString = NewText
                        objTextFile.WriteLine AttValue & vbCrLf & NewText
                    End If
                Next
            End If
        Next

Message 4 of 5

Hi,

 

as I understood the jon the first loop is correct, but instead of checking if it's an attribute you should check if the entity in the blockdefinition is a blockreference (so then you know it's a nedesd block) and for that blockreference go through the attribute-references.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 5

Thank you! Once I started looking for sub block references I was able to do a get attributes and then change then.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost