示例#1
0
        private static void Doc_CommandWillStart(object sender, CommandEventArgs e)
        {
            if (!(sender is Document document))
            {
                return;
            }

            // Для команд автослоев - подписка на добавление объектов в чертеж
            Debug.WriteLine(e.GlobalCommandName);
            curAutoLayer = GetAutoLayerCommand(e.GlobalCommandName);
            if (curAutoLayer == null)
            {
                return;
            }
            idAddedEnts = new List <ObjectId>();

            // Подписка на события добавления объектов и завершения команды
            document.Database.ObjectAppended -= Database_ObjectAppended;
            document.Database.ObjectAppended += Database_ObjectAppended;
            document.CommandEnded            -= Doc_CommandEnded;
            document.CommandEnded            += Doc_CommandEnded;

            // При Esc объекты все равно могут быть успешно добавлены в чертеж (если зациклена командв добавления размера, есть такие)
            document.CommandCancelled -= Doc_CommandCancelled;
            document.CommandCancelled += Doc_CommandCancelled;
        }
示例#2
0
 public static void Stop()
 {
     Application.DocumentManager.DocumentActivated -= DocumentManager_DocumentActivated;
     UnsubscribeDocument(_doc);
     _doc         = null;
     curAutoLayer = null;
     idAddedEnts  = null;
     IsStarted    = false;
     Save();
 }
示例#3
0
        private static void AutoLayerEntities([NotNull] AutoLayer autoLayer, [NotNull] IEnumerable <ObjectId> autoLayerEnts)
        {
            var layId = autoLayer.Layer.CheckLayerState();

            foreach (var idEnt in autoLayerEnts)
            {
                var ent = idEnt.GetObject <Entity>(OpenMode.ForWrite);
                if (ent != null && ent.LayerId != layId)
                {
                    ent.LayerId = layId;
                }
            }
        }
示例#4
0
        private static void ProcessingAutoLayers([NotNull] AutoLayer currentAutoLayerAutoLayer, List <ObjectId> idsAddedEnt)
        {
            var autoLayerEnts = currentAutoLayerAutoLayer.GetAutoLayerEnts(idsAddedEnt);

            if (autoLayerEnts == null)
            {
                return;
            }
            using (var t = _doc.TransactionManager.StartTransaction())
            {
                AutoLayerEntities(currentAutoLayerAutoLayer, autoLayerEnts);
                t.Commit();
            }
        }
示例#5
0
        private static void EndCommand([CanBeNull] Document document, string globalCommandName)
        {
            curAutoLayer = GetAutoLayerCommand(globalCommandName);
            if (curAutoLayer == null || document == null)
            {
                return;
            }

            document.Database.ObjectAppended -= Database_ObjectAppended;
            document.CommandEnded            -= Doc_CommandEnded;

            // Обработка объектов
            ProcessingAutoLayers(curAutoLayer, idAddedEnts);
            curAutoLayer = null;
        }