Layout import code fails in AutoCAD 2015
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The following code for importing a layout from another drawing works fine except for in 2015. In 2015, I get an eSetFailed error and the layout does not get created. I would to get any help to get this code working in 2015 also.
Public Shared Sub CopyLayerFrom(ByVal lname As String)
' Check if the application is still initalizing.
If Starting Then
Exit Sub
End If
Try
' Get the active Document, Editor, and Database objects.
Dim doc As Document = Core.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim thisDb As Database = HostApplicationServices.WorkingDatabase
' Lock our Active Database.
Using docLock As DocumentLock = Core.Application.DocumentManager.MdiActiveDocument.LockDocument
' Start a Transaction with the "Standard DB"
Using tr As Transaction = Db.TransactionManager.StartTransaction
' Get our Layer Table from our ""Standard DB"" and double check the Layer exists.
Dim lt As LayerTable = CType(tr.GetObject(Db.LayerTableId, OpenMode.ForRead, False), LayerTable)
If lt.Has(lname) Then
' Get our Layer as an object and make sure it isn't erased (this would cause AutoCAD to crash if we imported a deleted layer).
Dim ltr As LayerTableRecord = CType(tr.GetObject(lt(lname), OpenMode.ForRead), LayerTableRecord)
If Not ltr.IsErased Then
' Start a transaction with the Active Database
Using thisTr As Transaction = thisDb.TransactionManager.StartTransaction
Dim thisLt As LayerTable = CType(thisTr.GetObject(thisDb.LayerTableId, OpenMode.ForWrite), LayerTable)
If thisLt.Has(lname) Then
' Clone the Layer
Dim map As New IdMapping()
Dim objIDs As ObjectIdCollection = New ObjectIdCollection
objIDs.Add(ltr.ObjectId)
thisDb.WblockCloneObjects(objIDs, thisLt.ObjectId, map, DuplicateRecordCloning.Ignore, False) 'no defer
thisTr.Commit()
Else
' Clone the Layer
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 If
thisDb.Clayer = thisLt(lname)
End Using
tr.Commit()
End If
End If
End Using
End Using
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.Message + vbCrLf + vbCrLf + ex.ToString)
End Try
End Sub