.NET

Reply
Mentor
GeeHaa
Posts: 156
Registered: ‎04-14-2005
Message 1 of 15 (1,641 Views)

Changing Current Layout

1641 Views, 14 Replies
03-18-2010 12:02 PM
Hi,

Can anyone tell me why this code doesn't Change the current layout.

Dim acLayoutMgr As LayoutManager
acLayoutMgr = LayoutManager.Current
acLayoutMgr.CurrentLayout = "Model"

Thanks in Advance
*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 2 of 15 (1,634 Views)

Re: Changing Current Layout

03-18-2010 02:23 PM in reply to: GeeHaa
The code I have is intended to activate a newly created layout tab, and ran in a command that has to be run from the Model tab, so I had to test it to see if it would activate the model tab and it worked fine. So the problem is not the code you posted.

Perhaps it has to do with where the code is running from (ie from code in a form class), but you'll have to provide more info for anyone to help.

If the code is as it is posted (always activates the Model tab, never any other tab) then you could try setting the system variable TILEMODE to 1 and see if that works.
Dave O.                                                                  Sig-Logos32.png
*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 3 of 15 (1,634 Views)

Re: Changing Current Layout

03-18-2010 02:44 PM in reply to: GeeHaa
try adding the session flag

Autodesk.AutoCAD.Runtime.CommandMethod("CommandName", Autodesk.AutoCAD.Runtime.CommandFlags.Session)
---------------------------



(defun botsbuildbots() (botsbuildbots))
Mentor
GeeHaa
Posts: 156
Registered: ‎04-14-2005
Message 4 of 15 (1,634 Views)

Re: Changing Current Layout

03-19-2010 07:16 AM in reply to: GeeHaa
Thanks for the response. I have command flags.session in there but for some reason it still doesn't change layouts. I was running it from a form so I tried putting it in the command routine,But it still doesn't change. It doesn't give an error either. Aside from the imports here is the code leading up to the change.

CommandMethod("PCL", CommandFlags.Session)
Public Sub PCL()

Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database

Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

Dim acLayoutMgr As LayoutManager
acLayoutMgr = LayoutManager.Current
acLayoutMgr.CurrentLayout = "Model"
MsgBox("Current Layout = " + acLayoutMgr.CurrentLayout)

current layout is still "Layout1"

Thanks again.
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 15 (1,634 Views)

Re: Changing Current Layout

03-19-2010 09:01 AM in reply to: GeeHaa
Use Try..Catch to find a problem easily, i.e.
{code}
Public Sub PCL()
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using doclock As DocumentLock = acDoc.LockDocument
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Try
Dim acLayoutMgr As LayoutManager
acLayoutMgr = LayoutManager.Current
acLayoutMgr.CurrentLayout = "Model"

MsgBox("Current Layout = " + acLayoutMgr.CurrentLayout)
acTrans.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message & vbCr & ex.StackTrace)
End Try

End Using
End Using
End Sub
{code}

~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Member
Brad_Hamilton
Posts: 5
Registered: ‎03-15-2010
Message 6 of 15 (1,634 Views)

Re: Changing Current Layout

03-19-2010 09:08 AM in reply to: GeeHaa
I found it rolled back if you don't commit the transaction

If you leave out the commit, the layout changes, displays the layout name, and then checking okay rolls back
Mentor
GeeHaa
Posts: 156
Registered: ‎04-14-2005
Message 7 of 15 (1,634 Views)

Re: Changing Current Layout

03-19-2010 10:05 AM in reply to: GeeHaa
Locking the document did the trick. It changes the layout immediately even before the commit. I'm curious though, does Using Doclock lock the document just for this transaction and release it with the end Using statement?
*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 8 of 15 (1,634 Views)

Re: Changing Current Layout

03-19-2010 10:50 AM in reply to: GeeHaa
Yes. the DocumentLock is disposed at the End Using.

You actually don't need a transaction to do this at all. You need the DocumentLock because you are running it from a form (which is why I mentioned form code earlier), but my code works fine without either a transaction or a DocumentLock, running from a CommandMethod in a Module.
Dave O.                                                                  Sig-Logos32.png
Active Contributor
tahmad
Posts: 32
Registered: ‎09-12-2006
Message 9 of 15 (1,114 Views)

Re: Changing Current Layout

12-06-2011 08:00 AM in reply to: GeeHaa

Hi,

 

I still cannot understand the solution, i tried in many ways but it couldnt work. Can you please clarify much more

 

Thanks,

 

Tamer Mourad

Valued Mentor
fieldguy
Posts: 379
Registered: ‎03-31-2005
Message 10 of 15 (1,111 Views)

Re: Changing Current Layout

12-06-2011 08:45 AM in reply to: tahmad

Show us what you have so far.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!