.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ObjectID of dynamic blocks

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
coralie.jacobi
501 Views, 3 Replies

ObjectID of dynamic blocks

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).GetObject(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.

 

3 REPLIES 3
Message 2 of 4

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

 

Message 3 of 4
Balaji_Ram
in reply to: coralie.jacobi

Hi,

 

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.

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 4 of 4
coralie.jacobi
in reply to: Balaji_Ram

Thank you Balaji!

 

Yes, that makes it all clear now, I really appreciate the response.

 

THANK YOU

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost