Switching layouts & Windows form doesn't work

Switching layouts & Windows form doesn't work

Anonymous
Not applicable
497 Views
7 Replies
Message 1 of 8

Switching layouts & Windows form doesn't work

Anonymous
Not applicable
I am working with a plotting macro and my WindowsForm needs to activate a layout...Here is the problem. It doesn't work.

The method I am using to switch the layout is:
LayoutManager.Current.CurrentLayout() = "Layout1"

I know this works since if I have it like below without loading form it works fine:

Public Sub TestLayout()
LayoutManager.Current.CurrentLayout() = "Layout1"
End Sub

The one line of code will also work if its place inside the Form_Load event of the form i'm using...But once I place the code in any Button_Clicked event it doesn't work anymore. The drawing stays in Model space and a prompt says it regening layout...The code you can try is below:


Public Sub TestLayout()
Dim frm As New Form1
frm.Show()
End Sub

Imports Autodesk.AutoCAD.DatabaseServices
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
LayoutManager.Current.CurrentLayout() = "Layout1"
End Sub
End Class
0 Likes
498 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
CurrentLayout()?

LayoutManager.CurrentLayout is a property of String type, not a method.
Remove the bracket from your code.


wrote in message news:5779159@discussion.autodesk.com...
I am working with a plotting macro and my WindowsForm needs to activate a
layout...Here is the problem. It doesn't work.

The method I am using to switch the layout is:
LayoutManager.Current.CurrentLayout() = "Layout1"

I know this works since if I have it like below without loading form it
works fine:

Public Sub TestLayout()
LayoutManager.Current.CurrentLayout() = "Layout1"
End Sub

The one line of code will also work if its place inside the Form_Load event
of the form i'm using...But once I place the code in any Button_Clicked
event it doesn't work anymore. The drawing stays in Model space and a prompt
says it regening layout...The code you can try is below:


Public Sub TestLayout()
Dim frm As New Form1
frm.Show()
End Sub

Imports Autodesk.AutoCAD.DatabaseServices
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
LayoutManager.Current.CurrentLayout() = "Layout1"
End Sub
End Class
0 Likes
Message 3 of 8

Anonymous
Not applicable
Thanks for the suggestion. I added the parenthesis' because of the way the object browser lists the property.

Removed it and it still doesn't work. The code with the parenthesis actually works just not in the button clicked event of the form....

Thanks.
0 Likes
Message 4 of 8

Anonymous
Not applicable
Try this instead, it was working for me in A2008

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim Db As Database = HostApplicationServices.WorkingDatabase
Using locked As Autodesk.AutoCAD.ApplicationServices.DocumentLock = AcadApp.DocumentManager.MdiActiveDocument.LockDocument()
Using trans As Transaction = Db.TransactionManager.StartTransaction()
LayoutManager.Current.CurrentLayout = "Layout1"
ed.Regen()
trans.Commit()
End Using
End Using
End Sub
End Class

~'J'~
0 Likes
Message 5 of 8

Anonymous
Not applicable
Awesome! That worked. Added everything piece by piece. It ended up that locking the document is needed.

Thanks!
0 Likes
Message 6 of 8

Anonymous
Not applicable
Always happy to help
Cheers 🙂

~'J'~
0 Likes
Message 7 of 8

Anonymous
Not applicable
Sorry, don't you need to dispose of the lock? Or does the transaction take care of that?
0 Likes
Message 8 of 8

Anonymous
Not applicable
Good observation. You do.
0 Likes