Esempio n. 1
0
        // When the OFFSET command starts, let's add our selection manipulating event-handler
        /// <summary>
        ///
        /// </summary>
        public void Initialize()
        {
            DocumentCollection dm = Application.DocumentManager;

            // Remove any temporary objects at the end of the command

            dm.DocumentLockModeWillChange += delegate(object sender, DocumentLockModeWillChangeEventArgs e)
            {
                if (_ids.Count > 0)
                {
                    try
                    {
                        using (Transaction tr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
                        {
                            foreach (ObjectId id in _ids)
                            {
                                DBObject obj = id.GetObject(OpenMode.ForWrite, true);
                                obj.Erase();
                            }
                            tr.Commit();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        BaseObjs.writeDebug(ex.Message + " xRefOffsetApp.cs: line: 64");
                    }
                    _ids.Clear();
                }
            };

            // When a document is created, make sure we handle the important events it fires

            dm.DocumentCreated += delegate(object sender, DocumentCollectionEventArgs e)
            {
                e.Document.CommandWillStart += new CommandEventHandler(OnCommandWillStart);
                e.Document.CommandEnded     += new CommandEventHandler(OnCommandFinished);
                e.Document.CommandCancelled += new CommandEventHandler(OnCommandFinished);
                e.Document.CommandFailed    += new CommandEventHandler(OnCommandFinished);
            };

            // Do the same for any documents existing on application initialization

            foreach (Document doc in dm)
            {
                doc.CommandWillStart += new CommandEventHandler(OnCommandWillStart);
                doc.CommandEnded     += new CommandEventHandler(OnCommandFinished);
                doc.CommandCancelled += new CommandEventHandler(OnCommandFinished);
                doc.CommandFailed    += new CommandEventHandler(OnCommandFinished);
            }
        }
Esempio n. 2
0
        updateBrkLine(this ObjectId idPoly3dOrg, List <Point3d> pnts3d)
        {
            ObjectId   idPoly3dNew = ObjectId.Null;
            Polyline3d poly3dNew   = new Polyline3d();

            using (Transaction tr = BaseObjs.startTransactionDb())
            {
                BlockTableRecord ms = Blocks.getBlockTableRecordMS();
                idPoly3dNew = ms.AppendEntity(poly3dNew);

                poly3dNew.SetDatabaseDefaults();
                poly3dNew.Layer = idPoly3dOrg.getLayer();

                foreach (Point3d pnt3dX in pnts3d)
                {
                    PolylineVertex3d v3d = new PolylineVertex3d(pnt3dX);
                    poly3dNew.AppendVertex(v3d);
                    tr.AddNewlyCreatedDBObject(v3d, true);
                }
                tr.AddNewlyCreatedDBObject(poly3dNew, true);
                tr.Commit();
            }

            using (Transaction tr1 = BaseObjs.startTransactionDb())
            {
                DBObject dbObjOrg = tr1.GetObject(idPoly3dOrg, OpenMode.ForRead);
                DBObject dbObjNew = tr1.GetObject(idPoly3dNew, OpenMode.ForRead);

                dbObjNew.UpgradeOpen();
                dbObjNew.SwapIdWith(dbObjOrg.ObjectId, true, true);
                //dbObjOrg.HandOverTo(dbObjNew, true, true);
                dbObjOrg.Erase();

                tr1.Commit();
            }
        }
        public void PlineToPlots()
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            PromptSelectionOptions pso = new PromptSelectionOptions();

            pso.SingleOnly = true;
            pso.RejectObjectsOnLockedLayers = true;
            PromptSelectionResult psr = acDoc.Editor.GetSelection(pso);

            if (psr.Status == PromptStatus.OK)
            {
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    CivSurface oSurface = null;

                    //Get the target surface
                    ObjectIdCollection SurfaceIds = CivilApplication.ActiveDocument.GetSurfaceIds();
                    foreach (ObjectId surfaceId in SurfaceIds)
                    {
                        CivSurface temp = surfaceId.GetObject(OpenMode.ForRead) as CivSurface;
                        if (temp.Name == Civils.Constants.ProposedGroundName)
                        {
                            oSurface = temp;
                        }
                    }

                    int plotCount = 0;


                    foreach (SelectedObject so in psr.Value)
                    {
                        try
                        {
                            DBObject obj = acTrans.GetObject(so.ObjectId, OpenMode.ForWrite);

                            if (obj is Curve)
                            {
                                plotCount++;

                                //Polyline acPline = obj as Polyline;

                                //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" + plotCount, obj.ObjectId);

                                FeatureLine perim = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;
                                perim.AssignElevationsFromSurface(oSurface.Id, false);
                                var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint);

                                double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15;

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

                                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();
                            }
                            else
                            {
                                acDoc.Editor.WriteMessage("Object is not a polyline\n");
                            }
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception e)
                        {
                            acDoc.Editor.WriteMessage(e.Message + "\n");
                        }
                        catch (System.Exception e)
                        {
                            acDoc.Editor.WriteMessage(e.Message + "\n");
                        }
                    }
                    acTrans.Commit();
                }
            }
        }