예제 #1
0
        public void DistanceTest()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptDistanceOptions opt1 = new PromptDistanceOptions("Enter the radius of the circle");

            opt1.AllowNegative = false;
            opt1.AllowZero     = false;
            opt1.AllowNone     = false;
            opt1.UseDashedLine = true;

            PromptDoubleResult res = ed.GetDistance(opt1);

            if (res.Status == PromptStatus.OK)
            {
                Point3d  center = new Point3d(9.0, 3.0, 0.0);
                Vector3d normal = new Vector3d(0.0, 0.0, 1.0);
                Database db     = Application.DocumentManager.MdiActiveDocument.Database;
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
                using (Transaction myT = tm.StartTransaction())
                {
                    BlockTable       bt  = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                    BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                    using (Circle pcirc = new Circle(center, normal, res.Value))
                    {
                        btr.AppendEntity(pcirc);
                        tm.AddNewlyCreatedDBObject(pcirc, true);
                    }
                    myT.Commit();
                }
            }
        }
예제 #2
0
        static public void DoIt()
        {
            Editor             ed   = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointOptions opts = new PromptPointOptions("\nEnter Ellipse Center Point:");
            PromptPointResult  res  = ed.GetPoint(opts);

            Vector3d x         = Application.DocumentManager.MdiActiveDocument.Database.Ucsxdir;
            Vector3d y         = Application.DocumentManager.MdiActiveDocument.Database.Ucsydir;
            Vector3d NormalVec = x.CrossProduct(y);


            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            //Create Ellipsejig
            EllipseJig jig = new EllipseJig(res.Value, NormalVec.GetNormal());

            //first call drag to get the major axis
            jig.setPromptCounter(0);
            Application.DocumentManager.MdiActiveDocument.Editor.Drag(jig);
            // Again call drag to get minor axis
            jig.setPromptCounter(1);
            Application.DocumentManager.MdiActiveDocument.Editor.Drag(jig);

            //Append entity.
            using (Transaction myT = tm.StartTransaction())
            {
                BlockTable       bt  = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                btr.AppendEntity(jig.GetEntity());
                tm.AddNewlyCreatedDBObject(jig.GetEntity(), true);
                myT.Commit();
            }
        }
예제 #3
0
        public static ObjectId AddToPaperSpace(Entity ent, Autodesk.AutoCAD.DatabaseServices.Database database)
        {
            ObjectId id;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager transactionManager = database.TransactionManager;
            using (Autodesk.AutoCAD.DatabaseServices.Transaction transaction = transactionManager.StartTransaction())
            {
                id = ((BlockTableRecord)transactionManager.GetObject(PaperSpaceId(database), OpenMode.ForWrite, false)).AppendEntity(ent);
                transactionManager.AddNewlyCreatedDBObject(ent, true);
                transaction.Commit();
            }
            return(id);
        }
예제 #4
0
        public void PointTest()
        {
            Editor             ed     = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointOptions ptopts = new PromptPointOptions("Enter start point of the line");

            ptopts.BasePoint     = new Point3d(1, 1, 1);
            ptopts.UseDashedLine = true;
            ptopts.Message       = "Enter start point of the line";

            ed.PromptingForPoint += new PromptPointOptionsEventHandler(handle_promptPointOptions);
            ed.PromptedForPoint  += new PromptPointResultEventHandler(handle_promptPointResult);
            PromptPointResult ptRes = ed.GetPoint(ptopts);

            ed.PromptingForPoint -= new PromptPointOptionsEventHandler(handle_promptPointOptions);
            ed.PromptedForPoint  -= new PromptPointResultEventHandler(handle_promptPointResult);


            Point3d start = ptRes.Value;

            if (ptRes.Status == PromptStatus.Cancel)
            {
                ed.WriteMessage("Taking (0,0,0) as the start point");
            }

            ptopts.Message = "Enter end point of the line: ";
            ptRes          = ed.GetPoint(ptopts);
            Point3d end = ptRes.Value;

            if (ptRes.Status == PromptStatus.Cancel)
            {
                ed.WriteMessage("Taking (0,0,0) as the end point");
            }

            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Transaction myT = tm.StartTransaction())
            {
                BlockTable       bt  = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                using (Line myline = new Line(start, end))
                {
                    btr.AppendEntity(myline);
                    tm.AddNewlyCreatedDBObject(myline, true);
                }
                myT.Commit();
            }
        }
