I need to change the attribute of "tag" = "PRO" in all blocks of the model space of the active document in autocad. The text you need to add is "my project".
I searched for information about walking blocks and change the attributes but I get nothing. Can anyone help me please?
Once you've obtained the desired BlockTableRecord, simply iterate GetBlockReferenceIds(), opening each BlockReference and edit the Attribute as needed... Here are some articles that may help:
Identify the number of reference to a block
Updating a specific attribute inside an AutoCAD drawing using .NET
Public Sub ModifyPitSchedule1()' adds single ptDim SS As AcadSelectionSetDim objENT As AcadEntityDim Count, Cntr As IntegerDim Newpitname As StringDim pitname As StringDim FilterDXFCode(0) As IntegerDim FilterDXFVal(0) As VariantDim PitNameSelect As AcadObjectDim basepnt, pt1, pt2, pt3 As VariantDim attribs As Variant'On Error Resume NextNewpitname = "1" 'dummy to pass then return changedBLOCK_NAME = "SCHEDTEXT"pitname = Getpitname(Newpitname)MsgBox "pitname selected is " & pitnameFilterDXFCode(0) = 0FilterDXFVal(0) = "INSERT"'FilterDXFCode(1) = 2'FilterDXFVal(1) = "SCHEDTEXT"Set SS = ThisDrawing.SelectionSets.Add("pit1sel")SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFValFor Cntr = 0 To SS.Count - 1If SS.Item(Cntr).Name = BLOCK_NAME Then attribs = SS.Item(Cntr).GetAttributes If attribs(0).TextString = pitname Then pt1 = ThisDrawing.Utility.GetPoint(, " pick first point") txtx1 = CStr(FormatNumber(pt1(0), 3)) TXTY1 = CStr(FormatNumber(pt1(1), 3)) attribs(1).TextString = txtx1 attribs(2).TextString = TXTY1 attribs(1).Update attribs(2).Update' ThisDrawing.Application.Update' try this Cntr = SS.Count Else: End If Else: End IfNext CntrThisDrawing.SelectionSets.Item("pit1sel").DeleteEnd Sub
This one allows either a text as the name of the attribute or pick a block
Function Getpitname(Newpitname As String) As StringDim PitNameSelect As AcadObjectDim pitattribs As VariantThisDrawing.Utility.GetEntity PitNameSelect, basepnt, "pick pit name : "If PitNameSelect.ObjectName = "AcDbText" Then Getpitname = PitNameSelect.TextStringEnd IfIf PitNameSelect.ObjectName = "AcDbBlockReference" Then pitblname = PitNameSelect.Name ' RETURNS BLOCK NAME pitattribs = PitNameSelect.GetAttributes Getpitname = pitattribs(0).TextStringEnd IfEnd Function