Example #1
0
        public void ReadSelection()
        {
            Params.Clear();
            updateDestinationNotchesCommand.AllowExecution = false;

            var document = Application.DocumentManager.MdiActiveDocument;
            var editor   = document.Editor;

            var selectionResult = editor.SelectImplied();

            if (selectionResult.Status == Autodesk.AutoCAD.EditorInput.PromptStatus.Error)
            {
                logger.Error("Error getting selection");
                Params.Error("Error getting selection");
                return;
            }

            var selection = selectionResult.Value;

            using (var tx = document.TransactionManager.StartTransaction())
            {
                var objects = selection.GetObjectIds()
                              .Select(objectId => tx.GetObject(objectId, OpenMode.ForRead))
                              .ToList();

                var       curves = objects.OfType <Polyline>().ToList();
                const int polylinesNeededCount = 2;
                if (curves.Count != polylinesNeededCount) // TODO: Add loggog
                {
                    logger.Error($"Error getting selection: {curves.Count} polyline(s) selected instead of {polylinesNeededCount} needed");
                    Params.Error($"Error getting selection: {curves.Count} polyline(s) selected instead of {polylinesNeededCount} needed");
                    return;
                }

                var notchLines = objects.OfType <Line>();
                projector = Projector.FromNotchLines(curves[0], curves[1], notchLines);
                UpdateParamsFromProjector();

                tx.Commit();
            }

            updateDestinationNotchesCommand.AllowExecution = true;
        }