<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Switching layouts in .net in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298174#M74130</link>
    <description>I got rid of the .dispose (I found that suggestion on another post you made).  The error occurs on line:&lt;BR /&gt;
&lt;BR /&gt;
return pRetVal;&lt;BR /&gt;
&lt;BR /&gt;
in CThreadSlotData::GetThreadValue of the afxtls.cpp file.  It is:&lt;BR /&gt;
&lt;BR /&gt;
Unhandled exception at 0x004bd022 in acad.exe: 0xC0000005: Access violation reading location 0x7efea8bc.&lt;BR /&gt;
&lt;BR /&gt;
Ceorl</description>
    <pubDate>Fri, 18 Jul 2008 13:28:27 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2008-07-18T13:28:27Z</dc:date>
    <item>
      <title>Switching layouts in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298168#M74124</link>
      <description>Hello,&lt;BR /&gt;
I've written a dll that cycles through a set of drawings using databaseservices.  I'm using the readdwgfile method to open my drawings.  All is going well with one exception.  I need to delete some unused layouts.  I can delete them, but when I reopen the drawing, I discover I need to recover them.  This occurs because in some instances I'm deleting the current layout.  Is there a way to switch the current layout without having to physically open the drawing?  I'm trying the layoutmanager.current.currentlayout method without success.  Any other ideas?&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance,&lt;BR /&gt;
Ceorl</description>
      <pubDate>Fri, 11 Jul 2008 16:37:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298168#M74124</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-11T16:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Switching layouts in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298169#M74125</link>
      <description>Try setting the value of the HostApplicationServices WorkingDatabase property to the database containing the layouts you're trying to switch.&lt;BR /&gt;
&lt;BR /&gt;
Make sure to save the current value and restore it afterwards.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2009&lt;BR /&gt;
Supporting AutoCAD 2000 through 2009&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Introducing AcadXTabs 2010:&lt;BR /&gt;
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm&lt;BR /&gt;
&lt;BR /&gt;
&lt;CEORL&gt; wrote in message news:5979608@discussion.autodesk.com...&lt;BR /&gt;
Hello,&lt;BR /&gt;
I've written a dll that cycles through a set of drawings using databaseservices.  I'm using the readdwgfile method to open my drawings.  All is going well with one exception.  I need to delete some unused layouts.  I can delete them, but when I reopen the drawing, I discover I need to recover them.  This occurs because in some instances I'm deleting the current layout.  Is there a way to switch the current layout without having to physically open the drawing?  I'm trying the layoutmanager.current.currentlayout method without success.  Any other ideas?&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance,&lt;BR /&gt;
Ceorl&lt;/CEORL&gt;</description>
      <pubDate>Sat, 12 Jul 2008 18:45:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298169#M74125</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-12T18:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Switching layouts in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298170#M74126</link>
      <description>Hey, I appreciate the help.  The code cycles through every drawing and switch layouts as intended, but when all is said and done, I get an exception error from:&lt;BR /&gt;
&lt;BR /&gt;
inline void* CThreadSlotData::GetThreadValue(int nSlot)&lt;BR /&gt;
{&lt;BR /&gt;
	EnterCriticalSection(&amp;amp;m_sect);&lt;BR /&gt;
	ASSERT(nSlot != 0 &amp;amp;&amp;amp; nSlot &amp;lt; m_nMax);&lt;BR /&gt;
	ASSERT(m_pSlotData != NULL);&lt;BR /&gt;
	ASSERT(m_pSlotData[nSlot].dwFlags &amp;amp; SLOT_USED);&lt;BR /&gt;
	ASSERT(m_tlsIndex != (DWORD)-1);&lt;BR /&gt;
	if( nSlot &amp;lt;= 0 || nSlot &amp;gt;= m_nMax ) // check for retail builds.&lt;BR /&gt;
	{&lt;BR /&gt;
		LeaveCriticalSection(&amp;amp;m_sect);&lt;BR /&gt;
		return NULL;&lt;BR /&gt;
	}&lt;BR /&gt;
&lt;BR /&gt;
	CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex);&lt;BR /&gt;
	if (pData == NULL || nSlot &amp;gt;= pData-&amp;gt;nCount)&lt;BR /&gt;
	{&lt;BR /&gt;
		LeaveCriticalSection(&amp;amp;m_sect);&lt;BR /&gt;
		return NULL;&lt;BR /&gt;
	}&lt;BR /&gt;
	void* pRetVal = pData-&amp;gt;pData[nSlot];&lt;BR /&gt;
	LeaveCriticalSection(&amp;amp;m_sect);&lt;BR /&gt;
	return pRetVal;&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
