I would like to change attribute values but seems that I cannot access them and don't know why.
I was trying to select all attribute definitions in current drawing - successfuly - and then tried to change their values based on it's attribute tags.
It turned out that I cannot access them from the selection set. How can I do it then? Attribute definitions are not nested in blocks, just definitions in the drawings.
Sub ChangeAttDefs() Using acDoc.LockDocument() Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() ' Create a TypedValue array to define the filter criteria Dim acTypValAr(0) As TypedValue acTypValAr.SetValue(New TypedValue(DxfCode.Start, "ATTDEF"), 0) '' Assign the filter criteria to a SelectionFilter object Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr) '' Request for objects to be selected in the drawing area Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.SelectAll(acSelFtr) If acSSPrompt.Status = PromptStatus.OK Then Dim acSSet As SelectionSet = acSSPrompt.Value '' Step through the objects in the selection set For Each acSSObj As SelectedObject In acSSet '' Open the selected object for write Dim acAttRef As AttributeReference = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) '' Change attribute values If acAttRef.Tag = "TEST" Then acAttRef.TextString = "WORKED" Exit Sub End If Next acTrans.Commit() End If End Using End Using End Sub
Solved! Go to Solution.
your code is not working because you did not open the blocktablerecord. To change the attribute definition , you should open the blocktablerecord first then you can edit it. You have only open the block and try to find the attribute definition. This is why it is not getting attef and not doing anything. So, first open the block table record from your selection set. Then try to change attdef. you can have a look on below link which may be useful for you.
"So, first open the block table record from your selection set. Then try to change attdef." that is it. Now it works fine. Many thanks,
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register