- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a function that clones drawing layouts from a source drawing to a current working (target) drawing. This function is causing a *Warning* Multiply owned object, handle "F4" warning after the layout is cloned and the target drawing saved. Since I've audit and recovered the target drawing and found no errors, this warning is just annoying.
Here's the code:
Public Function ImportLayout(ByVal filename As String, ByVal layoutname As String) As ObjectId
Dim idLayout As ObjectId = ObjectId.Null
Dim doc As Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim oLock As DocumentLock = doc.LockDocument()
Dim dbSource As New Database(False, False)
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Try
dbSource.ReadDwgFile(filename, System.IO.FileShare.Read, True, Nothing)
Dim idDbdSource As ObjectId = dbSource.LayoutDictionaryId
Dim dbdLayout As DBDictionary = DirectCast(trans.GetObject(idDbdSource, OpenMode.ForRead, False, False), DBDictionary)
For Each deLayout As DictionaryEntry In dbdLayout
Dim sLayout As String = deLayout.Key.ToString()
If sLayout.ToUpper() = layoutname.ToUpper() Then
idLayout = DirectCast(deLayout.Value, ObjectId)
Exit For
End If
Next
If idLayout <> ObjectId.Null Then
Dim idc As New ObjectIdCollection()
idc.Add(idLayout)
Dim im As IdMapping = New IdMapping()
Dim dbdict As DBDictionary = DirectCast(trans.GetObject(db.LayoutDictionaryId, OpenMode.ForRead, False, False), DBDictionary)
dbdict.UpgradeOpen()
db.WblockCloneObjects(idc, db.LayoutDictionaryId, im, DuplicateRecordCloning.MangleName, False)
Dim ip As IdPair = im.Lookup(idLayout)
idLayout = ip.Value
Dim lm As LayoutManager = LayoutManager.Current
lm.CurrentLayout = layoutname
dbdict.DecomposeForSave(DwgVersion.Current)
ed.Regen()
End If
trans.Commit()
Catch ex As System.Exception
MsgBox(ex.StackTrace)
Finally
trans.Dispose()
dbSource.Dispose()
oLock.Dispose()
End Try
Return idLayout
End Function
Any help would be greatly appreciated.
Thanks in advance.
Solved! Go to Solution.