Пример #1
0
        public void PythonScriptCmdLine()
        {
            // PythonScript(true);
            Document doc = Application.DocumentManager.MdiActiveDocument;

            Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
            Editor ed = doc.Editor;

            using (doc.LockDocument())
            {
                using (db)
                {
                    using (Transaction t = db.TransactionManager.StartTransaction())
                    {
                        BlockTable       bt  = t.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                        BlockTableRecord btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                        short fd = (short)Application.GetSystemVariable("FILEDIA");

                        // As the user to select a .py file

                        PromptStringOptions pso = new PromptStringOptions("Insert First Handle");
                        pso.AllowSpaces = true;

                        PromptResult pr      = ed.GetString(pso);
                        string       handle1 = pr.StringResult.Replace("\"", "");

                        pso             = new PromptStringOptions("Insert Second Handle");
                        pso.AllowSpaces = true;

                        pr = ed.GetString(pso);
                        string handle2 = pr.StringResult.Replace("\"", "");

                        ObjectId oid1 = db.GetObjectId(false, new Handle(Convert.ToInt64(handle1, 16)), 0);
                        ObjectId oid2 = db.GetObjectId(false, new Handle(Convert.ToInt64(handle2, 16)), 0);

                        DBObject ent1 = t.GetObject(oid1, OpenMode.ForWrite);
                        DBObject ent2 = t.GetObject(oid2, OpenMode.ForWrite);

                        ent2.SwapIdWith(oid1, true, true);

                        ent1.Erase();

                        Application.SetSystemVariable("FILEDIA", fd);

                        t.Commit();
                    }
                }
            }
        }
Пример #2
0
        static public void GetEnt()
        {
            AcEd.Editor  ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptResult rs = ed.GetString("\nВведите метку примитива (в hex-представлении): ");

            if (rs.Status != PromptStatus.OK)
            {
                return;
            }
            System.Int64  l  = System.Int64.Parse(rs.StringResult, System.Globalization.NumberStyles.HexNumber);
            AcDb.Handle   h  = new AcDb.Handle(l);
            AcDb.Database db = AcDb.HostApplicationServices.WorkingDatabase;
            AcDb.ObjectId id = db.GetObjectId(false, h, 0);
            if (!id.IsValid)
            {
                ed.WriteMessage("\nОшибочная метка примитива {0}", h);
                return;
            }
            using (AcAp.DocumentLock doclock = ed.Document.LockDocument())
            {
                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.Entity ent = tr.GetObject(id, AcDb.OpenMode.ForRead) as AcDb.Entity;
                    if (ent != null)
                    {
                        ed.WriteMessage("\nEntity Class: {0}", AcRx.RXClass.GetClass(ent.GetType()).Name);
                        // Ну и так далее - делаешь с примитивом то, что тебе нужно...
                    }
                    else
                    {
                        ed.WriteMessage("\nЭто не примитив!");
                    }
                }
            }
        }