Example #1
0
        public void bx_OpenTamplate()
        {
            App.Document doc = App.Application.DocumentManager.MdiActiveDocument;
            if (doc == null)
            {
                return;
            }

            string strFileName = CheckLocalRepository.GetRepository();

            App.DocumentCollection acDocMgr = App.Application.DocumentManager;

            if (System.IO.File.Exists(strFileName))
            {
                //Для 2011 автокада
#if acad2011
                acDocMgr.Open(strFileName, false);
#endif
                //Для 2012 и выше
#if !acad2011
                App.DocumentCollectionExtension.Open(acDocMgr, strFileName, false);
#endif
            }
            else
            {
                acDocMgr.MdiActiveDocument.Editor.
                WriteMessage($"Файла репозитория { strFileName} не существует.");
            }
        }
Example #2
0
        /// <summary>
        /// Загрузка библиотеки
        /// http://through-the-interface.typepad.com/through_the_interface/2007/03/getting_the_lis.html
        /// </summary>
        #region
        public void Initialize()
        {
            String assemblyFileFullName = GetType().Assembly.Location;
            String assemblyName         = System.IO.Path.GetFileName(
                GetType().Assembly.Location);

            // Just get the commands for this assembly
            App.DocumentCollection dm = App.Application.DocumentManager;
            Assembly asm = Assembly.GetExecutingAssembly();

            Ed.Editor acEd = dm.MdiActiveDocument.Editor;

            // Сообщаю о том, что произведена загрузка сборки
            //и указываю полное имя файла,
            // дабы было видно, откуда она загружена
            acEd.WriteMessage(string.Format("\n{0} {1} {2}.\n{3}: {4}\n{5}\n",
                                            "Assembly", assemblyName, "Loaded",
                                            "Assembly File:", assemblyFileFullName,
                                            "Copyright © Владимир Шульжицкий, 2017"));


            //Вывожу список комманд определенных в библиотеке
            acEd.WriteMessage("\nStart list of commands: \n\n");

            string[] cmds = GetCommands(asm, false);
            foreach (string cmd in cmds)
            {
                acEd.WriteMessage(cmd + "\n");
            }

            acEd.WriteMessage("\n\nEnd list of commands.\n");
        }
Example #3
0
        EnableEvents()
        {
            AcApp.DocumentCollection docs = AcApp.Application.DocumentManager;

            docs.DocumentCreated       += new AcApp.DocumentCollectionEventHandler(event_DocumentCreated);
            docs.DocumentToBeDestroyed += new AcApp.DocumentCollectionEventHandler(event_DocumentToBeDestroyed);
        }
Example #4
0
        DisableEvents()
        {
            AcApp.DocumentCollection docs = AcApp.Application.DocumentManager;

            // Throws an assert when the SnoopEd command is used. Need to investigate this further.
            //docs.DocumentCreated -= new AcApp.DocumentCollectionEventHandler(event_DocumentCreated);

            docs.DocumentToBeDestroyed -= new AcApp.DocumentCollectionEventHandler(event_DocumentToBeDestroyed);
        }
Example #5
0
        Stream(ArrayList data, AcAp.DocumentCollection docCol)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(AcAp.DocumentCollection)));

            data.Add(new Snoop.Data.Bool("Document activation enabled", docCol.DocumentActivationEnabled));
            data.Add(new Snoop.Data.Bool("Is application context", docCol.IsApplicationContext));
            data.Add(new Snoop.Data.Int("Count", docCol.Count));
            data.Add(new Snoop.Data.Object("MDI active document", docCol.MdiActiveDocument));
            data.Add(new Snoop.Data.Enumerable("Documents", docCol));
        }
        public void ImportBlocks()
        {
            AcadApp.DocumentCollection dm = AcadApp.Application.DocumentManager;
            Editor       ed       = dm.MdiActiveDocument.Editor;
            Database     destDb   = dm.MdiActiveDocument.Database;
            Database     sourceDb = new Database(false, true);
            PromptResult sourceFileName;

            try
            {
                //从命令行要求用户输入以得到要导入的块所在的源DWG文件的名字
                sourceFileName = ed.GetString("\nEnter the name of the source drawing: ");
                //把源DWG读入辅助数据库
                sourceDb.ReadDwgFile(sourceFileName.StringResult, System.IO.FileShare.Write, true, "");
                //用集合变量来存储块ID的列表
                ObjectIdCollection blockIds = new ObjectIdCollection();
                Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =
                    sourceDb.TransactionManager;
                using (Transaction myT = tm.StartTransaction())
                {
                    //打开块表
                    BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId,
                                                             OpenMode.ForRead, false);
                    //在块表中检查每个块
                    foreach (ObjectId btrId in bt)
                    {
                        BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId,
                                                                              OpenMode.ForRead, false);
                        //只添加有名块和非layout块(layout块是非MS和非PS的块)
                        if (!btr.IsAnonymous && !btr.IsLayout)
                        {
                            blockIds.Add(btrId);
                        }
                        btr.Dispose(); //释放块表记录引用变量所占用的资源
                    }
                    bt.Dispose();      //释放块表引用变量所占用的资源
                    //没有作改变,不需要提交事务
                    myT.Dispose();
                }

                IdMapping mapping = new IdMapping();
                mapping = sourceDb.WblockCloneObjects(blockIds, destDb.BlockTableId, DuplicateRecordCloning.Replace, false);

                ed.WriteMessage("\nCopied " + blockIds.Count.ToString() + " block definitions from " + sourceFileName.StringResult + " to the current drawing.");
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage("\nError during copy: " + ex.Message);
            }
            sourceDb.Dispose();
        }
        public static void bn11009()
        {
            string strFileName = "e:\\grid.dwg";

            AcadApp.DocumentCollection acDocMgr = AcadApp.Application.DocumentManager;

            if (System.IO.File.Exists(strFileName))
            {
                acDocMgr.Open(strFileName, false);
                acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName + "  exist.");
            }

            else
            {
                acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName + " does not exist.");
            }
        }
