Beispiel #1
0
        public static void MassiveSuperExplode(this SelectionSet set, out DBObjectCollection col)
        {
            var ids = set.GetObjectIds();

            if (ids == null)
            {
                throw new Exception("Nothing Selected.");
            }

            var bfs = from id in ids
                      let ent                     = id.GetObject(OpenMode.ForRead) as Entity
                                          let lyr = ent.LayerId.GetObject(OpenMode.ForRead) as LayerTableRecord
                                                    where !lyr.IsLocked && ent is BlockReference
                                                    select ent as BlockReference;

            var db         = set.Database();
            var bt         = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
            var modelspace = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForRead) as BlockTableRecord;

            col = new DBObjectCollection();

            modelspace.UpgradeOpen();
            foreach (var bf in bfs)
            {
                foreach (var explodedObj in SuperExplode(bf, modelspace))
                {
                    col.Add(explodedObj as DBObject);
                }
            }
            modelspace.DowngradeOpen();
        }
        public void DLJS()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            PubVal.zongdianliang = 0;
            double val;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                TypedValue[] typeval = new TypedValue[1];
                typeval.SetValue(new TypedValue((int)DxfCode.Start, "TEXT"), 0);

                SelectionFilter sf = new SelectionFilter(typeval);

                PromptSelectionResult psr = ed.GetSelection(sf);
                if (psr.Status == PromptStatus.OK)
                {
                    SelectionSet ss = psr.Value;

                    foreach (ObjectId id in ss.GetObjectIds())
                    {
                        DBText dBText = trans.GetObject(id, OpenMode.ForRead) as DBText;
                        val = double.Parse(Tools.IntegerString(dBText.TextString)) / 1000;
                        PubVal.zongdianliang += val;
                    }
                }
                trans.Commit();
            }

            DLJSForm f1 = new DLJSForm();

            f1.ShowDialog();
        }
Beispiel #3
0
        private List <T> My_GetEntsInModelSpace <T>(Database db, OpenMode mode, bool openErased) where T : Entity
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //获取类型T代表的DXF代码名用于构建选择集过滤器
            string dxfname = RXClass.GetClass(typeof(T)).DxfName;

            //构建选择集过滤器
            TypedValue[]    values = { new TypedValue((int)DxfCode.Start,   dxfname),
                                       new TypedValue((int)DxfCode.LayoutName, "Model") };
            SelectionFilter filter = new SelectionFilter(values);
            //选择符合条件的所有实体
            PromptSelectionOptions pso = new PromptSelectionOptions();

            pso.MessageForAdding = "\n请选择要统计的实体";
            PromptSelectionResult entSelected = ed.GetSelection(pso, filter);

            if (entSelected.Status != PromptStatus.OK)
            {
                return(null);
            }
            SelectionSet ss   = entSelected.Value;
            List <T>     ents = new List <T>();

            using (Transaction ts = db.TransactionManager.StartTransaction())
            {
                ents.AddRange(ss.GetObjectIds().Select(id => ts.GetObject(id, mode, openErased)).OfType <T>());
            }
            return(ents);
        }
        public void ChooseEntityCollection()
        {
            Database              db               = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Editor                ed               = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Entity                entity           = null;
            DBObjectCollection    EntityCollection = new DBObjectCollection();
            PromptSelectionResult ents             = ed.GetSelection();

            if (ents.Status == PromptStatus.OK)
            {
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    SelectionSet SS = ents.Value;
                    foreach (ObjectId id in SS.GetObjectIds())
                    {
                        entity = (Entity)transaction.GetObject(id, OpenMode.ForWrite, true);
                        if (entity != null)
                        {
                            EntityCollection.Add(entity);
                        }
                    }
                    transaction.Commit();
                }
            }
        }
Beispiel #5
0
        deletePntFromProfile(string strLayer, int lngPntNum)
        {
            TypedValue[] tvs = new TypedValue[3];
            tvs.SetValue(new TypedValue((int)DxfCode.Start, "MTEXT"), 0);
            tvs.SetValue(new TypedValue((int)DxfCode.Text, lngPntNum.ToString()), 1);
            tvs.SetValue(new TypedValue((int)DxfCode.LayerName, strLayer), 2);

            SelectionSet ss = Select.buildSSet(tvs);

            ObjectId[] ids = ss.GetObjectIds();

            ResultBuffer rb = ids[0].getXData("LEADER");

            if (rb == null)
            {
                return;
            }
            tvs = rb.AsArray();

            ids[0].delete();

            ObjectId idLeader = tvs.getObjectId(1);

            idLeader.delete();
        }