예제 #5
0
        public void AngleTest()
        {
            Editor             ed   = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptAngleOptions opt1 = new PromptAngleOptions("Enter start angle of the arc");

            opt1.AllowNone     = false;
            opt1.UseDashedLine = true;

            //USAGE OF INPUT CONTEXT REACTORS
            ed.PromptingForAngle += new PromptAngleOptionsEventHandler(handle_promptangleOptions);
            ed.PromptedForAngle  += new PromptDoubleResultEventHandler(handle_promptAngleResult);

            PromptDoubleResult startAngle = ed.GetAngle(opt1);

            ed.PromptingForAngle -= new PromptAngleOptionsEventHandler(handle_promptangleOptions);
            ed.PromptedForAngle  -= new PromptDoubleResultEventHandler(handle_promptAngleResult);


            opt1.Message = "Enter end angle of the arc";
            PromptDoubleResult endAngle = ed.GetAngle(opt1);

            PromptDoubleOptions opt2 = new PromptDoubleOptions("Enter the radius of the arc(double)");

            opt2.Message = "Enter the radius of the arc(double)";
            PromptDoubleResult radius = ed.GetDouble(opt2);

            if (startAngle.Status == PromptStatus.OK && endAngle.Status == PromptStatus.OK && radius.Status == PromptStatus.OK)
            {
                Point3d  center = new Point3d(30.0, 19.0, 0.0);
                Database db     = Application.DocumentManager.MdiActiveDocument.Database;
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

                using (Transaction myT = tm.StartTransaction())
                {
                    BlockTable       bt  = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                    BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                    using (Arc arc1 = new Arc(center, radius.Value, startAngle.Value, endAngle.Value))
                    {
                        btr.AppendEntity(arc1);
                        tm.AddNewlyCreatedDBObject(arc1, true);
                    }
                    myT.Commit();
                }
            }
            else
            {
                ed.WriteMessage("Arc cannot be constructed");
            }
        }
예제 #6
0
        static public void D()
        {
            StandardLineWrapper sl = new StandardLineWrapper();

            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Transaction myT = tm.StartTransaction())
            {
                BlockTable       bt  = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                btr.AppendEntity(sl);
                tm.AddNewlyCreatedDBObject(sl, true);
                myT.Commit();
            }
        }
예제 #7
0
        static public void AppendEntity(Entity ent)
        {
            if (ent.ObjectId.IsNull == false)
            {
                return;
            }
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            TransactionControl(() =>
            {
                BlockTable bt        = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                btr.AppendEntity(ent);
                tm.AddNewlyCreatedDBObject(ent, true);
            });
        }
예제 #8
0
        private void Init()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            Transaction      t   = tm.StartTransaction();
            BlockTable       bt  = tm.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable;
            BlockTableRecord btr = tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord;

            Autodesk.Aec.DatabaseServices.MassElement temp = Autodesk.Aec.DatabaseServices.MassElement.Create(ShapeType.BoundaryRepresentation);
            Autodesk.Aec.Modeler.Body body = Autodesk.Aec.Modeler.Body.Cone(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(0, 0, 10)), 3, 3, 10);
            temp.SetBody(body, false);
            btr.AppendEntity(temp);
            tm.AddNewlyCreatedDBObject(temp, true);

            t.Commit();
            t.Dispose();
        }
