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

Changing Current Layout

14 REPLIES 14
Reply
Message 1 of 15
GeeHaa
5661 Views, 14 Replies

Changing Current Layout

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
14 REPLIES 14
Message 2 of 15
chiefbraincloud
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
Message 3 of 15
arcticad
in reply to: GeeHaa

try adding the session flag

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



(defun botsbuildbots() (botsbuildbots))
Message 4 of 15
GeeHaa
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.
Message 5 of 15
Hallex
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
Message 6 of 15
Brad_Hamilton
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
Message 7 of 15
GeeHaa
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?
Message 8 of 15
chiefbraincloud
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
Message 9 of 15
tahmad
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

Message 10 of 15
fieldguy
in reply to: tahmad

Show us what you have so far.

Message 11 of 15
tahmad
in reply to: fieldguy

Here it is

 

<CommandMethod("t13")>

 

PublicSubT13()

 

'Change the drawing Number

MsgBox("Please place all the sheet under the this path C:\x and create an empty folder under the C:\1 that drawings will be placed in")

 

Dim direc AsString = "C:\x"Dim filecount AsInteger = System.IO.Directory.GetFiles(direc, "*.dwg").Length

 

Dim arrfile() AsString = System.IO.Directory.GetFiles(direc, "*.dwg")

 

Dim val AsInteger = InputBox("Please Enter the value you want to add to the text")

 

Dim adedo AsEditor = Application.DocumentManager.MdiActiveDocument.Editor

 

 

 

Try

Dim i AsInteger= 0

 

For i = 0 To filecount - 1

 

Dim currentFile AsString= arrfile(i)

 

Dim doc AsDocument = Application.DocumentManager.Open(currentFile, False)

 

Dim db AsDatabase= doc.Database

 

 

 

Dim newfil AsString= Replace(currentFile, Mid(Right(currentFile, 7), 1, 3), Mid(Right(currentFile, 7), 1, 3) + val)

newfil = Replace(newfil,

"C:\x\", "C:\1\")

 

 

Dim doclock AsDocumentLock= doc.LockDocument

 

Usingdoclock

 

Dim trans AsTransaction= db.TransactionManager.StartTransaction()

 

Using(trans)

 

Dim ly1 AsLayoutManager = LayoutManager.Current

 

LayoutManager.Current.CurrentLayout = "Layout1"

 

trans.Commit()

EndUsingEndUsing

doc.Database.SaveAs(newfil,

True, DwgVersion.Current, doc.Database.SecurityParameters)

doc.CloseAndDiscard()

Next

 

Catch ex As Autodesk.AutoCAD.Runtime.Exception

MsgBox(ex.Message & vbLf & ex.StackTrace)

 

Finally

MsgBox("Done")

 

EndTry

EndSub

Message 12 of 15
fieldguy
in reply to: tahmad

I assume you have this working from the posts here and in the other thread. Unless there is more to this, you don't need the database or a transaction.  You also don't need an editor that I can see.  This will do nothing if layout1 does not exist.

 

Using doclock

 LayoutManager.Current.CurrentLayout = "Layout1"

End Using

 

If you do need the editor, declare it after you open the currentfile, like "dim adedo as editor = doc.editor".

 

Command flags session is described in the developers guide - a good page to bookmark.  (http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a919382...)

 

If you have to do more batch file processing do a google search for the openfiledialog class. 

Message 13 of 15
tahmad
in reply to: fieldguy

Hi,

 

I do need the editor and transaction for the rest of the program, however when i added this line next to the command method it worked

 

Autodesk.AutoCAD.Runtime.

CommandFlags.Session

 

Do you have any idea what does this line do?

By the way the hyperlink you attached is linking to something out of what i am asking for. R u sure from this bookmark

 

Thanks,

 

Tamer Mourad

Message 14 of 15
fieldguy
in reply to: tahmad

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html

 

There is lots of help available on the internet.  The main idea is to search first.

Message 15 of 15
tahmad
in reply to: tahmad

Thanks

 

 

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