.NET

Reply
Mentor
mgorecki
Posts: 399
Registered: ‎09-23-2004
Message 1 of 5 (172 Views)
Accepted Solution

Extra Layer Names When Importing a Layout From a Template

172 Views, 4 Replies
07-06-2012 03:36 PM

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

Valued Mentor
jeff
Posts: 322
Registered: ‎05-12-2009
Message 2 of 5 (171 Views)

Re: Extra Layer Names When Importing a Layout From a Template

07-06-2012 03:58 PM 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
Mentor
mgorecki
Posts: 399
Registered: ‎09-23-2004
Message 3 of 5 (137 Views)

Re: Extra Layer Names When Importing a Layout From a Template

07-09-2012 10:17 AM 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

Valued Mentor
jeff
Posts: 322
Registered: ‎05-12-2009
Message 4 of 5 (133 Views)

Re: Extra Layer Names When Importing a Layout From a Template

07-09-2012 10:25 AM 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
Mentor
mgorecki
Posts: 399
Registered: ‎09-23-2004
Message 5 of 5 (127 Views)

Re: Extra Layer Names When Importing a Layout From a Template

07-09-2012 01:05 PM in reply to: jeff

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community