Beispiel #6
0
 public void T2()
 {
     try
     {
         DocumentCollection acDocMgr = Application.DocumentManager;
         Document           acDoc    = acDocMgr.MdiActiveDocument;
         Database           acCurDb  = acDocMgr.MdiActiveDocument.Database;
         Editor             acDocEd  = acDocMgr.MdiActiveDocument.Editor;
         using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
         {
             Point3d acPtBotTxt3d = GetPoint3dFromPrompt(acDoc, "Pick First Point");
             Point3d acPtTopTxt3d = GetPoint3dFromPrompt(acDoc, "Pick Second Point");
             Point2d acPtBotTxt2d = new Point2d(acPtBotTxt3d.X, acPtBotTxt3d.Y);
             Point2d acPtTopTxt2d = new Point2d(acPtTopTxt3d.X, acPtTopTxt3d.Y);
             if ((acDocEd.SelectWindow(acPtBotTxt3d, acPtBotTxt3d)).Value == null)
             {
                 return;
             }
             SelectionSet acSSet = (acDocEd.SelectWindow(acPtBotTxt3d, acPtBotTxt3d)).Value;
             foreach (ObjectId acObjId in acSSet.GetObjectIds())
             {
                 Application.ShowAlertDialog(acObjId.ToString());
             }
         }
     }
     catch (Autodesk.AutoCAD.Runtime.Exception e)
     {
         Application.ShowAlertDialog("Message: \n" + e.Message);
         Application.ShowAlertDialog("StackTrace: \n" + e.StackTrace.ToString());
         Application.ShowAlertDialog("TargerSite: " + e.TargetSite.ToString());
     }
 }
Beispiel #7
0
        //选择对象并返回DBObjectCollection
        public static DBObjectCollection HJ_GetObjsBySelectionFilter(this Database db, SelectionFilter filter, OpenMode mode, bool openErased)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            //选择符合条件的所有实体
            PromptSelectionResult entSelected = ed.GetSelection(filter);

            if (entSelected.Status != PromptStatus.OK)
            {
                return(null);
            }
            SelectionSet ss = entSelected.Value;

            DBObjectCollection ents = new DBObjectCollection();

            using (Transaction ts = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ss.GetObjectIds())
                {
                    DBObject obj = ts.GetObject(id, mode, openErased);
                    if (obj != null)
                    {
                        ents.Add(obj);
                    }
                }
                ts.Commit();//没有这个就不会提交内部的修改
            }
            return(ents);
        }
        public static bool TrySelectObjects <T>(out IList <T> objCollection, OpenMode openMode, string msg, Transaction transaction)
            where T : DBObject
        {
            Editor       ed  = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            SelectionSet set = null;

            objCollection = null;
            PromptSelectionOptions opt = new PromptSelectionOptions();

            opt.AllowDuplicates = false;

            PromptSelectionResult res = ed.GetSelection(opt);

            if (res.Status == PromptStatus.OK)
            {
                if ((set = res.Value) != null)
                {
                    ObjectId[] ids = set.GetObjectIds();
                    objCollection = new List <T>(set.Count);
                    foreach (ObjectId id in ids)
                    {
                        DBObject dbobj = transaction.GetObject(id, openMode, true);
                        T        val   = dbobj as T;
                        if (val != null)
                        {
                            objCollection.Add(val);
                        }
                    }

                    ed.WriteMessage(string.Format("\n{0} selected points", objCollection.Count));
                    return(true);
                }
            }
            return(false);
        }
Beispiel #9
0
        checkAreaLimits(SelectionSet objSSetAreas)
        {
            SelectionSet objSSet = EW_Utility1.buildSSetGradingLim();

            if (objSSet.Count == 0)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("GRADING LIMIT missing - exiting..........");
                return;
            }
            ObjectId idGradingLim = objSSet.GetObjectIds()[0];

            objSSet = EW_Utility1.buildSSetBLDG_LIM();
            if (objSSet.Count == 0)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("BUILDING LIMIT missing - exiting.......");
                return;
            }

            if (checkAreaLimit(objSSetAreas, idGradingLim))
            {
                return;
            }

            List <Point3d> varPnts3dBndry0z = getGradingLimitCoords();

            limitIsOutside(objSSetAreas, varPnts3dBndry0z);
        }
