public bool isInpolyline(Polyline pline)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DBObject       obj   = tr.GetObject(this.BaseObjectId, OpenMode.ForRead);
                BlockReference block = (BlockReference)obj;
                Extents3d      bd    = block.GeometryExtentsBestFit();
                Point3d        p1    = bd.MinPoint;
                Point3d        p2    = bd.MaxPoint;
                if (Utils.Utility.PointInPolygon(p1, pline))
                {
                    if (Utils.Utility.PointInPolygon(p2, pline))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        public List <PipeLine> SearchConnected(BaseModel model)
        {
            List <PipeLine> pipes = new List <PipeLine>();

            if (!model.BaseObjectId.IsNull)
            {
                try
                {
                    Database db = HostApplicationServices.WorkingDatabase;
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        DBObject       obj   = tr.GetObject(model.BaseObjectId, OpenMode.ForRead);
                        BlockReference block = (BlockReference)obj;

                        Extents3d bd = block.GeometryExtentsBestFit();
                        foreach (var item in PipeLines)
                        {
                            Point3d p1 = item.Value.Point(0);
                            Point3d p2 = item.Value.Point(1);
                            if (p1.X >= bd.MinPoint.X - 0.001 && p1.Y >= bd.MinPoint.Y - 0.001 && p1.X <= bd.MaxPoint.X + 0.001 && p1.Y <= bd.MaxPoint.Y + 0.001)
                            {
                                pipes.Add(item.Value);
                                continue;
                            }
                            if (p2.X >= bd.MinPoint.X - 0.001 && p2.Y >= bd.MinPoint.Y - 0.001 && p2.X <= bd.MaxPoint.X + 0.001 && p2.Y <= bd.MaxPoint.Y + 0.001)
                            {
                                pipes.Add(item.Value);
                                continue;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.Message);
                }
            }
            return(pipes);
        }
예제 #3
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 PlotOnePaper(Database db, Document doc, BlockReference br, String pcsFileName,
                                        String mediaName, String outputFileName)
        {
            ;

            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");
            }



            Ed.Editor ed = doc.Editor;

            try
            {
                using (doc.LockDocument())
                {
                    using (Db.Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        Db.Extents3d extends = br.GeometryExtentsBestFit();
                        Point3d      pmin    = extends.MinPoint;
                        Point3d      pmax    = extends.MaxPoint;



                        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 PltInfo = new Pt.PlotInfo())
                        {
                            PltInfo.Layout = model.LayoutId;

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

                                Db.PlotSettingsValidator PltSetVald = Db.PlotSettingsValidator
                                                                      .Current;


                                Db.Extents2d extents = new Db.Extents2d(
                                    pmin.X * (1 - 0.0001),
                                    pmin.Y * (1 + 0.001),
                                    pmax.X,
                                    pmax.Y
                                    );

                                Log4NetHelper.WriteInfoLog("左上角坐标:" + pmin.X + "," + pmin.Y + "\n");
                                Log4NetHelper.WriteInfoLog("右下角角坐标:" + pmax.X + "," + pmax.Y + "\n");



                                PltSetVald.SetZoomToPaperOnUpdate(PltSet, true);

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

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

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

                                // 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(PltInfo, 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, PltInfo, 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;
            }
        }