.NET

Reply
Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 1 of 4 (221 Views)
Accepted Solution

ObjectID of dynamic blocks

221 Views, 3 Replies
08-01-2013 12:04 PM

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.

 

Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 2 of 4 (211 Views)

Re: ObjectID of dynamic blocks

08-01-2013 01:37 PM in reply to: cjacobi

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

 

ADN Support Specialist
Balaji_Ram
Posts: 692
Registered: ‎03-21-2011
Message 3 of 4 (173 Views)

Re: ObjectID of dynamic blocks

08-06-2013 05:01 AM in reply to: cjacobi

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

Valued Contributor
cjacobi
Posts: 54
Registered: ‎11-12-2012
Message 4 of 4 (166 Views)

Re: ObjectID of dynamic blocks

08-06-2013 05:45 AM in reply to: Balaji_Ram

Thank you Balaji!

 

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

 

THANK YOU

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.