Active Member
Posts: 7
Registered: ‎12-21-2009
Message 1 of 4 (173 Views)

Set CurrentLayout

173 Views, 3 Replies
01-07-2013 05:16 AM

Can someone please tell me why I get an 'esetfailed' error?  I must be missing something simple.  Just before this sub I call another sub that changes the active document. ?? This is in AutioCAD 2011 w/ 64bit environment.


    Public Shared Sub ActiveLayout(ByVal name As String)
        Dim acDoc As Document = AcApp.DocumentManager.MdiActiveDocument
        Dim Db As Database = HostApplicationServices.WorkingDatabase
        Dim tdoclock As DocumentLock = acDoc.LockDocument
        Dim layMgr As LayoutManager = LayoutManager.Current
        Using acTrans As Transaction = Db.TransactionManager.StartTransaction()
                If Not Regex.Match(layMgr.CurrentLayout, name).Success() Then
                    layMgr.CurrentLayout = name
                End If
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message & vbCr & ex.HelpLink & vbCr & ex.StackTrace)
                tdoclock = Nothing
            End Try
        End Using
    End Sub


Any help is greatly appreciated.


*Expert Elite*
Posts: 1,982
Registered: ‎04-29-2006
Message 2 of 4 (152 Views)

Re : Set CurrentLayout

01-07-2013 08:34 AM in reply to: mpalan2009



eSetFailed is probably due to the fact the 'name' Layout does not exist in the drawing and no need to complicate so much.

This works for me:

        Public Shared Sub ActiveLayout(ByVal name As String)
                LayoutManager.Current.CurrentLayout = name
                MsgBox(String.Format("Layout '{0}' not found", name))
            End Try
        End Sub


Gilles Chanteau
Active Member
Posts: 7
Registered: ‎12-21-2009
Message 3 of 4 (144 Views)

Re : Set CurrentLayout

01-07-2013 10:30 AM in reply to: _gile

I would like to change the question.  Why does that code not work for Drawing1.dwg and Layout1?  It does work with other drawings I have.  I don't have a reason to operate on that drawing, So I will exclude it from the forms listbox.




*Expert Elite*
Posts: 1,558
Registered: ‎10-08-2008
Message 4 of 4 (126 Views)

Re : Set CurrentLayout

01-07-2013 01:33 PM in reply to: mpalan2009

Delete "acTrans.Dispose" from Finally code block

and try again


You are not logged in.

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

Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

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

Ask the Community