예제 #9
0
        static public string GetDbFlag(Document doc)
        {
            Database db   = doc.Database;
            Editor   ed   = doc.Editor;
            string   uuid = null;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            Utils.TransactionControl(() =>
            {
                TypedValue[] value        = { new TypedValue((int)DxfCode.Start, "DWGMARK") };
                SelectionFilter sf        = new SelectionFilter(value);
                PromptSelectionResult res = ed.SelectAll(sf);
                if (res.Status == PromptStatus.OK)
                {
                    SelectionSet SS = res.Value;
                    var idArray     = SS.GetObjectIds();

                    foreach (var id in idArray)
                    {
                        Entity entity = (Entity)tm.GetObject(id, OpenMode.ForRead, true);
                        if (entity is MIM.Mark)
                        {
                            var mark = entity as MIM.Mark;
                            uuid     = mark.Uuid;
                            return;
                        }
                    }
                }

                Guid guid        = Guid.NewGuid();
                MIM.Mark newMark = new MIM.Mark();
                uuid             = guid.ToString();
                newMark.Uuid     = uuid;
                BlockTable bt    = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead);
                using (doc.LockDocument())
                {
                    BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                    btr.AppendEntity(newMark);
                    tm.AddNewlyCreatedDBObject(newMark, true);
                }
            });
            return(uuid);
        }
예제 #10
0
        static public void DoIt()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //输入起点坐标
            PromptPointOptions opts = new PromptPointOptions("\nEnter Roadway Start Point:");
            PromptPointResult  res  = ed.GetPoint(opts);

            if (res.Status == PromptStatus.Cancel)
            {
                return;
            }

            Point3d tmpPoint = res.Value;

            StandardLineJig jig = new StandardLineJig(tmpPoint, tmpPoint, tmpPoint);

            jig.setPromptCounter(0);
            PromptResult drag = ed.Drag(jig);

            jig.setPromptCounter(1);
            drag = ed.Drag(jig);

            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Transaction myT = tm.StartTransaction())
            {
                BlockTable       bt  = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                btr.AppendEntity(jig.GetEntity());
                tm.AddNewlyCreatedDBObject(jig.GetEntity(), true);
                myT.Commit();
            }
        }
예제 #11
0
        public bool newImg()
        {
            DocumentLock doclock = null;

            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                doclock = doc.LockDocument();

                Database db = HostApplicationServices.WorkingDatabase;

                ObjectId bjdtId = ElectronTransferDal.Cad.DCadApi.addLayer("背景地图");
                if (bjdtId != ObjectId.Null)
                {
                    db.Clayer = bjdtId;

                    Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

                    using (Transaction t = tm.StartTransaction())
                    {
                        try
                        {
                            var          imgDictID = RasterImageDef.GetImageDictionary(db);
                            DBDictionary imgDict;
                            if (imgDictID.OldId == 0)
                            {
                                imgDictID = RasterImageDef.CreateImageDictionary(db);
                            }

                            // create the raster image definition
                            RasterImageDef rasterDef = new RasterImageDef();

                            rasterDef.SourceFileName = ImgFullName;
                            rasterDef.Load();

                            // test the image dictionary and the raster before going further
                            bool bTestLoad = rasterDef.IsLoaded;

                            imgDict = (DBDictionary)t.GetObject(imgDictID, OpenMode.ForWrite);

                            // add the raster definition to the dictionary iff it doesn't already exist
                            ObjectId rasterDefID;
                            if (!imgDict.Contains(ImgName))
                            {
                                rasterDefID = imgDict.SetAt(ImgName, rasterDef);
                            }

                            t.AddNewlyCreatedDBObject(rasterDef, true);

                            // now add the REAL raster image reference
                            RasterImage rasterRef = new RasterImage();
                            rasterRef.ImageDefId = rasterDef.ObjectId;
                            ObjectId testRefID = rasterRef.ObjectId;

                            BlockTable       bt  = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
                            BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                            btr.AppendEntity(rasterRef);

                            tm.AddNewlyCreatedDBObject(rasterRef, true);

                            rasterRef.AssociateRasterDef(rasterDef);

                            parEntityId = rasterRef.ObjectId;
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception eex)
                        { }
                        catch (System.Exception ex) { }

                        t.Commit();
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception eex)
            {
                return(false);
            }
            catch (System.Exception ex) { return(false); }
            finally
            {
                doclock.Dispose();
            }

            return(true);
        }