The code stops on the return pRetVal line.  Do you know what's happening here?&lt;BR /&gt;
&lt;BR /&gt;
So you have something to visualize, I have a DWG class that looks like:&lt;BR /&gt;
&lt;BR /&gt;
Public Class Dwg&lt;BR /&gt;
    Private DwgName As String&lt;BR /&gt;
    Private Visibility As Boolean&lt;BR /&gt;
    Private MyDwg As Autodesk.AutoCAD.ApplicationServices.Document&lt;BR /&gt;
    Private MyDb As Autodesk.AutoCAD.DatabaseServices.Database&lt;BR /&gt;
    Private MyTransMan As Autodesk.AutoCAD.DatabaseServices.TransactionManager&lt;BR /&gt;
    Private MyTrans As Autodesk.AutoCAD.DatabaseServices.Transaction&lt;BR /&gt;
    Private MyEd As Autodesk.AutoCAD.EditorInput.Editor&lt;BR /&gt;
    Private CurDb As Autodesk.AutoCAD.DatabaseServices.Database&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub New(ByVal DrawingName As String, ByVal Visible As Boolean)&lt;BR /&gt;
        If Visible = True Then&lt;BR /&gt;
            Visibility = True&lt;BR /&gt;
            MyDwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(DrawingName, False)&lt;BR /&gt;
            MyDb = MyDwg.Database&lt;BR /&gt;
            MyDwg.LockDocument()&lt;BR /&gt;
            MyTransMan = MyDwg.TransactionManager&lt;BR /&gt;
            MyTrans = MyTransMan.StartTransaction&lt;BR /&gt;
        Else&lt;BR /&gt;
            Visibility = False&lt;BR /&gt;
            MyDb = New DatabaseServices.Database(False, True)&lt;BR /&gt;
            MyDb.ReadDwgFile(DrawingName, IO.FileShare.ReadWrite, True, "")&lt;BR /&gt;
            MyTransMan = MyDb.TransactionManager&lt;BR /&gt;
            MyTrans = MyTransMan.StartTransaction&lt;BR /&gt;
            CurDb = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = MyDb&lt;BR /&gt;
        End If&lt;BR /&gt;
        DwgName = DrawingName&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
Public Sub EndDrawing()&lt;BR /&gt;
        MyTrans.Commit()&lt;BR /&gt;
        MyTrans.Dispose()&lt;BR /&gt;
        MyTransMan.Dispose()&lt;BR /&gt;
        If Visibility = True Then&lt;BR /&gt;
            MyDwg.CloseAndSave(DwgName)&lt;BR /&gt;
            MyDb.Dispose()&lt;BR /&gt;
            mydwg.Dispose &lt;BR /&gt;
        Else&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = CurDb&lt;BR /&gt;
            CurDb.Dispose()&lt;BR /&gt;
            MyDb.SaveAs(DwgName, DwgVersion.Current)&lt;BR /&gt;
            MyDb.Dispose()&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
When I create the new drawing object, I provide a drawing name and a visibility option to determine whether the drawing opens as a drawing or a database.  I establish my transactions, database, etc...  I then use various methods that are unseen above and ultimately close the drawing/database using the EndDrawing method, which closes and disposes the transactions, databases, etc.&lt;BR /&gt;
&lt;BR /&gt;
If I understand your suggestion, it was to set the the HostApplicationServices.WorkingDatabase to the database I have open and to reset it back to the default when I was done.&lt;BR /&gt;
&lt;BR /&gt;
Record curent database:&lt;BR /&gt;
CurDb = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
&lt;BR /&gt;
Set database:&lt;BR /&gt;
HostApplicationServices.WorkingDatabase = MyDb&lt;BR /&gt;
&lt;BR /&gt;
Set it back:&lt;BR /&gt;
HostApplicationServices.WorkingDatabase = CurDb&lt;BR /&gt;
&lt;BR /&gt;
And dispose of it?&lt;BR /&gt;
CurDb.Dispose()&lt;BR /&gt;
&lt;BR /&gt;
Once again, any thoughts or suggestions are very much appreciated.&lt;BR /&gt;
Ceorl</description>
      <pubDate>Mon, 14 Jul 2008 15:32:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298170#M74126</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-14T15:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Switching layouts in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298171#M74127</link>
      <description>Sorry, but I don't see what the code you say is throwing the exception from has to do with switching layouts in managed code. That's C++.&lt;BR /&gt;