Beispiel #10
0
        private void createGroup(string groupName)
        {
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //新建一个组对象
                Group gp = new Group(groupName, true);
                //打开当前数据库的组字典对象以加入新建的组对象
                DBDictionary dict = (DBDictionary)trans.GetObject(db.GroupDictionaryId, OpenMode.ForWrite);
                //在组字典中将组对象作为一个新条目加入,并指定它的搜索关键字为groupName
                dict.SetAt(groupName, gp);
                //下面的操作用来选择组中要包含的对象
                PromptSelectionOptions opt = new PromptSelectionOptions();
                opt.MessageForAdding = "请选择组中要包含的对象";
                PromptSelectionResult res = ed.GetSelection(opt);
                if (res.Status != PromptStatus.OK)
                {
                    return;
                }
                //获取所选择对象的ObjectId集合
                SelectionSet       ss  = res.Value;
                ObjectIdCollection ids = new ObjectIdCollection(ss.GetObjectIds());
                //在组对象中加入所选择的对象
                gp.Append(ids);
                //通知事务处理完成组对象的加入
                trans.AddNewlyCreatedDBObject(gp, true);
                trans.Commit();
            }
        }
Beispiel #11
0
        private static bool GetPoints(Database db, Editor ed, ref Point3d[] pt)
        {
            DBObjectCollection    EntityCollection = new DBObjectCollection();
            PromptSelectionResult ents             = ed.GetSelection();
            Entity  entity = null;
            Point3d maxP   = new Point3d();
            Point3d minP   = new Point3d();

            if (ents.Status == PromptStatus.OK)
            {
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    SelectionSet SS = ents.Value;
                    foreach (ObjectId id in SS.GetObjectIds())
                    {
                        entity = (Entity)transaction.GetObject(id, OpenMode.ForWrite, true);
                        Entity entity2 = (Entity)transaction.GetObject(id, OpenMode.ForRead, true);
                        if (entity.GetType().Name == "Line")
                        {
                            Line line = (Line)transaction.GetObject(id, OpenMode.ForRead, true);
                            EntityCollection.Add(entity);
                            maxP  = line.StartPoint;
                            minP  = line.EndPoint;
                            pt[0] = maxP;
                            pt[1] = minP;

                            return(true);
                        }
                    }
                    transaction.Commit();
                }
            }
            return(false);
        }
Beispiel #12
0
        public void BLt()
        {
            // 获取当前文档获
            Document         doc = Application.DocumentManager.MdiActiveDocument;
            Database         db  = doc.Database;
            Editor           ed  = doc.Editor;
            Transaction      tr  = db.TransactionManager.StartTransaction();
            BlockTable       bt  = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
            BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

            using (tr)
            {
                PromptSelectionResult acSSPrompt = ed.GetSelection();
                SelectionSet          acSSet     = acSSPrompt.Value;
                if (acSSPrompt.Status == PromptStatus.OK)
                {
                    var ids = acSSet.GetObjectIds();
                    foreach (var item in ids)
                    {
                        Entity ent = (Entity)tr.GetObject(item, OpenMode.ForRead);
                        ed.WriteMessage("\n名字有:{0}", ent.GetType().Name);
                    }
                }
            }
        }
