コード例 #1
0
        public void Test()
        {
            var acDoc = AcadApp.Application.DocumentManager.MdiActiveDocument;
            var acDb  = acDoc.Database;
            var ed    = acDoc.Editor;

            // build a selection filter to get only measurable entities
            var filter = new SelectionFilter(new[]
            {
                new TypedValue(-4, "<OR"),
                new TypedValue(0, "ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,SPLINE"),
                new TypedValue(-4, "<AND"),
                new TypedValue(0, "POLYLINE"),      // polylines 2d or 3d
                new TypedValue(-4, "<NOT"),         // but not meshes
                new TypedValue(-4, "&"),
                new TypedValue(70, 112),
                new TypedValue(-4, "NOT>"),
                new TypedValue(-4, "AND>"),
                new TypedValue(-4, "OR>")
            });

            var selection = ed.GetSelection(filter);

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

            var watch = System.Diagnostics.Stopwatch.StartNew();

            using (var tr = acDb.TransactionManager.StartTransaction())
            {
                // use Linq queries to get lengths by type in a dictionary
                var lengths = selection.Value
                              .Cast <SelectedObject>()
                              .Select(selObj => (Curve)tr.GetObject(selObj.ObjectId, OpenMode.ForRead))
                              .ToLookup(curve => curve.GetType().Name,                         // <- key selector
                                        curve => curve.GetDistanceAtParameter(curve.EndParam)) // <- element selector
                              .ToDictionary(group => group.Key,                                // <- key selector
                                            group => group.Sum());                             // <- element selector

                // print results
                foreach (var entry in lengths)
                {
                    ed.WriteMessage($"\n{entry.Key,-12} = {entry.Value,9:0.00}");
                }
                ed.WriteMessage($"\nTotal Length = {lengths.Values.Sum(),9:0.00}");

                tr.Commit();
            }
            AcadApp.Application.DisplayTextScreen = false;
            watch.Stop();
            AcadFuncs.GetEditor().WriteMessage(watch.ElapsedMilliseconds.ToString());
        }
コード例 #2
0
        static public List <ObjectId> PickEnts()
        {
            using (AcadApp.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
                {
                    PromptSelectionResult prmpt_ret = AcadFuncs.GetEditor().GetSelection();
                    if (PromptStatus.Cancel == prmpt_ret.Status)
                    {
                        tr.Abort();
                        tr.Dispose();
                        return(new List <ObjectId>());
                    }

                    tr.Commit();
                    return(prmpt_ret.Value.GetObjectIds().ToList());
                }
            }
        }
コード例 #3
0
        public List <DataExcel> GetData()
        {
            List <ObjectId>  ids        = AcadFuncs.PickEnts();
            List <DataExcel> data_excel = new List <DataExcel>();

            using (Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction())
            {
                foreach (var id in ids)
                {
                    Line line = tr.GetObject(id, OpenMode.ForRead) as Line;
                    if (null == line)
                    {
                        continue;
                    }

                    data_excel.Add(new DataExcel(line.StartPoint, line.EndPoint));
                }
            }

            return(data_excel);
        }