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.
Solved! Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
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 -
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
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 -
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.