Beispiel #13
0
        private void SpecifySoilHatch(object arg)
        {
            if (doc != null)
            {
                //прервать выполнение любых команд (отправляем на выполнение эскейп-символ)
                //doc.SendStringToExecute(new string(new char[] { '\x03' }), true, false, false);

                HighlightObjs(false, SoilHatchIds);

                Editor   ed = doc.Editor;
                Database db = doc.Database;

                TypedValue[] tv = new TypedValue[]
                {
                    new TypedValue(0, "HATCH")
                };
                SelectionFilter flt = new SelectionFilter(tv);

                PromptSelectionOptions pso = new PromptSelectionOptions();
                pso.MessageForAdding = "\nВыберите штриховки грунтов";

                PromptSelectionResult acSSPrompt = doc.Editor.GetSelection(pso, flt);
                if (acSSPrompt.Status == PromptStatus.OK)
                {
                    SelectionSet acSSet = acSSPrompt.Value;
                    if (acSSet != null)
                    {
                        SoilHatchIds = acSSet.GetObjectIds();
                    }
                }

                HighlightObjs(true, SoilHatchIds);
            }
        }
        public static ObjectId[] GetAllShape()
        {
            ObjectId[] objs = null;

            string   name = "";
            Database db   = HostApplicationServices.WorkingDatabase;
            Editor   ed   = Interaction.ActiveEditor;// Application.DocumentManager.MdiActiveDocument.Editor;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //获取当前图层
                var layerTableRecord = (LayerTableRecord)trans.GetObject(db.Clayer, OpenMode.ForRead, false);

                //获取图层的名称
                name = layerTableRecord.Name;

                //以下是获取当前图层上所有元素
                TypedValue[] pTypeValue = new TypedValue[] { new TypedValue((int)DxfCode.LayerName, name) };

                SelectionFilter       pSelectFilter = new SelectionFilter(pTypeValue);
                PromptSelectionResult pSelectResult = ed.SelectAll(pSelectFilter);
                SelectionSet          pSelectSet    = pSelectResult.Value;

                objs = pSelectSet.GetObjectIds();

                trans.Commit();
            }

            db.CloseInput(true);
            return(objs);
        }
Beispiel #15
0
        public void TestPolyLine()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptSelectionOptions pso = new PromptSelectionOptions();

            pso.MessageForAdding = "请选择实体集:::";
            PromptSelectionResult psr = ed.GetSelection(pso);

            if (psr.Status == PromptStatus.OK)
            {
                SelectionSet ss    = psr.Value;
                int          count = ss.Count;
                ed.WriteMessage("选择了{0}个实体\n", count);


                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId id in ss.GetObjectIds())
                    {
                        using (Polyline pline = trans.GetObject(id, OpenMode.ForWrite) as Polyline)
                        {
                            Point2d pt;
                            for (int i = 0; i < pline.NumberOfVertices; i++)
                            {
                                pt = pline.GetPoint2dAt(i);
                                ed.WriteMessage(pt.X.ToString() + "," + pt.Y.ToString() + "\n");
                            }
                        }
                    }
                    trans.Commit();
                }
            }
        }
Beispiel #16
0
        public void TestIntersectWith()
        {
            //获取当前文档编辑器
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            TypedValue[] tValue = new TypedValue[2];
            tValue.SetValue(new TypedValue((int)DxfCode.Start, "LWPOLYLINE"), 0);
            tValue.SetValue(new TypedValue((int)DxfCode.ExtendedDataReal, 20.00), 1);
            //将过滤条件赋给 SelectionFilter 对象
            SelectionFilter sFilter = new SelectionFilter(tValue);
            //请求在图形区域选择对象
            PromptSelectionResult psr           = ed.SelectAll(sFilter);
            ObjectIdCollection    objCollection = new ObjectIdCollection();

            //如果提示状态 OK,说明已选对象
            if (psr.Status == PromptStatus.OK)
            {
                SelectionSet ss = psr.Value;
                Application.ShowAlertDialog("Number of objects selected: " +
                                            ss.Count.ToString());

                PromptEntityResult per = ed.GetEntity("请选择直线实体");
                ObjectId           lineId;
                if (per.Status != PromptStatus.OK)
                {
                    return;
                }
                lineId = per.ObjectId;
                int      count = 1;
                Database db    = HostApplicationServices.WorkingDatabase;
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    using (Line lineEntity = trans.GetObject(lineId, OpenMode.ForRead) as Line)
                    {
                        foreach (ObjectId id in ss.GetObjectIds())
                        {
                            using (Polyline pline = trans.GetObject(id, OpenMode.ForRead) as Polyline)
                            {
                                Point3dCollection pt3d = new Point3dCollection();
                                lineEntity.IntersectWith(pline, Intersect.OnBothOperands, new Plane(), pt3d, IntPtr.Zero, IntPtr.Zero);
                                if (pt3d.Count > 0)
                                {
                                    ed.WriteMessage("与多段线" + count + ":" + id + "有交点\n");
                                }
                                else
                                {
                                    ed.WriteMessage("与多段线" + count + ":" + id + "没有交点\n");
                                }
                            }
                            count++;
                        }
                    }
                    trans.Commit();
                }
            }
            else
            {
                ed.WriteMessage("已选择0000个对象");
            }
        }
