AbhilashDK2014 发表于 2022-7-6 21:57:44

无法复制的属性

大家好,
 
我是AutoCad和AutoCad的完全新手。净额。我遇到了一个问题。我要求用户选择一个块参考,它有三个属性,即LINEUP、BAY和HL。然后我尝试创建一个副本。但不会复制属性“LINEUP”和“BAY”(这些属性的值)。你能帮我解决这个问题吗。
 
带属性的原始块:请参见图像原始块带属性。巴布亚新几内亚
没有属性值的新块:请参见图像NewBlockWithoutAttributes。巴布亚新几内亚
 
这是VB。网络代码:
 

<CommandMethod("WithAttr2")> _
       Public Sub WithAttr2()
         Dim doc As Document = Application.DocumentManager.MdiActiveDocument
         Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
         Dim database As Database = ed.Document.Database
         Dim blockName As String
         Dim blockRef1 As BlockReference
         Dim options As PromptEntityOptions = New PromptEntityOptions("\nSelect block reference")
         options.SetRejectMessage("\nSelect only block reference")
         options.AddAllowedClass(GetType(BlockReference), False)

         Dim acSSPrompt As PromptEntityResult = ed.GetEntity(options)

         Using tx As Transaction = database.TransactionManager.StartTransaction()

               Dim blockRef As BlockReference = TryCast(tx.GetObject(acSSPrompt.ObjectId, OpenMode.ForRead), BlockReference)

               Dim block As BlockTableRecord = Nothing
               If (blockRef.IsDynamicBlock) Then

                   'get the real dynamic block name.
                   block = TryCast(tx.GetObject(blockRef.DynamicBlockTableRecord, OpenMode.ForRead), BlockTableRecord)

               Else

                   block = TryCast(tx.GetObject(blockRef.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
               End If


               If (block <> Nothing) Then
                   Dim sfilter As New SelectionFilter(New TypedValue() {New TypedValue(CInt(DxfCode.Start), "INSERT"), New TypedValue(2, block.Name)})
                   Dim res As PromptSelectionResult = ed.SelectAll(sfilter)
                   If res.Status = PromptStatus.OK Then
                     'display result
                     MsgBox("--->Selected " & res.Value.Count & " objects", res.Value.Count)
                     Dim Objectset As SelectionSet = res.Value
                     For Each id As ObjectId In Objectset.GetObjectIds()
                           blockRef1 = TryCast(tx.GetObject(id, OpenMode.ForRead), BlockReference)
                           MsgBox(blockRef1.Name)
                           blockName = blockRef1.Name
                           'Dim pt As New Point3d(0, 0, 0)
                           'ACADBlockMgr.InsertBlockWithAtt(blockRef1.Name, pt)
                     Next
                   End If
               End If
               tx.Commit()
         End Using
         Using trans As Transaction = database.TransactionManager.StartTransaction

               Dim blkTable As BlockTable = TryCast(database.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
               Dim blkRecId As ObjectId = blkTable(blockName)
               MsgBox(blkRecId.ToString())
               If blkRecId <> ObjectId.Null Then
                   Dim blkTableRecord As BlockTableRecord = trans.GetObject(blkRecId, OpenMode.ForRead)
                   Using acBlkRef As New BlockReference(New Point3d(2, 2, 0), blkTableRecord.Id)
                     Dim currentSpaceBlkTableRec As BlockTableRecord = trans.GetObject(database.CurrentSpaceId, OpenMode.ForWrite)
                     currentSpaceBlkTableRec.AppendEntity(acBlkRef)
                     trans.AddNewlyCreatedDBObject(acBlkRef, True)
                     'Check For Attributes
                     If blkTableRecord.HasAttributeDefinitions Then
                           'Add attributes from Block Table Records
                           For Each objId As ObjectId In blkTableRecord
                               Dim dbObj As DBObject = trans.GetObject(objId, OpenMode.ForRead)
                               If TypeOf dbObj Is AttributeDefinition Then
                                 Dim attrDef As AttributeDefinition = dbObj
                                 MsgBox(attrDef.Tag & " " & attrDef.TextString)
                                 If Not attrDef.Constant Then
                                       Using attRef As New AttributeReference
                                           attRef.SetAttributeFromBlock(attrDef, acBlkRef.BlockTransform)
                                           attRef.Position = attRef.Position.TransformBy(acBlkRef.BlockTransform)
                                           attRef.TextString = attrDef.TextString
                                           acBlkRef.AttributeCollection.AppendAttribute(attRef)
                                           trans.AddNewlyCreatedDBObject(attRef, True)
                                       End Using
                                 End If
                               End If
                           Next
                     End If
                   End Using
               End If
               trans.Commit()
         End Using
       End Sub

 
我做错了什么。请让我知道。
 
提前感谢,
Abhilash D K

页: [1]
查看完整版本: 无法复制的属性