.NET

Reply
Contributor
Human.Man.Name=Jose
Posts: 11
Registered: ‎01-05-2007
Message 1 of 2 (311 Views)

Drawing extents in Paperspace

311 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.

Thanks,
Jose.

Public Sub CheckMedia(ByVal Printers As Collection)
Try
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
'Autodesk.AutoCAD.DatabaseServices.Entity()
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)
'Application.ShowAlertDialog(Printers.Count)
Dim Count As Integer = 0
For Each oPlotterConfig As Acco.PlotterConfig In Printers
Try
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
Next
Catch ex As Exception
'Application.ShowAlertDialog(ex.TargetSite.Name)
Application.ShowAlertDialog(ex.Data)
End Try
Next
oEditor.WriteMessage("Number of PageSetups Available" + Count.ToString)
Catch ex As Exception
'Application.ShowAlertDialog(ex.TargetSite.Name)
Application.ShowAlertDialog(ex.Data)
End Try
'CheckMedia = Printers
End Sub
Distinguished Contributor
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 2 of 2 (245 Views)

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) {
        return;
    }

    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) {
                       extents.AddExtents(ent.GeometricExtents);
                  }
             }
        }

        // 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));
        extents.AddExtents(limits);

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

        tr.Commit();
    }
}

 

Hope this helps.
Art

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

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