&lt;BR /&gt;
Read my first reply again. You can't leave the current working database set to your database any longer than needed. Your code should change the current working database, switch layouts or do whatever else it needs to do with the LayoutManager, and then immediately switch the current working database back to what it was originally. &lt;BR /&gt;
&lt;BR /&gt;
    // Save the current working database&lt;BR /&gt;
&lt;BR /&gt;
    Database original = HostApplicationServices.WorkingDatabase;&lt;BR /&gt;
&lt;BR /&gt;
    // Set the current working database to the one&lt;BR /&gt;
    // you need to switch layouts in&lt;BR /&gt;
   &lt;BR /&gt;
    HostApplicationServices.WorkingDatabase = myDb;&lt;BR /&gt;
&lt;BR /&gt;
    // switch layouts here or do whatever with LayoutManager&lt;BR /&gt;
    LayoutManager.Current.CurrentLayout = ....&lt;BR /&gt;
&lt;BR /&gt;
    // Restore the current working database IMMEDIATELY&lt;BR /&gt;
&lt;BR /&gt;
    HostApplicationServices.WorkingDatabase = original&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2009&lt;BR /&gt;
Supporting AutoCAD 2000 through 2009&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Introducing AcadXTabs 2010:&lt;BR /&gt;
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm&lt;BR /&gt;
&lt;BR /&gt;
&lt;CEORL&gt; wrote in message news:5980828@discussion.autodesk.com...&lt;BR /&gt;
Hey, I appreciate the help.  The code cycles through every drawing and switch layouts as intended, but when all is said and done, I get an exception error from:&lt;BR /&gt;
&lt;BR /&gt;
inline void* CThreadSlotData::GetThreadValue(int nSlot)&lt;BR /&gt;
{&lt;BR /&gt;
EnterCriticalSection(&amp;amp;m_sect);&lt;BR /&gt;
ASSERT(nSlot != 0 &amp;amp;&amp;amp; nSlot &amp;lt; m_nMax);&lt;BR /&gt;
ASSERT(m_pSlotData != NULL);&lt;BR /&gt;
ASSERT(m_pSlotData[nSlot].dwFlags &amp;amp; SLOT_USED);&lt;BR /&gt;
ASSERT(m_tlsIndex != (DWORD)-1);&lt;BR /&gt;
if( nSlot &amp;lt;= 0 || nSlot &amp;gt;= m_nMax ) // check for retail builds.&lt;BR /&gt;
{&lt;BR /&gt;
LeaveCriticalSection(&amp;amp;m_sect);&lt;BR /&gt;
return NULL;&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex);&lt;BR /&gt;
if (pData == NULL || nSlot &amp;gt;= pData-&amp;gt;nCount)&lt;BR /&gt;
{&lt;BR /&gt;
LeaveCriticalSection(&amp;amp;m_sect);&lt;BR /&gt;
return NULL;&lt;BR /&gt;
}&lt;BR /&gt;
void* pRetVal = pData-&amp;gt;pData[nSlot];&lt;BR /&gt;
LeaveCriticalSection(&amp;amp;m_sect);&lt;BR /&gt;
return pRetVal;&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
The code stops on the return pRetVal line.  Do you know what's happening here?&lt;BR /&gt;
&lt;BR /&gt;
So you have something to visualize, I have a DWG class that looks like:&lt;BR /&gt;
&lt;BR /&gt;
Public Class Dwg&lt;BR /&gt;
    Private DwgName As String&lt;BR /&gt;
    Private Visibility As Boolean&lt;BR /&gt;
    Private MyDwg As Autodesk.AutoCAD.ApplicationServices.Document&lt;BR /&gt;
    Private MyDb As Autodesk.AutoCAD.DatabaseServices.Database&lt;BR /&gt;
    Private MyTransMan As Autodesk.AutoCAD.DatabaseServices.TransactionManager&lt;BR /&gt;
    Private MyTrans As Autodesk.AutoCAD.DatabaseServices.Transaction&lt;BR /&gt;
    Private MyEd As Autodesk.AutoCAD.EditorInput.Editor&lt;BR /&gt;
    Private CurDb As Autodesk.AutoCAD.DatabaseServices.Database&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub New(ByVal DrawingName As String, ByVal Visible As Boolean)&lt;BR /&gt;
        If Visible = True Then&lt;BR /&gt;
            Visibility = True&lt;BR /&gt;
            MyDwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(DrawingName, False)&lt;BR /&gt;
            MyDb = MyDwg.Database&lt;BR /&gt;
            MyDwg.LockDocument()&lt;BR /&gt;
            MyTransMan = MyDwg.TransactionManager&lt;BR /&gt;
            MyTrans = MyTransMan.StartTransaction&lt;BR /&gt;
        Else&lt;BR /&gt;
            Visibility = False&lt;BR /&gt;
            MyDb = New DatabaseServices.Database(False, True)&lt;BR /&gt;
            MyDb.ReadDwgFile(DrawingName, IO.FileShare.ReadWrite, True, "")&lt;BR /&gt;
            MyTransMan = MyDb.TransactionManager&lt;BR /&gt;
            MyTrans = MyTransMan.StartTransaction&lt;BR /&gt;
            CurDb = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = MyDb&lt;BR /&gt;
        End If&lt;BR /&gt;
        DwgName = DrawingName&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
Public Sub EndDrawing()&lt;BR /&gt;
        MyTrans.Commit()&lt;BR /&gt;
        MyTrans.Dispose()&lt;BR /&gt;
        MyTransMan.Dispose()&lt;BR /&gt;
        If Visibility = True Then&lt;BR /&gt;
            MyDwg.CloseAndSave(DwgName)&lt;BR /&gt;
            MyDb.Dispose()&lt;BR /&gt;
            mydwg.Dispose &lt;BR /&gt;
        Else&lt;BR /&gt;
            HostApplicationServices.WorkingDatabase = CurDb&lt;BR /&gt;
            CurDb.Dispose()&lt;BR /&gt;
            MyDb.SaveAs(DwgName, DwgVersion.Current)&lt;BR /&gt;
            MyDb.Dispose()&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
End Class&lt;BR /&gt;
&lt;BR /&gt;
When I create the new drawing object, I provide a drawing name and a visibility option to determine whether the drawing opens as a drawing or a database.  I establish my transactions, database, etc...  I then use various methods that are unseen above and ultimately close the drawing/database using the EndDrawing method, which closes and disposes the transactions, databases, etc.&lt;BR /&gt;
&lt;BR /&gt;
If I understand your suggestion, it was to set the the HostApplicationServices.WorkingDatabase to the database I have open and to reset it back to the default when I was done.&lt;BR /&gt;
&lt;BR /&gt;
Record curent database:&lt;BR /&gt;
CurDb = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
&lt;BR /&gt;
Set database:&lt;BR /&gt;
HostApplicationServices.WorkingDatabase = MyDb&lt;BR /&gt;
&lt;BR /&gt;
Set it back:&lt;BR /&gt;
HostApplicationServices.WorkingDatabase = CurDb&lt;BR /&gt;
&lt;BR /&gt;
And dispose of it?&lt;BR /&gt;
CurDb.Dispose()&lt;BR /&gt;
&lt;BR /&gt;
Once again, any thoughts or suggestions are very much appreciated.&lt;BR /&gt;
Ceorl&lt;/CEORL&gt;</description>
      <pubDate>Mon, 14 Jul 2008 21:45:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298171#M74127</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-14T21:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Switching layouts in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298172#M74128</link>
      <description>No, I apologize.  I provided not enough information in some areas, and too much in others.  The C++ code is in an AFXTLS.CPP file, and the error appears after all the code has been executed.  The AFXTLS.CPP file is nothing I wrote, and its origin is unknown to me.  Your suggestion worked, but now I'm dealing with a new error, and like you, I don't understand what the relationship is between switching layouts and the AFXTLS.CPP file is (there may not even be one), I just know I'm getting an error when I try to switch working databases.  If I exclude my SetLayout method (see below), my layouts don't switch, but I'm error free.&lt;BR /&gt;
&lt;BR /&gt;
The MyDb variable is a private class variable established when I create a new drawing object.  I use it throughout the class, and so far, I haven't had any trouble with it (although, I wouldn't rule it out).&lt;BR /&gt;
&lt;BR /&gt;
Public Sub SetLayout(ByVal LName As String)&lt;BR /&gt;
        Dim CurDb As Autodesk.AutoCAD.DatabaseServices.Database&lt;BR /&gt;
       &lt;BR /&gt;
        CurDb = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
        HostApplicationServices.WorkingDatabase = MyDb&lt;BR /&gt;