Beispiel #17
0
        public DBObjectCollection Collection()
        {
            Document              doc              = Application.DocumentManager.MdiActiveDocument;
            Database              db               = doc.Database;
            Editor                editor           = doc.Editor;
            Entity                ent              = null;
            DBObjectCollection    entityCollection = new DBObjectCollection();
            PromptSelectionResult ents             = editor.GetSelection();

            if (ents.Status == PromptStatus.OK)
            {
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    SelectionSet ss = ents.Value;
                    foreach (ObjectId id in ss.GetObjectIds())
                    {
                        ent = trans.GetObject(id, OpenMode.ForWrite, true) as Entity;
                        if (ent != null)
                        {
                            entityCollection.Add(ent);
                        }
                    }
                    trans.Commit();
                }
            }
            return(entityCollection);
        }
Beispiel #18
0
        static public void SelectAll(string type, Action <ObjectId[]> handler)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            TypedValue[] value =
            {
                new TypedValue((int)DxfCode.Start, type)
            };
            SelectionFilter       sf  = new SelectionFilter(value);
            PromptSelectionResult res = ed.SelectAll(sf);

            SelectionSet SS = res.Value;

            if (SS == null)
            {
                return;
            }

            ObjectId[] idArray = SS.GetObjectIds();

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

            Utils.TransactionControl(() =>
            {
                handler(idArray);
            });
        }
Beispiel #19
0
        Stream(ArrayList data, SelectionSet selSet)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(SelectionSet)));

            data.Add(new Snoop.Data.ObjectIdCollection("Object IDs", selSet.GetObjectIds()));
            data.Add(new Snoop.Data.Enumerable("Selected objects", selSet));
        }
Beispiel #20
0
        private static List <object> GetLayerObjectsByLayerName(List <string> layerNames)
        {
            List <object> objects = new List <object>();

            if (layerNames.Count != 0)
            {
                using (OpenCloseTransaction trans = acCurDb.TransactionManager.StartOpenCloseTransaction())
                {
                    foreach (string layerName in layerNames)
                    {
                        try
                        {
                            TypedValue[] typedValue = new TypedValue[]
                            {
                                new TypedValue((int)DxfCode.LayerName, layerName)
                            };
                            SelectionFilter       filter = new SelectionFilter(typedValue);
                            PromptSelectionResult result = ed.SelectAll(filter);
                            SelectionSet          set    = result.Value;
                            ObjectId[]            ids    = set.GetObjectIds();
                            foreach (ObjectId entid in ids)
                            {
                                objects.Add(trans.GetObject(entid, OpenMode.ForRead));
                            }
                        }
                        catch (Exception)
                        {
                            ed.WriteMessage("\n获取信息出错。");
                        }
                    }
                    trans.Commit();
                }
            }
            return(objects);
        }
Beispiel #21
0
        setupSpreadSheetPS(string strFullPath, double dblHeight)
        {
            string strPath = BaseObjs.docFullName;
            string strJN   = BaseObjs.jobNumber();
            string strFN   = string.Format("{0}EW.xlsx", strJN);

            string strPntX = "24";
            string strPntY = "6";

            string strPntIns = string.Format("{0},{1}", strPntX, strPntY);

            Excel_ext excl = new Excel_ext(true);

            excl.OpenFile(strFullPath, "");
            excl.FindExcelWorksheet("SUMMARY");
            Excel._Worksheet objWS = excl.excelWrkSht;

            objWS.Range["EW_SUMMARY"].Copy();
            excl.excelAPP.Visible = false;

            BaseObjs._acadDoc.SendStringToExecute(string.Format("_pasteclip {0}\r", strPntIns), true, false, false);
            SelectionSet ss = BaseObjs._editor.SelectAll().Value;
            int          k  = ss.Count;
            ObjectId     id = ss.GetObjectIds()[k - 1];

            using (var tr = BaseObjs.startTransactionDb()){
                Autodesk.AutoCAD.DatabaseServices.Ole2Frame objAcadOle = (Ole2Frame)tr.GetObject(id, OpenMode.ForWrite);
                objAcadOle.LockAspect = false;
                objAcadOle.WcsHeight  = dblHeight;
                objAcadOle.WcsWidth   = dblHeight / 2;
                tr.Commit();
            }
        }
