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

Set page setup current

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
MarkSanchezSPEC
1249 Views, 3 Replies

Set page setup current

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?

 

TIA

 

3 REPLIES 3
Message 2 of 4
hyperpics
in reply to: MarkSanchezSPEC

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), _
                              OpenMode.ForRead)

        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 = _
                acPlSet.GetAt("MyPageSetup").GetObject(OpenMode.ForRead)

            ' Update the layout
            acLayout.UpgradeOpen()
            acLayout.CopyFrom(plSet)

            ' Save the new objects to the database
            acTrans.Commit()
        Else
            ' Ignore the changes made
            acTrans.Abort()
        End If
    End Using

    ' Update the display
    acDoc.Editor.Regen()
End Sub

 

Message 3 of 4

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!

 

 

 

 

Message 4 of 4
hyperpics
in reply to: MarkSanchezSPEC

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

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