BlackBox 发表于 2022-7-6 20:12:15

您好,我试图编辑块引用中的属性,但我认为您的程序工作正常,但从未更改我的私有属性。你知道为什么吗?
 

SuperNim143 发表于 2022-7-6 20:19:39

SuperNim143 发表于 2022-7-6 20:24:09

I feel like I'm close, but something is still missing.
I have made a modification to factor layout into it.
I have been able to confirm that it is now iterating through the correct block and does pull in that attribute, however, it still does not recognize the tag as equal to the attTag that is passed in. I'm attaching a quick screen shot of the issue I have with my output. If you look at the attribute names you can see that it creates a new attribute with an identical name.
 

Private Sub UpdateBlockAttribute(acBlkRef As BlockReference, attTag As String, textValue As String, Optional modelSpace As Boolean = True)       Dim acBlkTable As BlockTable = Nothing       Dim acBlkDef As BlockTableRecord = Nothing       Dim acCurLyr As ObjectId       Dim acAttRef As DatabaseServices.AttributeReference = Nothing       Dim attFound As Boolean = False       Dim acSpaceID As ObjectId       Dim layoutDict As DBDictionary       Dim dictEntry As DictionaryEntry       Dim layout As Layout       Dim layoutID As ObjectId       Try         layoutDict = acTrans.GetObject(acdb.LayoutDictionaryId, OpenMode.ForRead, False)         'If modelSpace = False Then         'acSpaceID = acBlkTable(BlockTableRecord.PaperSpace)         'Else         'acSpaceID = acBlkTable(BlockTableRecord.ModelSpace)         ' End If         ' acBlkDef = DirectCast(acTrans.GetObject(acSpaceID, OpenMode.ForRead), BlockTableRecord)         If (layoutDictNothing) Then               For Each dictEntry In layoutDict                   layoutID = dictEntry.Value                   layout = acTrans.GetObject(layoutID, OpenMode.ForRead)                   acBlkTable = acTrans.GetObject(acdb.BlockTableId, OpenMode.ForRead)                   acBlkDef = DirectCast(acBlkTable(acBlkRef.Name).GetObject(OpenMode.ForRead), BlockTableRecord)                   Dim acLyrTbl As LayerTable = acTrans.GetObject(acdb.LayerTableId, OpenMode.ForRead)                   acCurLyr = acdb.Clayer                   If acLyrTbl.Has("0") Then                     acdb.Clayer = acLyrTbl("0")                   End If                   For Each acEntId In acBlkDef                     Dim acEnt As Entity = acTrans.GetObject(acEntId, OpenMode.ForRead)                     If Not IsNothing(acEnt) Then                           If acEnt.GetType.ToString = "Autodesk.AutoCAD.DatabaseServices.AttributeDefinition" Then                               Dim acAttDef As AttributeDefinition = DirectCast(acEnt, AttributeDefinition)                               If Not IsNothing(acAttDef) And Not acAttDef.Constant Then                                                                     acAttRef = New AttributeReference                                 acAttRef.SetAttributeFromBlock(acAttDef, DirectCast(acTrans.GetObject(acBlkRef.ObjectId, OpenMode.ForRead), BlockReference).BlockTransform)                                 If acAttDef.Tag.ToString = attTag Or acAttRef.Tag.ToString = attTag.ToString Then                                       attFound = True                                       Exit For                                 End If                           End If                     End If                     End If                   Next                   If attFound = True Then                     Exit For                   End If               Next         End If         DirectCast(acTrans.GetObject(acBlkRef.ObjectId, OpenMode.ForRead), BlockReference).AttributeCollection.AppendAttribute(acAttRef)         'IF THE ATTRIBUTE DOES NOT EXIST, ADD A NEW ONE...         If Not attFound Then               acAttRef.Tag = attTag               acAttRef.Justify = AttachmentPoint.MiddleCenter               acTrans.AddNewlyCreatedDBObject(acAttRef, True)               acAttRef.UpgradeOpen()         End If         acAttRef.TextString = textValue         acAttRef.DowngradeOpen()         'acBlkDef.SynchronizeAttributes()         acdb.Clayer = acCurLyr       Catch ex As Exception         MsgBox("Update Block Attribute: " & ex.Message & acAttRef.BlockName.ToString & " - " & acAttRef.Tag.ToString)       End Try   End Sub
 
paperspace blocks.docx

Roberto casado 发表于 2022-7-6 20:28:47

Hi, i try to edit the attributes in a Block reference, but i think your program work goog, but never change my private attributes. You know why?
         
页: 1 [2]
查看完整版本: .中的NET Update块属性