Beispiel #22
0
        /// <summary> 将指定的曲线的起始点反转 </summary>
        /// <param name="docMdf"></param>
        /// <param name="impliedSelection"> 用户在执行方法之前已经选择好的对象。</param>
        private ExternalCmdResult ReverseCurveEnds(DocumentModifier docMdf, SelectionSet impliedSelection)
        {
            docMdf.acEditor.Command();

            Curve c = null;

            if (impliedSelection != null)
            {
                foreach (var id in impliedSelection.GetObjectIds())
                {
                    c = docMdf.acTransaction.GetObject(id, OpenMode.ForRead) as Curve;
                    if (c != null)
                    {
                        break;
                    }
                }
            }
            if (c == null)
            {
                c = PickOneCurve(docMdf);
            }

            if (c != null)
            {
                docMdf.acTransaction.GetObject(c.Id, OpenMode.ForWrite);
                c.ReverseCurve();
                // 提示信息
                string msg = $"\n反转后曲线起点:{c.StartPoint.ToString()},终点:{c.EndPoint.ToString()}";
                docMdf.WriteNow(msg);

                c.DowngradeOpen();
            }
            return(ExternalCmdResult.Commit);
        }
Beispiel #23
0
        public List <Spline> Main_Process(PromptSelectionResult ents)
        {
            Entity        entity  = null;
            List <string> ResData = new List <string>();
            List <Spline> splies  = new List <Spline>();

            if (ents.Status == PromptStatus.OK)
            {
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    SelectionSet SS = ents.Value;

                    foreach (ObjectId id in SS.GetObjectIds())
                    {
                        entity = (Entity)transaction.GetObject(id, OpenMode.ForWrite, true);
                        string TargetslayName = entity.Layer;

                        Object obj = transaction.GetObject(id, OpenMode.ForWrite, true);
                        if (obj.GetType().Name == "Spline")
                        {
                            Spline sp = obj as Spline;
                            splies.Add(sp);
                        }
                    }
                    transaction.Commit();
                }
            }

            return(splies);
        }
Beispiel #24
0
        private static void EraseAll()
        {
            Document Doc = Application.DocumentManager.MdiActiveDocument;
            Editor   Ed  = Application.DocumentManager.MdiActiveDocument.Editor;

            ObjectIdCollection    acObjIdColl = new ObjectIdCollection();
            PromptSelectionResult prrr        = null;

            prrr = Ed.SelectAll();

            if (prrr.Status == PromptStatus.OK)
            {
                SelectionSet acSSett = prrr.Value;
                acObjIdColl = new ObjectIdCollection(acSSett.GetObjectIds());
            }
            else
            {
            }
            DocumentLock locc = Doc.LockDocument();

            using (locc)
            {
                using (Transaction trr = Doc.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId ID in acObjIdColl)
                    {
                        Entity ent = trr.GetObject(ID, OpenMode.ForWrite) as Entity;
                        ent.Erase();
                    }
                    trr.Commit();
                }
            }
        }
Beispiel #25
0
        public List <ObjectId> GetCrossObjectIds(Editor ed, Polyline pl, SelectionFilter sf, Transaction tran)
        {
            Point3dCollection point3DCollection = new Point3dCollection();

            ObjectId[] list = null; List <ObjectId> ooids = new List <ObjectId>();
            for (int i = 0; i < pl.NumberOfVertices; i++)
            {
                point3DCollection.Add(pl.GetPoint3dAt(i));
            }
            PromptSelectionResult psr = ed.SelectCrossingPolygon(point3DCollection, sf);

            if (psr.Status == PromptStatus.OK)
            {
                SelectionSet sst  = psr.Value;
                ObjectId[]   oids = sst.GetObjectIds();

                foreach (ObjectId item in oids)
                {
                    if (item.OldId != pl.ObjectId.OldId)
                    {
                        ooids.Add(item);
                    }
                }
            }

            return(ooids);
        }
Beispiel #26
0
        /// <summary>
        /// /// 选择所有对象
        /// </summary>
        /// <returns></returns>
        public static DBObjectCollection All()
        {
            Database              db               = Application.DocumentManager.MdiActiveDocument.Database;
            Editor                ed               = Application.DocumentManager.MdiActiveDocument.Editor;
            Entity                entity           = null;
            DBObjectCollection    EntityCollection = new DBObjectCollection();
            PromptSelectionResult ents             = ed.SelectAll();

            if (ents.Status == PromptStatus.OK)
            {
                using (Transaction transaction = db.TransactionManager.StartTransaction())
                {
                    SelectionSet ss = ents.Value;
                    foreach (ObjectId id in ss.GetObjectIds())
                    {
                        entity = transaction.GetObject(id, OpenMode.ForWrite, true) as Entity;
                        if (entity != null)
                        {
                            EntityCollection.Add(entity);
                        }
                    }


                    transaction.Commit();
                }
            }
            return(EntityCollection);
        }
