Exemplo n.º 1
0
        // This method helps to get correct "boundary box" for the regions which
        // created through the splines. Written by Alexander Rivilis.
        public static void GetVisualBoundary(this Db.Region region, double delta,
                                             ref Gm.Point2d minPoint, ref Gm.Point2d maxPoint)
        {
            using (Gm.BoundBlock3d boundBlk = new Gm.BoundBlock3d())
            {
                using (Br.Brep brep = new Br.Brep(region))
                {
                    foreach (Br.Edge edge in brep.Edges)
                    {
                        using (Gm.Curve3d curve = edge.Curve)
                        {
                            Gm.ExternalCurve3d curve3d = curve as Gm.ExternalCurve3d;

                            if (curve3d != null && curve3d.IsNurbCurve)
                            {
                                using (Gm.NurbCurve3d nurbCurve = curve3d.NativeCurve
                                                                  as Gm.NurbCurve3d)
                                {
                                    Gm.Interval interval = nurbCurve.GetInterval();
                                    for (double par = interval.LowerBound; par <=
                                         interval.UpperBound; par += (delta * 2.0))
                                    {
                                        Gm.Point3d p = nurbCurve.EvaluatePoint(par);
                                        if (!boundBlk.IsBox)
                                        {
                                            boundBlk.Set(p, p);
                                        }
                                        else
                                        {
                                            boundBlk.Extend(p);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (!boundBlk.IsBox)
                                {
                                    boundBlk.Set(edge.BoundBlock.GetMinimumPoint(),
                                                 edge.BoundBlock.GetMaximumPoint());
                                }
                                else
                                {
                                    boundBlk.Extend(edge.BoundBlock.GetMinimumPoint());
                                    boundBlk.Extend(edge.BoundBlock.GetMaximumPoint());
                                }
                            }
                        }
                    }
                }
                boundBlk.Swell(delta);

                minPoint = new Gm.Point2d(boundBlk.GetMinimumPoint().X,
                                          boundBlk.GetMinimumPoint().Y);
                maxPoint = new Gm.Point2d(boundBlk.GetMaximumPoint().X,
                                          boundBlk.GetMaximumPoint().Y);
            }
        }
Exemplo n.º 2
0
        public static ACADDB.Region CompareResultsofRegion(ACADDB.Region region1, ACADDB.Region region2)
        {
            var outterRegion = region1;
            var innerRegion  = region2;

            if (outterRegion.Area > innerRegion.Area)

            {
                outterRegion.BooleanOperation(ACADDB.BooleanOperationType.BoolSubtract, innerRegion);
                innerRegion.Dispose();
            }
            return(null);
        }
Exemplo n.º 3
0
        public static ACADDB.Region AddRegion(ACADDB.ObjectId acadObjectId)
        {
            ACADDB.Region returnvalue = null;
            // Get the current document and database
            Document acDoc = Application.DocumentManager.MdiActiveDocument;

            ACADDB.Database acCurDb = acDoc.Database;

            // Start a transaction
            using (ACADDB.Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                ACADDB.BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             ACADDB.OpenMode.ForRead) as ACADDB.BlockTable;

                // Open the Block table record Model space for write
                ACADDB.BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[ACADDB.BlockTableRecord.ModelSpace],
                                                ACADDB.OpenMode.ForWrite) as ACADDB.BlockTableRecord;

                ACADDB.Polyline polyline = acTrans.GetObject(acadObjectId,
                                                             ACADDB.OpenMode.ForRead) as ACADDB.Polyline;
                if (polyline != null)

                {
                    ACADDB.DBObjectCollection acDBObjColl = new ACADDB.DBObjectCollection();
                    acDBObjColl.Add((ACADDB.DBObject)polyline.AcadObject);

                    // Calculate the regions based on each closed loop
                    ACADDB.DBObjectCollection myRegionColl = new ACADDB.DBObjectCollection();
                    myRegionColl = ACADDB.Region.CreateFromCurves(acDBObjColl);
                    ACADDB.Region acRegion = myRegionColl[0] as ACADDB.Region;
                    returnvalue = acRegion;
                    // Add the new object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(acRegion);
                    acTrans.AddNewlyCreatedDBObject(acRegion, true);

                    // Dispose
                }

                // Save the new object to the database
                acTrans.Commit();
            }
            return(returnvalue);
        }
Exemplo n.º 4
0
        public static ObjectId CreateFromCurve(Curve poly)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                BlockTable acBlkTbl;
                acBlkTbl = tr.GetObject(doc.Database.BlockTableId,
                                        OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                           OpenMode.ForWrite) as BlockTableRecord;


                //Curve poly = tr.GetObject(polyId, OpenMode.ForRead) as Curve;
                DBObjectCollection objColl = new DBObjectCollection();
                objColl.Add(poly);

                DBObjectCollection myRegionColl = new DBObjectCollection();
                Autodesk.AutoCAD.DatabaseServices.Region objreg = new Autodesk.AutoCAD.DatabaseServices.Region();
                DBObjectCollection objRegions = new DBObjectCollection();
                try
                {
                    objRegions = Autodesk.AutoCAD.DatabaseServices.Region.CreateFromCurves(objColl);
                    objreg     = objRegions[0] as Autodesk.AutoCAD.DatabaseServices.Region;

                    acBlkTblRec.AppendEntity(objreg);
                    tr.AddNewlyCreatedDBObject(objreg, true);
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    // eInvalidInput exception
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Error: unable to create region collection:\n" + ex.Message);
                }

                tr.Commit();
                return(objreg.ObjectId);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 检查 pl 是否包含 jmdPL
        /// </summary>
        /// <param name="pl"></param>
        /// <param name="jmdPL"></param>
        /// <returns></returns>
        public static bool CheckPLContains(Polyline pl, Polyline jmdPL)
        {
            if (pl == jmdPL)
            {
                return(false);
            }
            Autodesk.AutoCAD.DatabaseServices.Region plRegion = CreateRegion(pl);
            Region re = CADUtils.CreateRegion(jmdPL);

            if (re != null && re.Area != 0)
            {
                double area = plRegion.Area;
                if (plRegion.Area == 0)
                {
                    return(false);
                }
                try
                {
                    plRegion.BooleanOperation(BooleanOperationType.BoolUnite, re);
                }
                catch
                {
                    return(false);
                }

                if (plRegion.Area < area + 0.1)
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        public static DBObject Create(this Grevit.Types.Slab s, Transaction tr)
        {
            try
            {
                BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                // Polyline acPoly = new Polyline();
                //acPoly.SetDatabaseDefaults();

                //int i = 0;

                DBObjectCollection objColl = new DBObjectCollection();
                Point3dCollection ptcol = new Point3dCollection();
                foreach (Grevit.Types.Loop loop in s.surface.profile)
                {
                    foreach (Grevit.Types.Component p in loop.outline)
                        ptcol = p.To3dPointCollection();


                    //Curve3dCollection collt = parse3dCurve(p);
                    //acPoly.AppendVertex(new PolylineVertex3d(new Point3d(p.x, p.y, p.z)));
                    //acPoly.AddVertexAt(i, new Point2d(p.x, p.y), 0, 0, 0);
                    //i++;

                    //foreach (Curve3d curve in collt)
                    //{ 
                    //    objColl.Add(Autodesk.AutoCAD.DatabaseServices.Curve.CreateFromGeCurve(curve));
                    //}
                }

                Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, ptcol, true);
                objColl.Add(face);
                //Polyline3d face = new Polyline3d();
                //ETC...
                // or from your settings
                // Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, vertices, true);





                DBObjectCollection myRegionColl = new DBObjectCollection();
                // create a single region
                Autodesk.AutoCAD.DatabaseServices.Region objreg = new Autodesk.AutoCAD.DatabaseServices.Region();
                DBObjectCollection objRegions = new DBObjectCollection();
                try
                {
                    objRegions = Autodesk.AutoCAD.DatabaseServices.Region.CreateFromCurves(objColl);
                    objreg = objRegions[0] as Autodesk.AutoCAD.DatabaseServices.Region;

                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    // eInvalidInput exception
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Error: unable to create region collection:\n" + ex.Message);

                }






                //acPoly.Closed = true;
                //ms.AppendEntity(acPoly);
                //tr.AddNewlyCreatedDBObject(acPoly, true);

                //atrix3d mm = Matrix3d.Displacement(new Vector3d(0, 0, r.outline[0].z));
                //acPoly.TransformBy(mm);


                //Autodesk.Aec.Geometry.Profile myProfile = Autodesk.Aec.Geometry.Profile.CreateFromEntity(acPoly, ed.CurrentUserCoordinateSystem);

                //Slab slab = new Slab();
                //slab.SetDatabaseDefaults(db);
                //slab.SetToStandard(db);         
                //slab.Location = new Point3d(0, 0, 0);

                //slab.SetBaseProfile(myProfile, Matrix3d.Identity);

                //DBObjectCollection col = acPoly.GetOffsetCurves(0);


                //DBObjectCollection res = Region.CreateFromCurves(coll);

                //Region reg = res[0] as Region;

                Solid3d solid = new Solid3d();
                solid.Extrude(objreg, s.height, s.slope);


                LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);
                if (s.TypeOrLayer != "") { if (lt.Has(s.TypeOrLayer)) solid.LayerId = lt[s.TypeOrLayer]; }
                //if (ss.Has(r.family, tr)) slab.StyleId = ss.GetAt(r.family);


                ms.AppendEntity(solid);
                tr.AddNewlyCreatedDBObject(solid, true);
                return solid;
            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
            }

            return null;
        }
        // TODO: Port of existing code, requires refactoring immininently
        public void EstimateFFLFromSurface(CivSurface proposed)
        {
            Document acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                DBObject obj = acTrans.GetObject(this.BaseObject, OpenMode.ForWrite);

                //Need to add the temp line to create feature line from it
                BlockTable       acBlkTbl    = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec =
                    acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                ObjectId    perimId = FeatureLine.Create("plot" + PlotId, obj.ObjectId);
                FeatureLine perim   = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;
                perim.AssignElevationsFromSurface(proposed.Id, false);
                var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint);

                // TODO: Move to settings
                double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15;

                // TODO: Move to generation code
                //Ad the FFL Label
                // Create a multiline text object
                using (MText acMText = new MText())
                {
                    Solid3d            Solid = new Solid3d();
                    DBObjectCollection coll  = new DBObjectCollection();
                    coll.Add(obj);
                    Solid.Extrude(((Region)Region.CreateFromCurves(coll)[0]), 1, 0);
                    Point3d centroid = new Point3d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y, 0);
                    Solid.Dispose();

                    acMText.Location = centroid;
                    acMText.Contents = "FFL = " + FinishedFloorLevel.ToString("F3");

                    //acMText.Rotation = Rotation;
                    acMText.Height     = 8;
                    acMText.Attachment = AttachmentPoint.MiddleCenter;

                    acBlkTblRec.AppendEntity(acMText);
                    acTrans.AddNewlyCreatedDBObject(acMText, true);
                }

                // TODO: Move to generation code
                foreach (Point3d p in points)
                {
                    using (MText acMText = new MText())
                    {
                        Point3d insert = new Point3d(p.X, p.Y, 0);
                        acMText.Location = insert;

                        //Number of course
                        int courses = (int)Math.Ceiling((double)(((FinishedFloorLevel - 0.15f - p.Z) / 0.075f)));

                        if (courses > 0)
                        {
                            acMText.Contents   = courses + " Courses";
                            acMText.Height     = 4;
                            acMText.Attachment = AttachmentPoint.TopRight;

                            acBlkTblRec.AppendEntity(acMText);
                            acTrans.AddNewlyCreatedDBObject(acMText, true);
                        }
                    }
                }

                //perim.Erase();
                //obj.Erase();
                acTrans.Commit();
            }
        }
