Update Dynamic block definition from other file's block definition

Update Dynamic block definition from other file's block definition

Anonymous
Not applicable
927 Views
2 Replies
Message 1 of 3

Update Dynamic block definition from other file's block definition

Anonymous
Not applicable

I use the the below to update block definitions from other drawings. It works on both regular and dynamic blocks. For some reason when the block is dynamic I get errors when auditing along with the "Program Errors were detected. Recommend that you save your work and restart the program." Everything else works as expected. Audit error example directly below. Does anyone have any insight on why I'm getting audit errors when updating dynamic block definitions?

 

 

Pass 1 200 objects auditedAcDbSortentsTable(1886)
AcDbSortEntsTable Block Id not valid fixed.

Auditing Entities Pass 2

Pass 2 100 objects auditedAcDbBlockBasepointParameter(1849)
could not be repaired. It will be Erased.
AcDbBlockLinearParameter(184A) could not be repaired. It will be Erased.
AcDbBlockLinearGrip(184B) could not be repaired. It will be Erased.
AcDbBlockGripExpr(184C) could not be repaired. It will be Erased.
AcDbBlockGripExpr(184D) could not be repaired. It will be Erased.
AcDbBlockArrayAction(184E) could not be repaired. It will be Erased.
Pass 2 200 objects audited
Auditing Blocks


3 Blocks audited

Total errors found 1 fixed 1

Erased 6 objects

 

 

 

 

 

 

 

 

 

 

Sub UpdateBlockDefinitions(myTargetDB As Database, DrawingFilePath As String, BlockName As String)
          Dim myTargetDoc As Document = DocumentManager.MdiActiveDocument


          Dim myObjIDColl As New ObjectIdCollection
          myObjIDColl.Clear()

 

          'Read the drawing into a side database to update block definition


          Dim mySourceDB As New Database(False, True)
          mySourceDB.ReadDwgFile(DrawingFilePath, FileOpenMode.OpenForReadAndAllShare, True, "")


          Using mySourceTrans As Transaction = mySourceDB.TransactionManager.StartTransaction


          ' Open the Block table for read
                    Dim mySourceBT As BlockTable = CType(mySourceTrans.GetObject(mySourceDB.BlockTableId, OpenMode.ForRead), BlockTable)

                    For Each myID As ObjectId In mySourceBT
                              Dim mySourceBTR As BlockTableRecord = CType(mySourceTrans.GetObject(myID, OpenMode.ForRead), BlockTableRecord)
                              'Filter out modelspace and paperspaces
                                        If Not mySourceBTR.Name.StartsWith("*") And Not mySourceBTR.Name.StartsWith("_") Then
                                                  If mySourceBTR.Name = BlockName Then
                                                            If mySourceBT.Has(mySourceBTR.Name) Then
                                                                      'Add blocktablerecord to collection for cloning
                                                                      myObjIDColl.Add(myID)
                                                            End If
                                                  End If
                                        End If
                    Next
                    mySourceTrans.Commit()
          End Using


          If myObjIDColl.Count > 0 Then


                    'lock target document
                    Using myTargetLock As DocumentLock = myTargetDoc.LockDocument

                              Using myTargetTrans As Transaction = myTargetDB.TransactionManager.StartTransaction
                                        ' Open the Block table for read
                                        Dim myTargetBT As BlockTable = CType(myTargetTrans.GetObject(myTargetDB.BlockTableId, OpenMode.ForRead), BlockTable)

                                        ' Open the Block table record Model space for read
                                         Dim myTargetBTR As BlockTableRecord = CType(myTargetTrans.GetObject(myTargetBT(BlockTableRecord.ModelSpace), OpenMode.ForRead), BlockTableRecord)

                                        Dim BRobjectid As List(Of ObjectId) = CType(GetBlockReference(myTargetDB, BlockName), Global.System.Collections.Generic.List(Of Global.Autodesk.AutoCAD.DatabaseServices.ObjectId))


                                        Dim myMap As New IdMapping

                                        'Clone the collection from the tempDB blocktable to the current drawing's blocktable
                                        mySourceDB.WblockCloneObjects(myObjIDColl, myTargetDB.CurrentSpaceId, myMap, DuplicateRecordCloning.Replace, False)

                                        'Update the anonymous blocks (dynamic blocks)
                                         Dim targetBlockDef As BlockTableRecord = CType(myTargetBT(BlockName).GetObject(OpenMode.ForRead), BlockTableRecord)
                                        targetBlockDef.UpdateAnonymousBlocks()

 

                              myTargetTrans.Commit()
                    End Using

          End Using
          mySourceDB.Dispose()

End If

0 Likes
928 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Autocad 2012 64 bit by the way

0 Likes
Message 3 of 3

Paulio
Advocate
Advocate

Hi trcorp.

 

Did you ever solve this? I'm getting the same problem (although AutoCAD 2015 64 bit).

 

Your post helped me to solve a problem I had with the graphics not updating when re-defining the dynamic block (it was the call to UpdateAnonymousBlocks that I was missing so thanks for that).

 

I'm getting a handful of:

 

Incorrect object node id
changed to zero

 

errors after the redefine.

 

If you haven't resolved it then hopefully this reply will bump this post back to the top and someone will see it and help us both!

0 Likes