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

Set CurrentLayout

3 REPLIES 3
Reply
Message 1 of 4
mpalan2009
1503 Views, 3 Replies

Set CurrentLayout

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()
            Try
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(acDoc.Name)
                If Not Regex.Match(layMgr.CurrentLayout, name).Success() Then
                    layMgr.CurrentLayout = name
                End If
                acTrans.Commit()
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message & vbCr & ex.HelpLink & vbCr & ex.StackTrace)
            Finally
                acTrans.Dispose()
                tdoclock.Dispose()
                tdoclock = Nothing
            End Try
        End Using
    End Sub

 

Any help is greatly appreciated.

Matthew

Tags (1)
3 REPLIES 3
Message 2 of 4
_gile
in reply to: mpalan2009

Hi,

 

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)
            Try
                LayoutManager.Current.CurrentLayout = name
            Catch
                MsgBox(String.Format("Layout '{0}' not found", name))
            End Try
        End Sub

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 4
mpalan2009
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.

 

Thanks

Matthew

Message 4 of 4
Hallex
in reply to: mpalan2009

Delete "acTrans.Dispose" from Finally code block

and try again

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

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