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.
Solved by jeff. Go to Solution.
Hi Jeff,
Thank you very much for your help. That did the trick. Where can I find out info like this? I looked in http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html, but I didn't see where it broke the command down to include the arguments.
Thanks,
Mark
Look inside the ObjectArx docs folder.
The arxmgd.chm is the .NET API but I would strongly suggest using the arxdoc.chm.
The arxdoc.chm contains the arxmgd.chm but contains the ObjectARX developers guide that has alot of useful information to give some deeper explanations on what the .NET API in end is using.