I'm still really new at my efforts to code in .NET, so any help or direction is greatly appreciated.
I'm trying to loop through blocks in paperspace for a specific name and then edit it's attributes. The code works fine if the block is a standard block, but does not see dyanmic blocks.
I have looked through other posts and can see how there is a isdynamic property, but just don't know how to apply it here.
The function i have to update the attributes expects the objectid of the block. Just don't know how to get that if the block is dynamic.
Dim TbloOjbectID As ObjectId Dim mydb As New Database(False, True) mydb.ReadDwgFile(Newfname, FileOpenMode.OpenForReadAndWriteNoShare, True, "") Using Trans As Transaction = mydb.TransactionManager.StartTransaction() Dim myblocktable As BlockTable = mydb.BlockTableId.GetObject(OpenMode.ForRead) Dim mypaperspace As BlockTableRecord = myblocktable(BlockTableRecord.PaperSpace).GetObjec
t(OpenMode.ForRead) For Each myBTR As ObjectId In mypaperspace If myBTR.ObjectClass.DxfName = "INSERT" Then Dim myBref As BlockReference = myBTR.GetObject(OpenMode.ForRead) If UCase(Left(myBref.Name, 4)) = "TBLO" Then TbloOjbectID = myBref.ObjectId If DwgTitle.Length > 0 Then SetAttribute(TbloOjbectID, "PROJECT/CONTRACT_NAME", DwgTitle) End If End If End If Next Trans.Commit() End Using
Thanks for any help or suggestions.
Solved! Go to Solution.
got the following to work, but not sure if it is the best way.
If myBref.IsDynamicBlock Then Dim oDoID As ObjectId = myBref.DynamicBlockTableRecord Dim oDBtr As BlockTableRecord = oDoID.GetObject(OpenMode.ForRead) If UCase(Left(oDBtr.Name, 4)) = "TBLO" Then TbloOjbectID = myBref.ObjectId End If Else If UCase(Left(myBref.Name, 4)) = "TBLO" Then TbloOjbectID = myBref.ObjectId End If End If
Your last code snippet looks ok.
Looking at the original post, it seems you were unclear about the distinction between BlockTableRecord (BTR) and a block reference.
A block (BlockTableRecord) can be identified by iterating the BlockTable. "PaperSpace" is also a "BlockTableRecord" and by iterating it, you can identify entities in it but not other BlockTableRecords.
For example, this line in your original code snippet is misleading : "For Each myBTR As ObjectId In mypaperspace"
This should be, for example : "For Each entityId As ObjectId in mypaperspace"
Paperspace can only contain entities such as Lines, circles, BlockReferences etc. By iterating it, you will not find a BlockTableRecord id.
Hope this clarifies.