Beispiel #27
0
        getStakedPnts()
        {
            SelectionSet ss = Select.buildSSet(typeof(CogoPoint), false, "Select Cogo Point");

            ObjectId[]       ids        = ss.GetObjectIds();
            List <StakedPnt> stakedPnts = new List <StakedPnt>();

            for (int i = 0; i <= ids.Length; i++)
            {
                ObjectId     idCgPnt = ids[i];
                ResultBuffer rb      = idCgPnt.getXData("STAKE");
                if (rb == null)
                {
                    continue;
                }
                TypedValue[] tvs       = rb.AsArray();
                StakedPnt    stakedPnt = new StakedPnt
                {
                    hCgPnt  = idCgPnt.getHandle(),
                    hAlign  = tvs[1].Value.ToString().stringToHandle(),
                    Station = double.Parse(tvs[2].Value.ToString()),
                    Offset  = double.Parse(tvs[3].Value.ToString()),
                    Elev    = idCgPnt.getCogoPntElevation(),
                    Desc    = idCgPnt.getCogoPntDesc(),
                    Number  = (uint)idCgPnt.getCogoPntNumber()
                };
                stakedPnts.Add(stakedPnt);
            }
            return(stakedPnts);
        }
Beispiel #28
0
        limitIsOutside(SelectionSet objSSetAreas, List <Point3d> pnts3dBndry0z)
        {
            ObjectId[]     ids    = objSSetAreas.GetObjectIds();
            List <Point3d> pnts3d = new List <Point3d>();

            Color color = new Color();

            color = Color.FromColorIndex(ColorMethod.ByBlock, 2);

            for (int i = 0; i < ids.Length; i++)
            {
                pnts3d = ids[i].getCoordinates3dList();

                foreach (Point3d pnt3d in pnts3d)
                {
                    if (!pnt3d.isInside(pnts3dBndry0z))
                    {
                        if (Geom.isOn2dSegment(pnt3d, pnts3dBndry0z) == -1)
                        {
                            ObjectId idCircle = Draw.addCircle(pnt3d, 2);
                            idCircle.changeProp(color, "DEBUG-0", LineWeight.LineWeight035);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #29
0
        deleteObjs(TypedValue[] TVs)
        {
            SelectionSet ss = Select.buildSSetBase(TVs, true);

            if (ss == null)
            {
                return;
            }

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    foreach (ObjectId idObj in ss.GetObjectIds())
                    {
                        Entity ENT = (Entity)idObj.GetObject(OpenMode.ForWrite, true);
                        ENT.Erase();
                    }
                    tr.Commit();
                }                // end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Misc.cs: line: 458");
            }
        }
        public static ObjectId[] PromptForBlockSelection(Editor editor, string message)
        {
            TypedValue[] blockFilterList = new TypedValue[1]
            {
                new TypedValue((int)DxfCode.Start, "INSERT")
            };
            SelectionFilter blockelectionFilter = new SelectionFilter(blockFilterList);

            PromptSelectionOptions promptSelectionOptions = new PromptSelectionOptions();

            promptSelectionOptions.MessageForAdding = message;

            PromptSelectionResult promptSelectionResult = editor.GetSelection(promptSelectionOptions, blockelectionFilter);

            if (promptSelectionResult.Status != PromptStatus.OK)
            {
                return(null);
            }

            SelectionSet blockSelectionSet = promptSelectionResult.Value;

            ObjectId[] objectIdCollection = blockSelectionSet.GetObjectIds();

            return(objectIdCollection);
        }
        private void PrintSelectionSet(string title, SelectionSet ss)
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
             Editor ed = doc.Editor;

             ed.WriteMessage(string.Format("{0} BreakupBegin", Environment.NewLine));

             foreach (ObjectId id in ss.GetObjectIds())
             {
                 ed.WriteMessage( string.Format("{0}{1}", Environment.NewLine, id.ObjectClass.Name)          );
             }

             ed.WriteMessage(string.Format("{0}BreakupEnd", Environment.NewLine));
        }