Valued Contributor
Posts: 90
Registered: ‎11-13-2006
Message 1 of 4 (363 Views)
Accepted Solution

Set page setup current

363 Views, 3 Replies
02-25-2013 12:14 PM

I have existing .NET code that adds page setups to drawings.  I now wanted to set the newly added page setup as "current" within the drawing. 


The "manual" way to do what I am asking is by clicking the "Set Current" button from within the Page Setup Manager dialog.  How would I do this programmatically?




Active Member
Posts: 9
Registered: ‎06-13-2003
Message 2 of 4 (326 Views)

Re: Set page setup current

02-26-2013 02:07 PM in reply to: spanqy

Here is something similar to what I have done in the past.


Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.PlottingServices

' Assigns a page setup to a layout
<CommandMethod("AssignPageSetupToLayout")> _
Public Shared Sub AssignPageSetupToLayout()
    ' Get the current document and database, and start a transaction
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acCurDb As Database = acDoc.Database

    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
        ' Reference the Layout Manager
        Dim acLayoutMgr As LayoutManager = LayoutManager.Current

        ' Get the current layout and output its name in the Command Line window
        Dim acLayout As Layout = _
            acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _

        Dim acPlSet As DBDictionary = _
            acTrans.GetObject(acCurDb.PlotSettingsDictionaryId, OpenMode.ForRead)

        ' Check to see if the page setup exists
        If acPlSet.Contains("MyPageSetup") = True Then
            Dim plSet As PlotSettings = _

            ' Update the layout

            ' Save the new objects to the database
            ' Ignore the changes made
        End If
    End Using

    ' Update the display
End Sub


Valued Contributor
Posts: 90
Registered: ‎11-13-2006
Message 3 of 4 (321 Views)

Re: Set page setup current

02-26-2013 03:28 PM in reply to: spanqy

Works great!


I only had to add another using statement like this to lock the document:


Using dl as DocumentLock = dwg.LockDocument

End Using

 I think this is becuase I run in batch mode using:

    <CommandMethod("MYCOMMAND", CommandFlags.Session)>


Thanks a lot!





Active Member
Posts: 9
Registered: ‎06-13-2003
Message 4 of 4 (316 Views)

Re: Set page setup current

02-26-2013 03:44 PM in reply to: spanqy

Glad it helped and you were able to adapt it to your particular situation.

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.