Exemplo n.º 1
0
        public static void Finalise()
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);

                ObjectId         newBlockId = bt[PlotType.CurrentOpen.PlotTypeName];
                BlockTableRecord btr        = tr.GetObject(newBlockId, OpenMode.ForWrite) as BlockTableRecord;
                foreach (ObjectId e in btr)
                {
                    Entity temp = tr.GetObject(e, OpenMode.ForWrite) as Entity;
                    temp.Erase();
                }

                ObjectIdCollection plotObjects = new ObjectIdCollection();

                plotObjects.Add(PlotType.CurrentOpen.BackgroundBlockID);
                plotObjects.Add(PlotType.CurrentOpen.BasepointID);

                foreach (WallSegment ws in PlotType.CurrentOpen.Segments)
                {
                    plotObjects.Add(ws.PerimeterLine);
                }

                foreach (ObjectId c in PlotType.CurrentOpen.AccessPointLocations.Collection)
                {
                    plotObjects.Add(c);
                }

                btr.AssumeOwnershipOf(plotObjects);

                tr.Commit();
            }

            //Triggeer regen to update blocks display
            //alternatively http://adndevblog.typepad.com/autocad/2012/05/redefining-a-block.html
            Application.DocumentManager.CurrentDocument.Editor.Regen();

            //Add to the document store
            CivilDocumentStore cds = acDoc.GetDocumentStore <CivilDocumentStore>();

            cds.PlotTypes.Add(PlotType.CurrentOpen);

            PlotType.CurrentOpen = null;
            OnCurrentOpenChanged?.Invoke();
        }
Exemplo n.º 2
0
        public static void CreatePlotType()
        {
            Document acDoc    = Application.DocumentManager.MdiActiveDocument;
            Editor   acEditor = acDoc.Editor;
            Database acCurDb  = acDoc.Database;

            if (CurrentOpen == null)
            {
                PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter plot type name: ")
                {
                    AllowSpaces = true
                };
                PromptResult pStrRes = acDoc.Editor.GetString(pStrOpts);

                //Verify input
                if (pStrRes.Status == PromptStatus.OK)
                {
                    //Check the block does not already exist
                    bool exists = false;
                    using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
                    {
                        //Create all plot specific layers
                        LayerTable acLayerTable = tr.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite) as LayerTable;
                        Core.Utilities.CreateLayer(tr, acLayerTable, Constants.JPP_HS_PlotPerimiter, Constants.JPP_HS_PlotPerimiterColor);

                        //Create the background block
                        BlockTable bt = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                        if (bt.Has(pStrRes.StringResult))
                        {
                            exists = true;
                        }
                    }

                    if (!exists)
                    {
                        // Prompt for the start point
                        PromptPointOptions pPtOpts = new PromptPointOptions("")
                        {
                            Message = "\nEnter the base point. Basepoint to be located at bottom left corner of the plot: "
                        };
                        PromptPointResult pPtRes = acDoc.Editor.GetPoint(pPtOpts);

                        if (pPtRes.Status == PromptStatus.OK)
                        {
                            CurrentOpen = new PlotType()
                            {
                                PlotTypeName = pStrRes.StringResult,
                                BasePoint    = pPtRes.Value
                            };

                            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
                            {
                                Main.AddRegAppTableRecord();

                                //Create all plot specific layers
                                LayerTable acLayerTable = tr.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite) as LayerTable;
                                Core.Utilities.CreateLayer(tr, acLayerTable, Constants.JPP_HS_PlotPerimiter, Constants.JPP_HS_PlotPerimiterColor);

                                //Create the background block
                                BlockTable bt = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                                bt.UpgradeOpen();

                                BlockTableRecord backgroundBlockRecord = new BlockTableRecord
                                {
                                    Name   = CurrentOpen.PlotTypeName + "Background",
                                    Origin = CurrentOpen.BasePoint
                                };
                                ObjectId objRef = bt.Add(backgroundBlockRecord);
                                tr.AddNewlyCreatedDBObject(backgroundBlockRecord, true);

                                //Prep the block for finalising
                                BlockTableRecord plotTypeBlockRecord = new BlockTableRecord
                                {
                                    Name   = CurrentOpen.PlotTypeName,
                                    Origin = CurrentOpen.BasePoint
                                };
                                ObjectId blockRef = bt.Add(plotTypeBlockRecord);
                                tr.AddNewlyCreatedDBObject(plotTypeBlockRecord, true);

                                //Insert the background block
                                CurrentOpen.BackgroundBlockID = Core.Utilities.InsertBlock(CurrentOpen.BasePoint, 0, objRef);
                                CurrentOpen.BlockID           = blockRef;

                                //Create and add basepoint
                                Circle bp = new Circle
                                {
                                    Center = CurrentOpen.BasePoint,
                                    Radius = 0.5f
                                };
                                BlockTableRecord acBlkTblRec = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                                if (acBlkTblRec != null)
                                {
                                    CurrentOpen.BasepointID = acBlkTblRec.AppendEntity(bp);
                                }
                                else
                                {
                                    //This should never, ever come up but best to handle it
                                    throw new NullReferenceException("Model space not found", null);
                                }

                                tr.AddNewlyCreatedDBObject(bp, true);

                                tr.Commit();
                            }

                            //Inform all event handlers the current plot type has changed
                            OnCurrentOpenChanged?.Invoke();
                        }
                        else
                        {
                            acEditor.WriteMessage("Point selection cancelled\n");
                        }
                    }
                    else
                    {
                        acEditor.WriteMessage("Plot Type Name already exists as block. Please choose a different name or rename exisitng block\n");
                    }
                }
                else
                {
                    acEditor.WriteMessage("No plot type name entered\n");
                }
            }
            else
            {
                acEditor.WriteMessage("Plot Type already open for editing. Please finalise before attempting to create a new plot type.\n");
            }
        }