.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Extra Layer Names When Importing a Layout From a Template

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
mgorecki
473 Views, 4 Replies

Extra Layer Names When Importing a Layout From a Template

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

4 REPLIES 4
Message 2 of 5
jeff
in reply to: mgorecki

Looking real quick at your WblockCloneObjects call your DuplicateRecordCloning argument is set to DuplicateRecordCloning.MangleName.

 

From docs

MangleName -  Mangle all the incoming record names using $0$  

 

You can also find your answers @ TheSwamp
Message 3 of 5
mgorecki
in reply to: jeff

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

Message 4 of 5
jeff
in reply to: mgorecki

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.

You can also find your answers @ TheSwamp
Message 5 of 5
mgorecki
in reply to: jeff

Thanks for the info.  I've made a shortcut to it on my desktop.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost