Fatty - At the risk of discouraging you from posting code, I am going to say this anways, because I think others that come here to get help and learn to code using the .NET API, are entitled to know it.
I mentioned this to you in the past, but you chosen to ignore it for whatever reason, and as a result, you are posting code that does not serve as a good example for anyone.
So mainly for the benefit of others, here it goes yet once again:
You do not call Dispose() on objects that are under control of 'Using', because that is what 'Using' is for, to begin with. 'Using' automatically calls Dispose() for you.
And so, this:
Using obj As MyDisposable = New MyDisposable()
obj.DoSomething() ' use 'obj' here
End Using
is exactly the same as this:
Dim obj As MyDisposable = New MyDisposable()
Try
obj.DoSomething() ' use 'obj' here
Finally
obj.Dispose()
End Try
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
wrote in message news:5831311@discussion.autodesk.com...
Hi Bruno
Try this instead
Public Sub CopyLayerFrom(ByVal lname As String, ByVal fname As String)
Try
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim thisDb As Database = HostApplicationServices.WorkingDatabase
Using docLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument
Try
Using db As Database = New Database(False, False)
Try
db.ReadDwgFile(fname, System.IO.FileShare.Read, True, Nothing)
Using tr As Transaction = db.TransactionManager.StartTransaction
Try
Dim lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead, False)
Dim ltr As LayerTableRecord = tr.GetObject(lt(lname), OpenMode.ForRead)
Using thisTr As Transaction = thisDb.TransactionManager.StartTransaction
Dim thisLt As LayerTable = thisTr.GetObject(thisDb.LayerTableId, OpenMode.ForWrite)
Dim map As New IdMapping()
Dim objIDs As ObjectIdCollection = New ObjectIdCollection
objIDs.Add(ltr.ObjectId)
thisDb.WblockCloneObjects(objIDs, thisLt.ObjectId, map, DuplicateRecordCloning.Replace, False) 'no defer
thisTr.Commit()
End Using
tr.Commit()
Finally
CType(tr, IDisposable).Dispose()
End Try
End Using
Finally
CType(db, IDisposable).Dispose()
End Try
End Using
Finally
CType(docLock, IDisposable).Dispose()
End Try
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(ControlChars.CrLf & "Error {0} Copy layer from other document" & ControlChars.CrLf, ex)
ed.WriteMessage(ex.StackTrace)
End Try
End Sub
~'J'~