Example #8
0
        InitDocsTab()
        {
            m_tvDocs.BeginUpdate();

            // get all documents
            AcApp.DocumentCollection docs = AcApp.Application.DocumentManager;
            int count = docs.Count;

            foreach (AcApp.Document doc in docs)
            {
                TreeNode treeNode = new TreeNode(doc.Name);
                treeNode.Tag = (AcApp.Document)doc;
                m_tvDocs.Nodes.Add(treeNode);
            }
            // initial select condition
            m_tvDocs.SelectedNode = m_tvDocs.Nodes[0];
            m_tvDocs.EndUpdate();
        }
Example #9
0
        DisableEventsImp()
        {
            Utils.AcadUi.PrintToCmdLine("\nDocument Manager Events Turned Off ...\n");

            AcApp.DocumentCollection docs = AcApp.Application.DocumentManager;

            docs.DocumentActivated            -= new AcApp.DocumentCollectionEventHandler(event_DocumentActivated);
            docs.DocumentActivationChanged    -= new AcApp.DocumentActivationChangedEventHandler(event_DocumentActivationChanged);
            docs.DocumentBecameCurrent        -= new AcApp.DocumentCollectionEventHandler(event_DocumentBecameCurrent);
            docs.DocumentCreated              -= new AcApp.DocumentCollectionEventHandler(event_DocumentCreated);
            docs.DocumentCreateStarted        -= new AcApp.DocumentCollectionEventHandler(event_DocumentCreateStarted);
            docs.DocumentCreationCanceled     -= new AcApp.DocumentCollectionEventHandler(event_DocumentCreationCanceled);
            docs.DocumentDestroyed            -= new AcApp.DocumentDestroyedEventHandler(event_DocumentDestroyed);
            docs.DocumentLockModeChanged      -= new AcApp.DocumentLockModeChangedEventHandler(event_DocumentLockModeChanged);
            docs.DocumentLockModeChangeVetoed -= new AcApp.DocumentLockModeChangeVetoedEventHandler(event_DocumentLockModeChangeVetoed);
            docs.DocumentLockModeWillChange   -= new AcApp.DocumentLockModeWillChangeEventHandler(event_DocumentLockModeWillChange);
            docs.DocumentToBeActivated        -= new AcApp.DocumentCollectionEventHandler(event_DocumentToBeActivated);
            docs.DocumentToBeDeactivated      -= new AcApp.DocumentCollectionEventHandler(event_DocumentToBeDeactivated);
            docs.DocumentToBeDestroyed        -= new AcApp.DocumentCollectionEventHandler(event_DocumentToBeDestroyed);
        }
