Hello,
Can someone please help me out understanding the "tabOrder" for layouts.
I would like to rename my layouts "P1", "P2", "P3".... based on the taborder.
Also, I would like to copy a layout (the last layout tab) and place it at a given point (like the third tab). Once I can copy it and place it, I'll be able to rename the layout tabs using taborder.
Thanks,
Mark
Solved! Go to Solution.
Solved by mgorecki. Go to Solution.
http://forums.autodesk.com/t5/NET/Layout-Tab-list-ordered/m-p/2816844/highlight/true#M21306
This blog post might help you:
http://drive-cad-with-code.blogspot.com/2011/06/set-layout-in-order.html
Norman Yuan
Hello Jeff,
Thanks for the link. I think I saw that while looking for answers, but I saw so many things I couldn't remember where it was.
Mark
Hello Norman,
Thank you for the post. I've added it to My Favorites as a place to check often.
mark
Our drawings are created with layouts called "P1", "P2", "P3"... What I want to do is add or remove a layout entered using a form. What I have is code that will delete a specified layout, and some code that will re-name the layouts prefixed with "X"s. I rename with a prefix "X" so that if a new page 4 (for example) is added, the current page 4 will not hinder the rename process because of "same name" issues.
Here is the rename code:
Sub renamePagesWithX() ' Changes all the page numbers with a suffix "X", so the code can re-number ' the pages without running into page name duplicates Dim myDWG As Autodesk.AutoCAD.ApplicationServices.Document Dim myDB As Autodesk.AutoCAD.DatabaseServices.Database Dim myTransManForXRename As Autodesk.AutoCAD.DatabaseServices.TransactionManager Dim myTransForXRename As Transaction myDWG = DocumentManager.MdiActiveDocument myDB = myDWG.Database myTransManForXRename = myDWG.TransactionManager myTransForXRename = myTransManForXRename.StartTransaction Dim myBT As BlockTable Dim myBTR As BlockTableRecord Dim myBTE As SymbolTableEnumerator myBT = myDB.BlockTableId.GetObject(OpenMode.ForWrite) myBTE = myBT.GetEnumerator While myBTE.MoveNext myBTR = myBTE.Current.GetObject(OpenMode.ForWrite) If myBTR.IsLayout Then If Not myBTR.Name = "*Model_Space" Then Dim LayoutMgrX As LayoutManager = LayoutManager.Current Dim layoutObject As Layout = myTransForXRename.GetObject(myBTR.LayoutId, OpenMode.ForWrite) ' Get the layout's name Dim layoutName As String = layoutObject.LayoutName Dim newLayoutName As String newLayoutName = "X" & layoutName LayoutMgrX.RenameLayout(layoutName, newLayoutName) myDWG.Editor.Regen() End If End If End While myTransForXRename.Commit() myTransForXRename.Dispose() myTransManForXRename.Dispose() End Sub
Now I thought I could use similar code to rename the layouts per the tab order, but it just crashes. Here is the code:
Public Sub renamePagesUsingTabOrder() ' Now that the pages have been prefixed with an "X", the code can now change the tabs to be named ' per their tabOrder number Dim myDWG As Autodesk.AutoCAD.ApplicationServices.Document Dim myDB As Autodesk.AutoCAD.DatabaseServices.Database Dim myTransManForTabOrder As Autodesk.AutoCAD.DatabaseServices.TransactionManager Dim myTransForTabOrder As Transaction myDWG = DocumentManager.MdiActiveDocument myDB = myDWG.Database myTransManForTabOrder = myDWG.TransactionManager myTransForTabOrder = myTransManForTabOrder.StartTransaction Dim myBT As BlockTable Dim myBTR As BlockTableRecord Dim myBTE As SymbolTableEnumerator myBT = myDB.BlockTableId.GetObject(OpenMode.ForWrite) myBTE = myBT.GetEnumerator ' Go through the pages again and renumber them with the correct tab names While myBTE.MoveNext myBTR = myBTE.Current.GetObject(OpenMode.ForWrite) If myBTR.IsLayout Then If Not myBTR.Name = "*Model_Space" Then Dim LayoutMgrP As LayoutManager = LayoutManager.Current Dim layoutObject As Layout = myTransForTabOrder.GetObject(myBTR.LayoutId, OpenMode.ForWrite) ' Get the layout's name Dim layoutName As String = layoutObject.TabOrder.ToString Dim newLayoutName As String newLayoutName = "P" & layoutName LayoutMgrP.RenameLayout(layoutName, newLayoutName) End If End If End While myDWG.Editor.Regen() myTransForTabOrder.Commit() myTransForTabOrder.Dispose() myTransManForTabOrder.Dispose() End Sub
I'm sure you're going to see the issue right away, but I've looked at so many different articles and web pages that it's making my head ache. If you can help me out, I'd really appreciate it.
Thanks,
Mark
I'm also looking into the LayoutDictionary approach, but I don't understand it completely. Still doing research.
Hi Mark,
I think I see why your renamePagesUsingTabOrder() code doesn't work.
Look at this part of your code:
Dim layoutName As String = layoutObject.TabOrder.ToString
Dim newLayoutName As String
newLayoutName = "P" & layoutName
LayoutMgrP.RenameLayout(layoutName, newLayoutName)
Your layoutName string variable is set to a number (i.e. layoutObject.TabOrder.ToString). But no such layout name actually exists. So your RenameLayout() function is trying to rename a non-existant layout, hence probably the reason for your crash.
Instead why not just rename the layout directly, i.e.:
Dim layoutObject As Layout =
myTransForTabOrder.GetObject(myBTR.LayoutId, OpenMode.ForWrite)
layoutObject.Name = "P" & layoutObject.TabOrder.ToString
Hope this helps.
Art