Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've asked this before but I confused the topic when I posted code that was unrelated.
Inserting multiple blocks and changing their dynamic block properties under the one transactions requires multiple undo's to reverse a single command.
I think if I change to StartOpenCloseTransaction from StartTransaction it might fix it.
The problem with doing that is that that I get an eWasOpenForRead on the line:
destdb.WblockCloneObjects(ids, destdb.BlockTableId, iMap, DuplicateRecordCloning.Replace, False)
Which doesn't occur when using StartTransaction.
Public Sub ImportBlock(ByVal blockFileName As String, ByVal Blockname As String, ByRef trans As Transaction)
Dim destdb As Database = Application.DocumentManager.MdiActiveDocument.Database
Try
Using sourcedb As New Database(False, True)
sourcedb.ReadDwgFile(blockFileName, FileShare.ReadWrite, True, "")
Dim ids As New ObjectIdCollection()
Using sourceTrans As Transaction = sourcedb.TransactionManager.StartOpenCloseTransaction()
Dim sourceBT As BlockTable
sourceBT = DirectCast(sourceTrans.GetObject(sourcedb.BlockTableId, OpenMode.ForRead), BlockTable)
If sourceBT.Has(Blockname) Then
ids.Add(sourceBT(Blockname))
Else
MsgBox("ImportBlock - Blockname not found in file" & vbCrLf & "Block must be incorrectly named.")
Cancel = True
Return
End If
End Using
'if found, add the block
If ids.Count <> 0 Then
'get the current drawing database
Dim iMap As New IdMapping()
destdb.WblockCloneObjects(ids, destdb.BlockTableId, iMap, DuplicateRecordCloning.Replace, False)
End If
End Using
Catch ex As Exception
Cancel = True
If ex.Message = "eFileSharingViolation" Then
MsgBox("Close Blocks Drawing. ", MsgBoxStyle.Exclamation)
ElseIf ex.Message = "eFileNotFound" Then
MsgBox("Block File Not Found. ", MsgBoxStyle.Exclamation)
Else
MsgBox(Reflection.MethodBase.GetCurrentMethod.Name() + " Exception: " + ex.Message)
End If
End Try
End Sub
Hope someone can help.
Solved! Go to Solution.