Example #10
0
        /// <summary>
        /// Загрузка библиотеки
        /// http://through-the-interface.typepad.com/through_the_interface/2007/03/getting_the_lis.html
        /// </summary>
        #region
        public void Initialize()
        {
            String assemblyFileFullName = GetType().Assembly.Location;
            String assemblyName         = System.IO.Path.GetFileName(
                GetType().Assembly.Location);

            // Just get the commands for this assembly
            App.DocumentCollection dm = App.Application.DocumentManager;
            Assembly asm = Assembly.GetExecutingAssembly();

            // Сообщаю о том, что произведена загрузка сборки
            //и указываю полное имя файла,
            // дабы было видно, откуда она загружена

            Ed.Editor     editor        = App.Application.DocumentManager.MdiActiveDocument.Editor;
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"\n Assembly, {assemblyName}, Loaded");
            stringBuilder.AppendLine($"\nAssembly File:{ assemblyFileFullName}");
            stringBuilder.AppendLine("\nДанная программа предназначена, на данный момент,");
            stringBuilder.AppendLine("только для удаления невидимых объектов, некоей \"Siberia\"");
            stringBuilder.AppendLine("(предположительно, Autodesk СПДС, без наличия оного)");
            stringBuilder.AppendLine("\nCopyright © ООО \'НСК-Проект\' written by Владимир Шульжицкий, 01.2020");
            editor.WriteMessage(stringBuilder.ToString());

            //Вывожу список комманд определенных в библиотеке
            App.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
                ("\nСписок команд реализованных в библиотеке: \n\n");

            string[] cmds = GetCommands(asm, false);
            foreach (string cmd in cmds)
            {
                App.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
                    (cmd + "\n");
            }

            App.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
                ("\n\nКонец списка.\n");
        }
Example #11
0
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false);    // why did someone else send us the message?
                return;
            }

            // branch to all types we are concerned with
            System.Type type = e.ObjToSnoop as System.Type;
            if (type != null)
            {
                Stream(snoopCollector.Data(), type);
                return;
            }

            System.Version ver = e.ObjToSnoop as System.Version;
            if (ver != null)
            {
                Stream(snoopCollector.Data(), ver);
                return;
            }

            System.Collections.Specialized.StringCollection strCol = e.ObjToSnoop as System.Collections.Specialized.StringCollection;
            if (strCol != null)
            {
                Stream(snoopCollector.Data(), strCol);
                return;
            }

            AcAp.Document doc = e.ObjToSnoop as AcAp.Document;
            if (doc != null)
            {
                Stream(snoopCollector.Data(), doc);
                return;
            }

            AcAp.DocumentCollectionEventArgs docCollectEventArgs = e.ObjToSnoop as AcAp.DocumentCollectionEventArgs;
            if (docCollectEventArgs != null)
            {
                Stream(snoopCollector.Data(), docCollectEventArgs);
                return;
            }

            AcAp.DocumentLockModeWillChangeEventArgs docLockModeEventArgs = e.ObjToSnoop as AcAp.DocumentLockModeWillChangeEventArgs;
            if (docLockModeEventArgs != null)
            {
                Stream(snoopCollector.Data(), docLockModeEventArgs);
                return;
            }

            AcAp.DocumentLockModeChangedEventArgs docLockModeChangedEventArgs = e.ObjToSnoop as AcAp.DocumentLockModeChangedEventArgs;
            if (docLockModeChangedEventArgs != null)
            {
                Stream(snoopCollector.Data(), docLockModeChangedEventArgs);
                return;
            }

            AcAp.DocumentLockModeChangeVetoedEventArgs docLockModeVetoedEventArgs = e.ObjToSnoop as AcAp.DocumentLockModeChangeVetoedEventArgs;
            if (docLockModeVetoedEventArgs != null)
            {
                Stream(snoopCollector.Data(), docLockModeVetoedEventArgs);
                return;
            }

            AcAp.DocumentDestroyedEventArgs docDestroyedEventArgs = e.ObjToSnoop as AcAp.DocumentDestroyedEventArgs;
            if (docDestroyedEventArgs != null)
            {
                Stream(snoopCollector.Data(), docDestroyedEventArgs);
                return;
            }

            AcAp.DocumentCollection docCollection = e.ObjToSnoop as AcAp.DocumentCollection;
            if (docCollection != null)
            {
                Stream(snoopCollector.Data(), docCollection);
                return;
            }

            AcAp.XrefFileLock xrefFileLock = e.ObjToSnoop as AcAp.XrefFileLock;
            if (xrefFileLock != null)
            {
                Stream(snoopCollector.Data(), xrefFileLock);
                return;
            }

            Autodesk.AutoCAD.Windows.Window win = e.ObjToSnoop as Autodesk.AutoCAD.Windows.Window;
            if (win != null)
            {
                Stream(snoopCollector.Data(), win);
                return;
            }

            Autodesk.AutoCAD.Windows.StatusBar statusBar = e.ObjToSnoop as Autodesk.AutoCAD.Windows.StatusBar;
            if (statusBar != null)
            {
                Stream(snoopCollector.Data(), statusBar);
                return;
            }

            Autodesk.AutoCAD.Windows.StatusBarItem statusBarItem = e.ObjToSnoop as Autodesk.AutoCAD.Windows.StatusBarItem;
            if (statusBarItem != null)
            {
                Stream(snoopCollector.Data(), statusBarItem);
                return;
            }
        }