Community
Hi,
I am coding an application which switch a block on the model space with an other one copying the old block attributes and pasting to the new one. (this part is working well). I would like to access and copy the dynamic properties of blocks. I can read the old value, but cannot change the value on the newly inserted block:
Private Sub insertblock(BlkFullPath As String, acInsBLock As Point3d, acRotBLock As Double, dl As DocumentLock, acDoc As Document, acTransInsbk As Transaction, acCurDb As Database, acAttColl As AttributeCollection,pc As DynamicBlockReferencePropertyCollection)
Dim bkObjId As ObjectId
Dim bt As BlockTable = acCurDb.BlockTableId.GetObject(OpenMode.ForRead)
Dim btrMs As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Using dbInsert As New Database(False, True)
dbInsert.ReadDwgFile(BlkFullPath, IO.FileShare.Read, True, "")
bkObjId = acCurDb.Insert(System.IO.Path.GetFileNameWithoutExtension(BlkFullPath), dbInsert, True)
End Using
Dim BlkRef As New BlockReference(acInsBLock, bkObjId)
btrMs.AppendEntity(BlkRef)
acTransInsbk.AddNewlyCreatedDBObject(BlkRef, True)
BlkRef.Rotation = acRotBLock
Dim BlkRefObjId = BlkRef.ObjectId()
' add the attribute definitions.
Dim blkTblR As BlockTableRecord = bkObjId.GetObject(OpenMode.ForWrite)
For Each objId As ObjectId In blkTblR
Dim obj As DBObject = objId.GetObject(OpenMode.ForRead)
If TypeOf obj Is AttributeDefinition Then
Dim ad As AttributeDefinition = objId.GetObject(OpenMode.ForRead)
Dim ar As AttributeReference = New AttributeReference()
ar.SetAttributeFromBlock(ad, BlkRef.BlockTransform)
ar.Position = ad.Position.TransformBy(BlkRef.BlockTransform)
BlkRef.AttributeCollection.AppendAttribute(ar)
acTransInsbk.AddNewlyCreatedDBObject(ar, True)
End If
Next
'On instancie la collection d'attribut
Dim NewacAttColl As AttributeCollection = BlkRef.AttributeCollection
'On explore la collection et on récupère son identifiantv
If acAttColl IsNot Nothing Then
For Each NewattReferenceId As ObjectId In NewacAttColl
'On récupère l'objet dans la base et on le déclare en temps qu'attribut autocad
Dim dbObj As DBObject = acTransInsbk.GetObject(NewattReferenceId, OpenMode.ForRead)
Dim NewattReference As AttributeReference = dbObj
If NewattReference IsNot Nothing Then
For Each attReferenceId As ObjectId In acAttColl
''On récupère l'objet dans la base et on le déclare en temps qu'attribut autocad
Dim dbObj2 As DBObject = acTransInsbk.GetObject(attReferenceId, OpenMode.ForRead)
Dim attReference As AttributeReference = dbObj2
If attReference IsNot Nothing Then
If attReference.Tag.ToUpper() = NewattReference.Tag.ToUpper() Then 'On verifie si l'étiquette est celle que l'on a défini
NewattReference.UpgradeOpen()
NewattReference.TextString = attReference.TextString
NewattReference.DowngradeOpen()
End If
End If
Next
End If
Next
End If
BlkRef.Rotation = acRotBLock
' explode the block
BlkRef.UpgradeOpen()
Dim newpc As DynamicBlockReferencePropertyCollection = BlkRef.DynamicBlockReferencePropertyCollection
For Each prop As DynamicBlockReferenceProperty In newpc
For Each oldprop As DynamicBlockReferenceProperty In pc
If oldprop.PropertyName = prop.PropertyName Then
MsgBox(oldprop.Value)
'This is not working:
prop.Value = oldprop.Value
End If
Next
Next
BlkRef.DowngradeOpen()
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.