11 Posts
0 Kudos
Registered: ‎01-05-2007
Post 1 of 2

Drawing extents in Paperspace

352 Views, 1 Replies
01-18-2007 03:34 PM
Hello Everyone,
I'm a little lost with this one. I am able to get the drawing extents in the database but just fine except that when I draw objects in paperspace and the extents decrease the properties Pextmax and Pextmin do not change accordingly. When I make objects larger everything is fine, I capture the change just fine. Can anyone tell where else to look or if there is a method to update this properly? Any comments will be greatly appreciated.


Public Sub CheckMedia(ByVal Printers As Collection)
Dim oEditor As Autodesk.AutoCAD.EditorInput.Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim oDatabase As Autodesk.AutoCAD.DatabaseServices.Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Dim objMedia As New Acco.Media
objMedia.PageSize_x = (oDatabase.Pextmax.X - oDatabase.Pextmin.X)
objMedia.PageSize_y = (oDatabase.Pextmax.Y - oDatabase.Pextmin.Y)
Application.ShowAlertDialog(objMedia.PageSize_x.ToString + "," + objMedia.PageSize_y.ToString)
Dim Count As Integer = 0
For Each oPlotterConfig As Acco.PlotterConfig In Printers
For Each oMedia As Acco.Media In oPlotterConfig.CanonicalMedia
oMedia.PageSize_x = Decimal.ToDouble(oMedia.PageSize_x) / 25.4
oMedia.PageSize_y = Decimal.ToDouble(oMedia.PageSize_y) / 25.4
oMedia.PageSize_x = Decimal.Round(oMedia.PageSize_x, 1)
oMedia.PageSize_y = Decimal.Round(oMedia.PageSize_y, 1)
oEditor.WriteMessage(oMedia.MediaName + " has been processed" + vbNewLine)
'Application.ShowAlertDialog("numbers rounded")
If Not oMedia.PageSize_x >= objMedia.PageSize_x And oMedia.PageSize_x <= objMedia.PageSize_x + 25.4 And oMedia.PageSize_y >= objMedia.PageSize_y And oMedia.PageSize_y <= objMedia.PageSize_y + 25.4 Then
oMedia.ApplytoLayout = True
'Application.ShowAlertDialog(oMedia.MediaName + " fits")
oEditor.WriteMessage(oMedia.MediaName + " " + oMedia.PageSize_x.ToString + "," + oMedia.PageSize_y.ToString + " fits" + vbNewLine)
Count += 1
End If
Catch ex As Exception
End Try
oEditor.WriteMessage("Number of PageSetups Available" + Count.ToString)
Catch ex As Exception
End Try
'CheckMedia = Printers
End Sub
Distinguished Contributor
104 Posts
11 Kudos
Registered: ‎04-21-2011
Post 2 of 2

Re: Drawing extents in Paperspace

10-03-2011 11:34 PM in reply to: Human.Man.Name=Jose

Hi Jose,


As you are probably aware, the Database.UpdateExt() method only seems to update the Extmin and Extmax properties for model space.


I have two suggestions.


1. If you switch to another layout (e.g. the Model tab) and then back to the paper space layout, the Database.Pextmin and
    Database.Pextmax properties will be updated correctly. So in C# you could do something like this:

        db.TileMode = !db.TileMode;
        db.TileMode = !db.TileMode;


2. Below is a C# helper method that I created to update Pextmin and Pextmax for the currently selected paper space layout tab.

public static void UpdatePSpaceExts() {

    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    // Check current layout is a paper space layout.
    if (db.TileMode == true) {

    using (Transaction tr = db.TransactionManager.StartTransaction()) {

        // Current paper space BlockTableRecord.
        BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as BlockTableRecord;


        // Current paper space Layout.
        Layout layout = tr.GetObject(btr.LayoutId, OpenMode.ForRead) as Layout;


        // Main paper space area Viewport ObjectId.
        // # Note: First ObjectId from GetViewports() is the main paper space area Viewport ObjectId.
        ObjectId mainPSpaceVportId = layout.GetViewports()[0];


        // Create Extents3d based on BlockTableRecord entities.
        // # Note: Exclude main paper space viewport ObjectId.
        Extents3d extents = new Extents3d();
        foreach (ObjectId id in btr) {
             if (id != mainPSpaceVportId) {
                  Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;
                  if (ent != null) {

        // Create Extents3d based on paper space layout limits.
        Extents3d limits = new Extents3d(
             new Point3d(layout.Limits.MinPoint.X, layout.Limits.MinPoint.Y, 0),
             new Point3d(layout.Limits.MaxPoint.X, layout.Limits.MaxPoint.Y, 0));

        // Update Pextmin and Pextmax.
        db.Pextmin = extents.MinPoint;
        db.Pextmax = extents.MaxPoint;



Hope this helps.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!