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

TabOrder Help

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
mgorecki
576 Views, 8 Replies

TabOrder Help

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

8 REPLIES 8
Message 2 of 9
jeff
in reply to: mgorecki
Message 3 of 9
norman.yuan
in reply to: mgorecki

Message 4 of 9
mgorecki
in reply to: jeff

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

Message 5 of 9
mgorecki
in reply to: norman.yuan

Hello Norman,

Thank you for the post.  I've added it to My Favorites as a place to check often.

 

mark

Message 6 of 9
mgorecki
in reply to: jeff

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

Message 7 of 9
mgorecki
in reply to: mgorecki

I'm also looking into the LayoutDictionary approach, but I don't understand it completely.  Still doing research.

Message 8 of 9
Artvegas
in reply to: mgorecki

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

Message 9 of 9
mgorecki
in reply to: Artvegas

HI Art,

Thank you for the help.  That did the trick.

 

Best regards,

Mark

 

 

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