Exemplo n.º 8
0
        public static DBObject Create(this Grevit.Types.Slab s, Transaction tr)
        {
            try
            {
                BlockTable       bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                // Polyline acPoly = new Polyline();
                //acPoly.SetDatabaseDefaults();

                //int i = 0;

                DBObjectCollection objColl = new DBObjectCollection();
                Point3dCollection  ptcol   = new Point3dCollection();
                foreach (Grevit.Types.Loop loop in s.surface.profile)
                {
                    foreach (Grevit.Types.Component p in loop.outline)
                    {
                        ptcol = p.To3dPointCollection();
                    }


                    //Curve3dCollection collt = parse3dCurve(p);
                    //acPoly.AppendVertex(new PolylineVertex3d(new Point3d(p.x, p.y, p.z)));
                    //acPoly.AddVertexAt(i, new Point2d(p.x, p.y), 0, 0, 0);
                    //i++;

                    //foreach (Curve3d curve in collt)
                    //{
                    //    objColl.Add(Autodesk.AutoCAD.DatabaseServices.Curve.CreateFromGeCurve(curve));
                    //}
                }

                Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, ptcol, true);
                objColl.Add(face);
                //Polyline3d face = new Polyline3d();
                //ETC...
                // or from your settings
                // Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, vertices, true);



                DBObjectCollection myRegionColl = new DBObjectCollection();
                // create a single region
                Autodesk.AutoCAD.DatabaseServices.Region objreg = new Autodesk.AutoCAD.DatabaseServices.Region();
                DBObjectCollection objRegions = new DBObjectCollection();
                try
                {
                    objRegions = Autodesk.AutoCAD.DatabaseServices.Region.CreateFromCurves(objColl);
                    objreg     = objRegions[0] as Autodesk.AutoCAD.DatabaseServices.Region;
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    // eInvalidInput exception
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Error: unable to create region collection:\n" + ex.Message);
                }



                //acPoly.Closed = true;
                //ms.AppendEntity(acPoly);
                //tr.AddNewlyCreatedDBObject(acPoly, true);

                //atrix3d mm = Matrix3d.Displacement(new Vector3d(0, 0, r.outline[0].z));
                //acPoly.TransformBy(mm);


                //Autodesk.Aec.Geometry.Profile myProfile = Autodesk.Aec.Geometry.Profile.CreateFromEntity(acPoly, ed.CurrentUserCoordinateSystem);

                //Slab slab = new Slab();
                //slab.SetDatabaseDefaults(db);
                //slab.SetToStandard(db);
                //slab.Location = new Point3d(0, 0, 0);

                //slab.SetBaseProfile(myProfile, Matrix3d.Identity);

                //DBObjectCollection col = acPoly.GetOffsetCurves(0);


                //DBObjectCollection res = Region.CreateFromCurves(coll);

                //Region reg = res[0] as Region;

                Solid3d solid = new Solid3d();
                solid.Extrude(objreg, s.height, s.slope);


                LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);
                if (s.TypeOrLayer != "")
                {
                    if (lt.Has(s.TypeOrLayer))
                    {
                        solid.LayerId = lt[s.TypeOrLayer];
                    }
                }
                //if (ss.Has(r.family, tr)) slab.StyleId = ss.GetAt(r.family);


                ms.AppendEntity(solid);
                tr.AddNewlyCreatedDBObject(solid, true);
                return(solid);
            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
            }

            return(null);
        }
