Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
When I manually add a new layout from a template, I do NOT get any extra layers, but when I use VB to do the same thing, I get extra layers.
In the original drawing, I have layers called "SHEET", "TEXT", and "VIEWPORT" (among other layers).
In the template where I get my new layout, I also have the same layer names ("SHEET", "TEXT", and "VIEWPORT").
After the new layout gets read in, I now have extra layers called "$0$SHEET", "$0$TEXT", and "$0$VIEWPORT". Why does this happen using VB, but not when I do it manually? Is there anything I can do to the code to change this? I understand the layer names are the same, but they're the same whether I do it manually or by code.
Public Function importLayout(ByVal templateFileName As String, ByVal templateLayoutName As String) As ObjectId Dim idLayout As ObjectId = ObjectId.Null Dim doc As Document = 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 templateTrans As Transaction = db.TransactionManager.StartTransaction() Try dbSource.ReadDwgFile(templateFileName, System.IO.FileShare.Read, True, Nothing) Dim idDbdSource As ObjectId = dbSource.LayoutDictionaryId Dim layoutDictionary As DBDictionary = DirectCast(templateTrans.GetObject(idDbdSource, OpenMode.ForRead, False, False), DBDictionary) For Each deLayout As DictionaryEntry In layoutDictionary Dim sLayout As String = deLayout.Key.ToString() If sLayout.ToUpper() = templateLayoutName.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 idMap As IdMapping = New IdMapping() Dim dbdict As DBDictionary = DirectCast(templateTrans.GetObject(db.LayoutDictionaryId, OpenMode.ForRead, False, False), DBDictionary) dbdict.UpgradeOpen() db.WblockCloneObjects(idc, db.LayoutDictionaryId, idMap, DuplicateRecordCloning.MangleName, False) Dim ip As IdPair = idMap.Lookup(idLayout) idLayout = ip.Value Dim layoutMgr As LayoutManager = LayoutManager.Current layoutMgr.CurrentLayout = templateLayoutName dbdict.DecomposeForSave(DwgVersion.Current) ed.Regen() End If templateTrans.Commit() Catch ex As Autodesk.AutoCAD.Runtime.Exception MsgBox(ex.StackTrace) Finally templateTrans.Dispose() dbSource.Dispose() oLock.Dispose() End Try Return idLayout End Function
Thanks,
Mark
Solved! Go to Solution.