&lt;BR /&gt;
        Dim MyLayoutMan As Autodesk.AutoCAD.DatabaseServices.LayoutManager&lt;BR /&gt;
        MyLayoutMan = LayoutManager.Current&lt;BR /&gt;
        MyLayoutMan.CurrentLayout = LName&lt;BR /&gt;
&lt;BR /&gt;
        HostApplicationServices.WorkingDatabase = CurDb&lt;BR /&gt;
        CurDb.Dispose()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
Ceorl</description>
      <pubDate>Thu, 17 Jul 2008 13:52:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298172#M74128</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-17T13:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Switching layouts in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298173#M74129</link>
      <description>Get rid of the call to CurDb.Dispose() for starters, because&lt;BR /&gt;
you don't call Dispose() on databases you did not create.&lt;BR /&gt;
&lt;BR /&gt;
Second, what's the error?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD 2009&lt;BR /&gt;
Supporting AutoCAD 2000 through 2009&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Introducing AcadXTabs 2010:&lt;BR /&gt;
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm&lt;BR /&gt;
&lt;BR /&gt;
&lt;CEORL&gt; wrote in message news:5983983@discussion.autodesk.com...&lt;BR /&gt;
No, I apologize.  I provided not enough information in some areas, and too much in others.  The C++ code is in an AFXTLS.CPP file, and the error appears after all the code has been executed.  The AFXTLS.CPP file is nothing I wrote, and its origin is unknown to me.  Your suggestion worked, but now I'm dealing with a new error, and like you, I don't understand what the relationship is between switching layouts and the AFXTLS.CPP file is (there may not even be one), I just know I'm getting an error when I try to switch working databases.  If I exclude my SetLayout method (see below), my layouts don't switch, but I'm error free.&lt;BR /&gt;
&lt;BR /&gt;
The MyDb variable is a private class variable established when I create a new drawing object.  I use it throughout the class, and so far, I haven't had any trouble with it (although, I wouldn't rule it out).&lt;BR /&gt;
&lt;BR /&gt;
Public Sub SetLayout(ByVal LName As String)&lt;BR /&gt;
        Dim CurDb As Autodesk.AutoCAD.DatabaseServices.Database&lt;BR /&gt;
       &lt;BR /&gt;
        CurDb = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
        HostApplicationServices.WorkingDatabase = MyDb&lt;BR /&gt;