Exemplo n.º 9
0
        // This code based on Kean Walmsley's article:
        // http://through-the-interface.typepad.com/through_the_interface/2007/10/plotting-a-wind.html
        public static void PlotRegion(Db.ObjectId regionId, String pcsFileName,
                                      String mediaName, String outputFileName)
        {
            if (regionId.IsNull)
            {
                throw new ArgumentException("regionId.IsNull == true");
            }
            if (!regionId.IsValid)
            {
                throw new ArgumentException("regionId.IsValid == false");
            }

            if (regionId.ObjectClass.Name != "AcDbRegion")
            {
                throw new ArgumentException("regionId.ObjectClass.Name != AcDbRegion");
            }

            if (pcsFileName == null)
            {
                throw new ArgumentNullException("pcsFileName");
            }
            if (pcsFileName.Trim() == String.Empty)
            {
                throw new ArgumentException("pcsFileName.Trim() == String.Empty");
            }

            if (mediaName == null)
            {
                throw new ArgumentNullException("mediaName");
            }
            if (mediaName.Trim() == String.Empty)
            {
                throw new ArgumentException("mediaName.Trim() == String.Empty");
            }

            if (outputFileName == null)
            {
                throw new ArgumentNullException("outputFileName");
            }
            if (outputFileName.Trim() == String.Empty)
            {
                throw new ArgumentException("outputFileName.Trim() == String.Empty");
            }

            Db.Database previewDb = Hs.WorkingDatabase;
            Db.Database db        = null;
            Ap.Document doc       = cad.DocumentManager.MdiActiveDocument;
            if (doc == null || doc.IsDisposed)
            {
                return;
            }

            Ed.Editor ed = doc.Editor;
            try
            {
                if (regionId.Database != null && !regionId.Database.IsDisposed)
                {
                    Hs.WorkingDatabase = regionId.Database;
                    db = regionId.Database;
                }
                else
                {
                    db = doc.Database;
                }

                using (doc.LockDocument())
                {
                    using (Db.Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        Db.Region region = tr.GetObject(regionId,
                                                        Db.OpenMode.ForRead) as Db.Region;

                        Db.Extents3d        extends = region.GeometricExtents;
                        Db.ObjectId         modelId = Us.GetBlockModelSpaceId(db);
                        Db.BlockTableRecord model   = tr.GetObject(modelId,
                                                                   Db.OpenMode.ForRead) as Db.BlockTableRecord;

                        Db.Layout layout = tr.GetObject(model.LayoutId,
                                                        Db.OpenMode.ForRead) as Db.Layout;

                        using (Pt.PlotInfo pi = new Pt.PlotInfo())
                        {
                            pi.Layout = model.LayoutId;

                            using (Db.PlotSettings ps = new Db.PlotSettings(layout.ModelType)
                                   )
                            {
                                ps.CopyFrom(layout);

                                Db.PlotSettingsValidator psv = Db.PlotSettingsValidator
                                                               .Current;

                                Gm.Point2d bottomLeft = Gm.Point2d.Origin;
                                Gm.Point2d topRight   = Gm.Point2d.Origin;

                                region.GetVisualBoundary(0.1, ref bottomLeft,
                                                         ref topRight);

                                Gm.Point3d bottomLeft_3d = new Gm.Point3d(bottomLeft.X,
                                                                          bottomLeft.Y, 0);
                                Gm.Point3d topRight_3d = new Gm.Point3d(topRight.X, topRight.Y,
                                                                        0);

                                Db.ResultBuffer rbFrom = new Db.ResultBuffer(new Db.TypedValue(
                                                                                 5003, 1));
                                Db.ResultBuffer rbTo = new Db.ResultBuffer(new Db.TypedValue(
                                                                               5003, 2));

                                double[] firres = new double[] { 0, 0, 0 };
                                double[] secres = new double[] { 0, 0, 0 };

                                acedTrans(bottomLeft_3d.ToArray(), rbFrom.UnmanagedObject,
                                          rbTo.UnmanagedObject, 0, firres);
                                acedTrans(topRight_3d.ToArray(), rbFrom.UnmanagedObject,
                                          rbTo.UnmanagedObject, 0, secres);

                                Db.Extents2d extents = new Db.Extents2d(
                                    firres[0],
                                    firres[1],
                                    secres[0],
                                    secres[1]
                                    );

                                psv.SetZoomToPaperOnUpdate(ps, true);

                                psv.SetPlotWindowArea(ps, extents);
                                psv.SetPlotType(ps, Db.PlotType.Window);
                                psv.SetUseStandardScale(ps, true);
                                psv.SetStdScaleType(ps, Db.StdScaleType.ScaleToFit);
                                psv.SetPlotCentered(ps, true);
                                psv.SetPlotRotation(ps, Db.PlotRotation.Degrees000);

                                // We'll use the standard DWF PC3, as
                                // for today we're just plotting to file
                                psv.SetPlotConfigurationName(ps, pcsFileName, mediaName);

                                // We need to link the PlotInfo to the
                                // PlotSettings and then validate it
                                pi.OverrideSettings = ps;
                                Pt.PlotInfoValidator piv = new Pt.PlotInfoValidator();
                                piv.MediaMatchingPolicy = Pt.MatchingPolicy.MatchEnabled;
                                piv.Validate(pi);

                                // A PlotEngine does the actual plotting
                                // (can also create one for Preview)
                                if (Pt.PlotFactory.ProcessPlotState == Pt.ProcessPlotState
                                    .NotPlotting)
                                {
                                    using (Pt.PlotEngine pe = Pt.PlotFactory.CreatePublishEngine()
                                           )
                                    {
                                        // Create a Progress Dialog to provide info
                                        // and allow thej user to cancel

                                        using (Pt.PlotProgressDialog ppd =
                                                   new Pt.PlotProgressDialog(false, 1, true))
                                        {
                                            ppd.set_PlotMsgString(
                                                Pt.PlotMessageIndex.DialogTitle, "Custom Plot Progress");

                                            ppd.set_PlotMsgString(
                                                Pt.PlotMessageIndex.CancelJobButtonMessage,
                                                "Cancel Job");

                                            ppd.set_PlotMsgString(
                                                Pt.PlotMessageIndex.CancelSheetButtonMessage,
                                                "Cancel Sheet");

                                            ppd.set_PlotMsgString(
                                                Pt.PlotMessageIndex.SheetSetProgressCaption,
                                                "Sheet Set Progress");

                                            ppd.set_PlotMsgString(
                                                Pt.PlotMessageIndex.SheetProgressCaption,
                                                "Sheet Progress");

                                            ppd.LowerPlotProgressRange = 0;
                                            ppd.UpperPlotProgressRange = 100;
                                            ppd.PlotProgressPos        = 0;

                                            // Let's start the plot, at last
                                            ppd.OnBeginPlot();
                                            ppd.IsVisible = true;
                                            pe.BeginPlot(ppd, null);

                                            // We'll be plotting a single document
                                            pe.BeginDocument(pi, doc.Name, null, 1, true,
                                                             // Let's plot to file
                                                             outputFileName);
                                            // Which contains a single sheet
                                            ppd.OnBeginSheet();
                                            ppd.LowerSheetProgressRange = 0;
                                            ppd.UpperSheetProgressRange = 100;
                                            ppd.SheetProgressPos        = 0;
                                            Pt.PlotPageInfo ppi = new Pt.PlotPageInfo();
                                            pe.BeginPage(ppi, pi, true, null);
                                            pe.BeginGenerateGraphics(null);
                                            pe.EndGenerateGraphics(null);

                                            // Finish the sheet
                                            pe.EndPage(null);
                                            ppd.SheetProgressPos = 100;
                                            ppd.OnEndSheet();

                                            // Finish the document
                                            pe.EndDocument(null);

                                            // And finish the plot
                                            ppd.PlotProgressPos = 100;
                                            ppd.OnEndPlot();
                                            pe.EndPlot(null);
                                        }
                                    }
                                }
                                else
                                {
                                    ed.WriteMessage("\nAnother plot is in progress.");
                                }
                            }
                        }
                        tr.Commit();
                    }
                }
            }
            finally
            {
                Hs.WorkingDatabase = previewDb;
            }
        }