&lt;BR /&gt;
        Dim MyLayoutMan As Autodesk.AutoCAD.DatabaseServices.LayoutManager&lt;BR /&gt;
        MyLayoutMan = LayoutManager.Current&lt;BR /&gt;
        MyLayoutMan.CurrentLayout = LName&lt;BR /&gt;
&lt;BR /&gt;
        HostApplicationServices.WorkingDatabase = CurDb&lt;BR /&gt;
        CurDb.Dispose()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
Ceorl&lt;/CEORL&gt;</description>
      <pubDate>Fri, 18 Jul 2008 03:23:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298173#M74129</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-18T03:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Switching layouts in .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298174#M74130</link>
      <description>I got rid of the .dispose (I found that suggestion on another post you made).  The error occurs on line:&lt;BR /&gt;
&lt;BR /&gt;
return pRetVal;&lt;BR /&gt;
&lt;BR /&gt;
in CThreadSlotData::GetThreadValue of the afxtls.cpp file.  It is:&lt;BR /&gt;
&lt;BR /&gt;
Unhandled exception at 0x004bd022 in acad.exe: 0xC0000005: Access violation reading location 0x7efea8bc.&lt;BR /&gt;
&lt;BR /&gt;
Ceorl</description>
      <pubDate>Fri, 18 Jul 2008 13:28:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switching-layouts-in-net/m-p/2298174#M74130</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-07-18T13:28:27Z</dc:date>
    </item>
  </channel>
</rss>

