Beispiel #1
0
        Stream(ArrayList data, PromptFileOptions promptFileOpts)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PromptFileOptions)));

            data.Add(new Snoop.Data.Bool("AllowUrls", promptFileOpts.AllowUrls));
            data.Add(new Snoop.Data.String("Dialog caption", promptFileOpts.DialogCaption));
            data.Add(new Snoop.Data.String("Dialog name", promptFileOpts.DialogName));
            data.Add(new Snoop.Data.String("Filter", promptFileOpts.Filter));
            data.Add(new Snoop.Data.Int("Filter index", promptFileOpts.FilterIndex));
            data.Add(new Snoop.Data.String("Initial directory", promptFileOpts.InitialDirectory));
            data.Add(new Snoop.Data.String("Initial file name", promptFileOpts.InitialFileName));
            data.Add(new Snoop.Data.String("Message", promptFileOpts.Message));
            data.Add(new Snoop.Data.Bool("Prefer command line", promptFileOpts.PreferCommandLine));

            PromptOpenFileOptions promptOpenFileOpts = promptFileOpts as PromptOpenFileOptions;

            if (promptOpenFileOpts != null)
            {
                Stream(data, promptOpenFileOpts);
                return;
            }

            PromptSaveFileOptions promptSaveFileOpts = promptFileOpts as PromptSaveFileOptions;

            if (promptSaveFileOpts != null)
            {
                Stream(data, promptSaveFileOpts);
                return;
            }
        }
Beispiel #2
0
        Stream(ArrayList data, PromptOpenFileOptions promptOpenFileOpts)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PromptOpenFileOptions)));

            data.Add(new Snoop.Data.Bool("Search path", promptOpenFileOpts.SearchPath));
            data.Add(new Snoop.Data.Bool("Transfer remote files", promptOpenFileOpts.TransferRemoteFiles));
        }
Beispiel #3
0
        public static void PythonLoad(bool useCmdLine)
        {
            Document doc =
              Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            short fd =
              (short)Application.GetSystemVariable("FILEDIA");

            // As the user to select a .py file

            PromptOpenFileOptions pfo =
                new PromptOpenFileOptions(
                  "Select Python script to load"
                );
            pfo.Filter = "Python script (*.py)|*.py";
            pfo.PreferCommandLine =
              (useCmdLine || fd == 0);
            PromptFileNameResult pr =
              ed.GetFileNameForOpen(pfo);

            // And then try to load and execute it

            if (pr.Status == PromptStatus.OK)
                ExecutePythonScript(pr.StringResult);
        }
Beispiel #4
0
 private static bool OpenNewDocument(string Name)
 {
     try
     {
         //Application.DocumentManager.Open(Name);
         new UtilityClass().ReadDocument(Name);
         return(true);
     }
     catch
     {
         try
         {
             PromptOpenFileOptions opts = new PromptOpenFileOptions("Select a drawing file (for a custom command)");
             opts.Filter = "Drawing (*.dwg)";
             PromptFileNameResult pr = Application.DocumentManager.MdiActiveDocument.Editor.GetFileNameForOpen(opts);
             if (pr.Status == PromptStatus.OK)
             {
                 //Application.DocumentManager.Open(pr.StringResult);
                 new UtilityClass().ReadDocument(pr.StringResult);
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch
         {
             return(false);
         }
     }
 }
Beispiel #5
0
        public void XrefAttachAtOrigin()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }
            var db = doc.Database;
            var ed = doc.Editor;

            // Ask the user to specify a file to attach

            var opts = new PromptOpenFileOptions("Select Reference File");

            opts.Filter = "Drawing (*.dwg)|*.dwg";
            var pr = ed.GetFileNameForOpen(opts);

            if (pr.Status == PromptStatus.OK)
            {
                // Attach the specified file and insert it at the origin

                var res = db.XrefAttachAndInsert(pr.StringResult, Point3d.Origin);

                ed.WriteMessage(
                    "External reference {0}attached at the origin.",
                    res ? "" : "not "
                    );
            }
        }
Beispiel #6
0
        getFilesWithEditor(string caption, string name, string filter, string directory, string message)
        {
            Editor ed = BaseObjs._editor;
            PromptOpenFileOptions pofo = null;

            try
            {
                pofo = new PromptOpenFileOptions("Select a file using Editor. GetFileNameForOpen()");
                pofo.DialogCaption = caption;
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " FileManager.cs: line: 183");
            }
            pofo.DialogName       = name;
            pofo.Filter           = filter;
            pofo.InitialDirectory = directory;
            pofo.Message          = message;

            PromptFileNameResult pfnr = ed.GetFileNameForOpen(pofo);

            if (pfnr.Status == PromptStatus.OK)
            {
                return(pfnr.StringResult);
            }
            return(null);
        }
Beispiel #7
0
        public void InsertUcsFromFileStart()
        {
            var pofo = new PromptOpenFileOptions("Select a file")
            {
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            };
            var res = _ed.GetFileNameForOpen(pofo);

            if (res.Status != PromptStatus.OK)
            {
                return;
            }
            using (var loc = _doc.LockDocument())
            {
                using (var destBaseTr = _db.TransactionManager.StartTransaction())
                {
                    var destUcsTable = (UcsTable)destBaseTr.GetObject(_db.UcsTableId, OpenMode.ForWrite);
                    using (var sourceDb = new Database(false, true))
                    {
                        sourceDb.ReadDwgFile(res.StringResult, FileOpenMode.OpenForReadAndAllShare, true, "");
                        using (var tr = sourceDb.TransactionManager.StartTransaction())
                        {
                            var sourceUcsTable = (UcsTable)tr.GetObject(sourceDb.UcsTableId, OpenMode.ForRead);
                            foreach (ObjectId uscRecordId in sourceUcsTable)
                            {
                                var ucsTr  = (UcsTableRecord)tr.GetObject(uscRecordId, OpenMode.ForRead);
                                var suffix = 1;
                                var name   = ucsTr.Name;
                                while (destUcsTable.Has(name))
                                {
                                    _editorHelper.WriteMessage(String.Format("UCS {0} exists!\n", ucsTr.Name));
                                    name = String.Format("{0}{1}", ucsTr.Name, String.Format("({0})", suffix));
                                    suffix++;
                                }

                                var x = new UcsTableRecord
                                {
                                    Name   = name,
                                    Origin = ucsTr.Origin,
                                    XAxis  = ucsTr.XAxis,
                                    YAxis  = ucsTr.YAxis
                                };
                                destUcsTable.Add(x);
                                destBaseTr.AddNewlyCreatedDBObject(x, true);
                            }
                        }
                    }
                    destBaseTr.Commit();
                }
            }
        }
        public static void RubyLoad(bool useCmdLine)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
              Editor ed = doc.Editor;

              short fd = (short)Application.GetSystemVariable("FILEDIA");

              PromptOpenFileOptions pfo = new PromptOpenFileOptions(
            "Select Ruby script to load");
              pfo.Filter = "Ruby script (*.rb)|*.rb";
              pfo.PreferCommandLine = (useCmdLine || fd == 0);
              PromptFileNameResult pr = ed.GetFileNameForOpen(pfo);

              if (pr.Status == PromptStatus.OK)
            ExecuteRubyScript(pr.StringResult);
        }
Beispiel #9
0
        public static void RubySpecUI()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            short fd = (short)Application.GetSystemVariable("FILEDIA");

            // Ask the user to select a .rb file
            PromptOpenFileOptions pfo =
                new PromptOpenFileOptions("Select Ruby script to load");

            pfo.Filter = "Ruby script (*.rb)|*.rb";
            PromptFileNameResult pr = ed.GetFileNameForOpen(pfo);

            // And then try to load and execute it
            if (pr.Status == PromptStatus.OK)
                runRspec(pr.StringResult);
        }
Beispiel #10
0
        public static void RubyLoad(bool useCmdLine)
        {
            short fd = (short)Application.GetSystemVariable("FILEDIA");

            // Ask the user to select a .rb file
            PromptOpenFileOptions pfo =
                new PromptOpenFileOptions("Select Ruby script to load");

            pfo.Filter = "Ruby script (*.rb)|*.rb";
            pfo.PreferCommandLine = (useCmdLine || fd == 0);
            PromptFileNameResult pr = ed.GetFileNameForOpen(pfo);

            // And then try to load and execute it
            if (pr.Status == PromptStatus.OK)
                ExecuteRubyScript(pr.StringResult);
        }
Beispiel #11
0
        [CommandMethod("gsi")] //Comanda revizuita care importa puncte din fisiere gsi
        public void ImportGSI()
        {
            //Selectia fisierelor gsi
            Document      acadDoc  = Application.DocumentManager.MdiActiveDocument;
            CivilDocument civilDoc = CivilApplication.ActiveDocument;
            Editor        ed       = acadDoc.Editor;
            Database      db       = HostApplicationServices.WorkingDatabase;

            PromptOpenFileOptions POFO = new PromptOpenFileOptions("Select gsi file: ");

            POFO.Filter = ".gsi";

            PromptFileNameResult FileRes = ed.GetFileNameForOpen(POFO);

            if (FileRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nFile selection failed! Aborting.");
                return;
            }
            string cale = FileRes.StringResult;

            PromptResult PSR = ed.GetString("\nSpecify points description");

            if (PSR.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nInvalid description! Aborting.");
                return;
            }
            string descriere = PSR.StringResult;

            String3D listaPuncte = new String3D();

            listaPuncte.ImportGSI(cale);

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                CogoPointCollection cogoPoints = civilDoc.CogoPoints;
                foreach (Punct3D punct in listaPuncte)
                {
                    ObjectId  pointId = cogoPoints.Add(new Point3d(punct.X, punct.Y, punct.Z));
                    CogoPoint cogo    = pointId.GetObject(OpenMode.ForWrite) as CogoPoint;
                    cogo.RawDescription = descriere;
                }
                trans.Commit();
            }
        }
Beispiel #12
0
        public void ZMachine()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }
            var ed = doc.Editor;

            var pofo = new PromptOpenFileOptions("File to load");
            var pfnr = ed.GetFileNameForOpen(pofo);

            if (pfnr.Status == PromptStatus.OK)
            {
                ExecuteGame(pfnr.StringResult, ed);
            }
        }
        public void OpenDwg()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //获取文档管理器对象以打开Dwg文件
            DocumentCollection docs = Application.DocumentManager;
            //设置打开文件对话框的有关选项
            PromptOpenFileOptions opt = new PromptOpenFileOptions("\n请输入文件名:");

            opt.Filter      = "图形(*.dwg)|*.dwg|图形(*.dxf)|*.dxf";
            opt.FilterIndex = 0;
            //根据打开文件对话框中用户的选择,获取文件名
            string filename = ed.GetFileNameForOpen(opt).StringResult;
            //打开所选择的Dwg文件
            Document doc = docs.Open(filename, true);

            //设置当前的活动文档为新打开的Dwg文件
            Application.DocumentManager.MdiActiveDocument = doc;
        }
Beispiel #14
0
        public void ReadConfigCommand()
        {
            PromptOpenFileOptions file_opt = new PromptOpenFileOptions("Укажите путь к файлу настроек ссылок");

            file_opt.Filter = "Файлы настроек ссылок (*.xml)|*.xml|Все файлы (*.*)|*.*";
            //file_opt.FilterIndex = 1;
            PromptFileNameResult file_res = Core.current_editor.GetFileNameForOpen(file_opt);

            if (file_res.Status == PromptStatus.OK)
            {
                Core.config = new Configuration(file_res.StringResult);
            }
            else
            {
                Core.WriteMessage("Пользователь отказался\n");
                return;
            }
            Core.WriteMessage("\n");
        }
Beispiel #15
0
        public void load_preview()
        {
            if (myPal == null) {
                this.preview();
            }
            //ask for a file using the open file dialog
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptOpenFileOptions op = new PromptOpenFileOptions("Select a File to Preview.");
            PromptFileNameResult fn = ed.GetFileNameForOpen(op);

            //did we get a file okay?
            if (fn.Status == PromptStatus.OK)
            {
                //use the loaded dwg file to update the preview box
                myPreviewBox.load_file_preview(fn.StringResult);
            }
            //show the palette just in case it's been closed
            myPal.Visible = true;
        }
Beispiel #16
0
        public static string GetRubyFile(bool useCmdLine)
        {
            string ret_val = string.Empty;
            short fd = (short)Application.GetSystemVariable("FILEDIA");

            // Ask the user to select a .rb file
            PromptOpenFileOptions pfo =
                new PromptOpenFileOptions("Select Ruby script to load");

            pfo.Filter = "Ruby script (*.rb)|*.rb";
            pfo.PreferCommandLine = (useCmdLine || fd == 0);
            PromptFileNameResult pr = ed.GetFileNameForOpen(pfo);

            // if they selected a file, return it
            if (pr.Status == PromptStatus.OK)
            {
                ret_val = pr.StringResult;
            }
            return ret_val;
        }
Beispiel #17
0
        public void load_preview()
        {
            if (myPal == null)
            {
                this.preview();
            }
            //ask for a file using the open file dialog
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptOpenFileOptions op = new PromptOpenFileOptions("Select a File to Preview.");
            PromptFileNameResult  fn = ed.GetFileNameForOpen(op);

            //did we get a file okay?
            if (fn.Status == PromptStatus.OK)
            {
                //use the loaded dwg file to update the preview box
                myPreviewBox.load_file_preview(fn.StringResult);
            }
            //show the palette just in case it's been closed
            myPal.Visible = true;
        }
Beispiel #18
0
        public static void PythonLoad(bool useCmdLine)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;

            short fd = (short)Application.GetSystemVariable("FILEDIA");

            // As the user to select a .py file

            PromptOpenFileOptions pfo = new PromptOpenFileOptions("Select Python Script to load");

            pfo.Filter            = "Python Script (*.py)|*.py";
            pfo.PreferCommandLine = (useCmdLine || fd == 0);
            PromptFileNameResult pr = ed.GetFileNameForOpen(pfo);

            // And then try to load and execute it

            if (pr.Status == PromptStatus.OK)
            {
                ExecutePythonScript(pr.StringResult);
            }
        }
        /// <summary>
        /// Запрос пользователя для выбора файла шаблона
        /// </summary>
        /// <returns>True, если был выбран корректный файл шаблона, иначе false</returns>
        private bool SelectTemplate()
        {
            Configuration.AppConfig cfg  = Configuration.AppConfig.Instance;
            PromptOpenFileOptions   pofo = new PromptOpenFileOptions(CP.TemplateFileQuery);

            pofo.Filter          = CP.TemplateFileQueryFilter;
            pofo.InitialFileName = cfg.TemplatePath;

            PromptFileNameResult templateName = ed.GetFileNameForOpen(pofo);

            if (templateName.Status == PromptStatus.OK)
            {
                if (!System.IO.File.Exists(templateName.StringResult))
                {
                    throw new System.IO.FileNotFoundException(templateName.StringResult);
                }
                cfg.TemplatePath = templateName.StringResult;
                cfg.Save();
                return(true);
            }

            return(false);
        }
Beispiel #20
0
        public static string GetFilename(
            this Editor ed, string prompt, bool openFile = true
            )
        {
            PromptFileNameResult pfnr;

            if (openFile)
            {
                var pofo = new PromptOpenFileOptions(prompt);
                pfnr = ed.GetFileNameForOpen(pofo);
            }
            else
            {
                var psfo = new PromptSaveFileOptions(prompt);
                pfnr = ed.GetFileNameForSave(psfo);
            }

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

            return(pfnr.StringResult);
        }
Beispiel #21
0
        private void PythonConsole(bool cmdLine)
        {
            Dictionary <string, object> options = new Dictionary <string, object>();

            options["Debug"] = true;

            var ipy    = Python.CreateRuntime(options);
            var engine = Python.GetEngine(ipy);

            try
            {
                string path = "";

                System.Version version = Application.Version;

                string ver = version.ToString().Split(new char[] { '.' })[0];

                string release = "2020";

                switch (ver)
                {
                case "20":
                    release = "2016";
                    break;

                case "21":
                    release = "2017";
                    break;

                case "22":
                    release = "2018";
                    break;

                case "23":
                    release = "2019";
                    break;

                case "24":
                    release = "2020";
                    break;
                }

                if (!cmdLine)
                {
                    WF.OpenFileDialog ofd = new WF.OpenFileDialog();
                    ofd.Filter = "Python Script (*.py) | *.py";

                    if (ofd.ShowDialog() == WF.DialogResult.OK)
                    {
                        path = ofd.FileName;
                    }
                }
                else
                {
                    Document doc = Application.DocumentManager.MdiActiveDocument;
                    Editor   ed  = doc.Editor;

                    short fd = (short)Application.GetSystemVariable("FILEDIA");

                    // Ask the user to select a .py file

                    PromptOpenFileOptions pfo = new PromptOpenFileOptions("Select Python script to load");
                    pfo.Filter            = "Python script (*.py)|*.py";
                    pfo.PreferCommandLine = (cmdLine || fd == 0);
                    PromptFileNameResult pr = ed.GetFileNameForOpen(pfo);
                    path = pr.StringResult;
                }

                if (path != "")
                {
                    ipy.LoadAssembly(Assembly.LoadFrom(string.Format(@"C:\Program Files\Autodesk\AutoCAD {0}\acmgd.dll", release)));
                    ipy.LoadAssembly(Assembly.LoadFrom(string.Format(@"C:\Program Files\Autodesk\AutoCAD {0}\acdbmgd.dll", release)));
                    ipy.LoadAssembly(Assembly.LoadFrom(string.Format(@"C:\Program Files\Autodesk\AutoCAD {0}\accoremgd.dll", release)));
                    ipy.LoadAssembly(Assembly.LoadFrom(string.Format(@"C:\Program Files\Autodesk\AutoCAD {0}\ACA\AecBaseMgd.dll", release)));
                    ipy.LoadAssembly(Assembly.LoadFrom(string.Format(@"C:\Program Files\Autodesk\AutoCAD {0}\ACA\AecPropDataMgd.dll", release)));
                    ipy.LoadAssembly(Assembly.LoadFrom(string.Format(@"C:\Program Files\Autodesk\AutoCAD {0}\C3D\AeccDbMgd.dll", release)));
                    ipy.LoadAssembly(Assembly.LoadFrom(string.Format(@"C:\Program Files\Autodesk\AutoCAD {0}\C3D\AeccPressurePipesMgd.dll", release)));
                    ipy.LoadAssembly(Assembly.LoadFrom(string.Format(@"C:\Program Files\Autodesk\AutoCAD {0}\acdbmgdbrep.dll", release)));


                    ScriptSource source       = engine.CreateScriptSourceFromFile(path);
                    CompiledCode compiledCode = source.Compile();
                    ScriptScope  scope        = engine.CreateScope();
                    compiledCode.Execute(scope);
                }
            }
            catch (System.Exception ex)
            {
                string message = engine.GetService <ExceptionOperations>().FormatException(ex);
                WF.MessageBox.Show(message);
            }

            return;
        }
Beispiel #22
0
        public static void PurgeDgnLinetypesExt()
        {
            var doc =
                Application.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;

            var pofo = new PromptOpenFileOptions("\nSelect file to purge");

            // Use the command-line version if FILEDIA is 0 or
            // CMDACTIVE indicates we're being called from a script
            // or from LISP

            short fd = (short)Application.GetSystemVariable("FILEDIA");
            short ca = (short)Application.GetSystemVariable("CMDACTIVE");

            pofo.PreferCommandLine = (fd == 0 || (ca & 36) > 0);
            pofo.Filter            = "DWG (*.dwg)|*.dwg|All files (*.*)|*.*";

            // Ask the user to select a DWG file to purge

            var pfnr = ed.GetFileNameForOpen(pofo);

            if (pfnr.Status == PromptStatus.OK)
            {
                // Make sure the file exists
                // (it should unless entered via the command-line)

                if (!File.Exists(pfnr.StringResult))
                {
                    ed.WriteMessage(
                        "\nCould not find file: \"{0}\".",
                        pfnr.StringResult
                        );
                    return;
                }

                try
                {
                    // We'll just suffix the selected filename with "-purged"
                    // for the output location. This file will be overwritten
                    // if the command is called multiple times

                    var output =
                        Path.GetDirectoryName(pfnr.StringResult) + "\\" +
                        Path.GetFileNameWithoutExtension(pfnr.StringResult) +
                        "-purged" +
                        Path.GetExtension(pfnr.StringResult);

                    // Assume a post-R12 drawing

                    using (var db = new ACADDB.Database(false, true))
                    {
                        // Read the DWG file into our Database object

                        db.ReadDwgFile(
                            pfnr.StringResult,
                            FileOpenMode.OpenForReadAndReadShare,
                            false,
                            ""
                            );

                        // No graphical changes, so we can keep the preview
                        // bitmap

                        db.RetainOriginalThumbnailBitmap = true;

                        // We'll store the current working database, to reset
                        // after the purge operation

                        var wdb = HostApplicationServices.WorkingDatabase;
                        HostApplicationServices.WorkingDatabase = db;

                        // Purge unused DGN linestyles from the drawing
                        // (returns false if nothing is erased)

                        if (PurgeDgnLinetypesInDb(db, ed))
                        {
                            // Check the version of the drawing to save back to

                            var ver =
                                (db.LastSavedAsVersion == DwgVersion.MC0To0
                                    ? DwgVersion.Current
                                    : db.LastSavedAsVersion
                                );

                            // Now we can save

                            db.SaveAs(output, ver);

                            ed.WriteMessage(
                                "\nSaved purged file to \"{0}\".",
                                output
                                );
                        }

                        // Still need to reset the working database

                        HostApplicationServices.WorkingDatabase = wdb;
                    }
                }
                catch (ACADRT.Exception ex)
                {
                    ed.WriteMessage("\nException: {0}", ex.Message);
                }
            }
        }
        /// <summary>
        /// Запрос пользователя для выбора файла шаблона
        /// </summary>
        /// <returns>True, если был выбран корректный файл шаблона, иначе false</returns>
        private bool SelectTemplate()
        {
            Configuration.AppConfig cfg = Configuration.AppConfig.Instance;
            PromptOpenFileOptions pofo = new PromptOpenFileOptions(CP.TemplateFileQuery);
            pofo.Filter = CP.TemplateFileQueryFilter;
            pofo.InitialFileName = cfg.TemplatePath;

            PromptFileNameResult templateName = ed.GetFileNameForOpen(pofo);

            if (templateName.Status == PromptStatus.OK)
            {
                if (!System.IO.File.Exists(templateName.StringResult))
                    throw new System.IO.FileNotFoundException(templateName.StringResult);
                cfg.TemplatePath = templateName.StringResult;
                cfg.Save();
                return true;
            }

            return false;
        }
Beispiel #24
0
        public void SetDataLink() // This method can have any name
        {
            // Put your command code here
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //获取目录表格的容量
            int NumberPerPage = 1;
            PromptIntegerOptions GetNumberOption = new PromptIntegerOptions("\n输入每张表格的最大容量");

            GetNumberOption.AllowNegative = false;
            GetNumberOption.AllowZero     = false;
            PromptIntegerResult GetNumberResult = ed.GetInteger(GetNumberOption);

            if (GetNumberResult.Status == PromptStatus.OK)
            {
                NumberPerPage = GetNumberResult.Value;
            }
            else
            {
                return;
            }
            //获取图纸目录数据文件
            string DataFile = "";
            PromptOpenFileOptions fileoption = new PromptOpenFileOptions("\n输入链接数据文件路径");

            fileoption.InitialDirectory = System.IO.Path.GetDirectoryName(db.Filename);
            fileoption.Filter           = "Excel Documents (*.xlsx) |*.xlsx";
            PromptFileNameResult DataFileResult = ed.GetFileNameForOpen(fileoption);

            if (DataFileResult.Status == PromptStatus.OK)
            {
                DataFile = DataFileResult.StringResult;
            }
            else
            {
                return;
            }
            //获取数据表范围信息
            string       SheetName    = "图纸目录";
            string       StartCol     = "A";
            string       EndCol       = "E";
            int          StartRow     = 2;
            PromptResult GetSheetName = ed.GetString("\n输入链接数据表名称");

            if (GetSheetName.Status == PromptStatus.OK)
            {
                SheetName = GetSheetName.StringResult;
            }
            else
            {
                return;
            }
            PromptResult GetStartCol = ed.GetString("\n输入数据起始列");

            if (GetStartCol.Status == PromptStatus.OK)
            {
                StartCol = GetStartCol.StringResult;
            }
            else
            {
                return;
            }
            PromptResult GetEndCol = ed.GetString("\n输入数据结束列");

            if (GetEndCol.Status == PromptStatus.OK)
            {
                EndCol = GetEndCol.StringResult;
            }
            else
            {
                return;
            }
            PromptIntegerResult GetStartRow = ed.GetInteger("\n输入数据起始行");

            if (GetStartRow.Status == PromptStatus.OK)
            {
                StartRow = GetStartRow.Value;
            }
            else
            {
                return;
            }
            using (Transaction Trans = db.TransactionManager.StartTransaction())
            {
                DBDictionary Layouts    = Trans.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
                ArrayList    Layoutlist = new ArrayList();
                foreach (DBDictionaryEntry item in Layouts)
                {
                    if (item.Key != "Model")
                    {
                        Layoutlist.Add(item.Key);
                    }
                }
                //int NumberOfList = Layoutlist.Count;
                ArrayList TableIDs = new ArrayList();
                foreach (string name in Layoutlist)
                {
                    TypedValue[] Filter = new TypedValue[]
                    {
                        new TypedValue((int)DxfCode.Operator, "<and"),
                        new TypedValue((int)DxfCode.LayoutName, name),
                        new TypedValue((int)DxfCode.Start, "ACAD_TABLE"),
                        new TypedValue((int)DxfCode.Operator, "and>"),
                    };
                    PromptSelectionResult selresult = ed.SelectAll(new SelectionFilter(Filter));
                    if (selresult.Status == PromptStatus.OK)
                    {
                        ObjectId[] ids = selresult.Value.GetObjectIds();
                        TableIDs.Add(ids[0]);
                    }
                }
                int NumberOfTables = TableIDs.Count;

                /*
                 * ed.WriteMessage("\nLayout:{0}", Layoutlist.Count);
                 * foreach(string name in Layoutlist)
                 * {
                 *  ed.WriteMessage("\nLayoutname:{0}", name);
                 * }
                 * ed.WriteMessage("\nTables:{0}", TableIDs.Count);
                 */
                DataLinkManager dlm = db.DataLinkManager;
                try
                {
                    for (int i = 0; i < NumberOfTables; i++)
                    {
                        Autodesk.AutoCAD.DatabaseServices.DataLink dl = new Autodesk.AutoCAD.DatabaseServices.DataLink();
                        dl.DataAdapterId = "AcExcel";
                        dl.Name          = SheetName + (i + 1).ToString();
                        dl.Description   = SheetName + "数据链接" + (i + 1).ToString();
                        string location = string.Format("!{0}!{1}{2}:{3}{4}", SheetName, StartCol, (StartRow + i * NumberPerPage), EndCol, ((1 + i) * NumberPerPage) + StartRow - 1);
                        dl.ConnectionString = DataFile + location;
                        dl.DataLinkOption   = DataLinkOption.PersistCache;
                        dl.UpdateOption    |= (int)UpdateOption.AllowSourceUpdate | (int)UpdateOption.SkipFormat;
                        ObjectId dlId = dlm.AddDataLink(dl);
                        ed.WriteMessage("\n链接字符串:{0}", dl.ConnectionString);
                        Trans.AddNewlyCreatedDBObject(dl, true);
                        Table tb = (Table)Trans.GetObject((ObjectId)TableIDs[i], OpenMode.ForWrite);
                        tb.Cells[1, 0].DataLink = dlId;
                        tb.GenerateLayout();
                    }
                    Trans.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception Ex)
                {
                    ed.WriteMessage("\n出错啦!" + Ex.ToString());
                }
                finally
                {
                    Trans.Dispose();
                }
            }
        }
Beispiel #25
0
        public static void ReadICD()
        {
            // CAD指针
            CivilDocument civildoc = CivilApplication.ActiveDocument;
            Document      doc      = Application.DocumentManager.MdiActiveDocument;
            Database      acCurDb  = doc.Database;
            Editor        ed       = doc.Editor;


            PromptOpenFileOptions opt = new PromptOpenFileOptions("\n请选择线型文件.");

            opt.Filter = "ICD File (*.icd)|*.icd|All files (*.*)|*.*";
            PromptFileNameResult res = ed.GetFileNameForOpen(opt);

            if (res.Status != PromptStatus.OK)
            {
                return;
            }
            SRBA.PM bill = new SRBA.PM(res.StringResult);

            // 转化平曲线
            ObjectId AlgID = Alignment.Create(civildoc, Path.GetFileNameWithoutExtension(res.StringResult), null, "0", "Basic", "All Labels");

            using (Transaction ts = acCurDb.TransactionManager.StartTransaction())
            {
                Alignment myAg = ts.GetObject(AlgID, OpenMode.ForWrite) as Alignment;
                AddICD(ref myAg, ref bill, ref ed);
                myAg.ReferencePointStation = bill.StartPK;
                //ed.WriteMessage("\n{0}读取成功.", res.StringResult);


                // 竖曲线
                PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("\n是否加载竖曲线?");
                pKeyOpts.Keywords.Add("Y");
                pKeyOpts.Keywords.Add("N");
                pKeyOpts.Keywords.Default = "Y";
                pKeyOpts.AllowNone        = true;
                PromptResult pKeyRes = doc.Editor.GetKeywords(pKeyOpts);
                switch (pKeyRes.Status)
                {
                case PromptStatus.OK:
                    if (pKeyRes.StringResult == "Y")
                    {
                        SRBA.SQX kitty      = new SRBA.SQX(Path.ChangeExtension(res.StringResult, "SQX"));
                        ObjectId layerId    = myAg.LayerId;
                        ObjectId styleId    = civildoc.Styles.ProfileStyles["Basic"];
                        ObjectId labelSetId = civildoc.Styles.LabelSetStyles.ProfileLabelSetStyles["Complete Label Set"];
                        ObjectId oProfileId = Profile.CreateByLayout(myAg.Name + "-Profile", myAg.ObjectId, layerId, styleId, labelSetId);
                        Profile  oProfile   = ts.GetObject(oProfileId, OpenMode.ForWrite) as Profile;

                        AddSQX(ref oProfile, ref kitty, ref ed);
                    }
                    break;

                default:
                    break;
                }


                // 转化对比JD法
                //pKeyOpts = new PromptKeywordOptions("\n是否加载交点法平曲线?");
                //pKeyOpts.Keywords.Add("Y");
                //pKeyOpts.Keywords.Add("N");
                //pKeyOpts.Keywords.Default = "Y";
                //pKeyOpts.AllowNone = true;
                //pKeyRes = doc.Editor.GetKeywords(pKeyOpts);
                //switch (pKeyRes.Status)
                //{
                //    case PromptStatus.OK:
                //        if (pKeyRes.StringResult == "Y")
                //        {

                //            PQXnew kitty = new PQXnew("Test");
                //            kitty.ReadICDFile(res.StringResult);
                //            ObjectId layerId = myAg.LayerId;
                //            ObjectId styleId = civildoc.Styles.ProfileStyles["Basic"];
                //            ObjectId labelSetId = civildoc.Styles.LabelSetStyles.ProfileLabelSetStyles["Complete Label Set"];
                //            ObjectId oProfileId = Profile.CreateByLayout(myAg.Name + "-Profile", myAg.ObjectId, layerId, styleId, labelSetId);
                //            Profile oProfile = ts.GetObject(oProfileId, OpenMode.ForWrite) as Profile;

                //            AddPQX( 0,24000,500, ref acCurDb, ref kitty, ref ed);
                //        }
                //        break;
                //    default:
                //        break;
                //}



                ts.Commit();
            }
        }
Beispiel #26
0
        public void MyCommand() // This method can have any name
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            using (Transaction Trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    PromptOpenFileOptions fileoptions = new PromptOpenFileOptions("\n输入要插入的图形文件");
                    fileoptions.Filter = "dwg图形文件(*.dwg)|*.dwg";
                    string filename = "";
                    PromptFileNameResult fileresult = ed.GetFileNameForOpen(fileoptions);
                    if (fileresult.Status == PromptStatus.OK)
                    {
                        filename = fileresult.StringResult;
                        if (!File.Exists(filename))
                        {
                            ed.WriteMessage("\n文件路径无效!");
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                    //自动脚本,去掉插入点输入
                    //PromptPointResult pointResult = ed.GetPoint("\n输入插入点");
                    Point3d insertpoint = new Point3d(0, 0, 0);

                    /*
                     * if (pointResult.Status == PromptStatus.OK)
                     * {
                     *  insertpoint = pointResult.Value;
                     * }
                     * else
                     * {
                     *  return;
                     * }
                     */

                    //获取布局列表(剔除模型空间)
                    DBDictionary Layouts    = Trans.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
                    ArrayList    Layoutlist = new ArrayList();
                    foreach (DBDictionaryEntry item in Layouts)
                    {
                        if (item.Key != "Model")
                        {
                            Layout layoutobject = Trans.GetObject(item.Value, OpenMode.ForRead) as Layout;
                            Layoutlist.Add(layoutobject);
                        }
                    }


                    foreach (Layout LT in Layoutlist)
                    {
                        ObjectId xrefID = db.AttachXref(filename, Path.GetFileNameWithoutExtension(filename));
                        if (!xrefID.IsNull)
                        {
                            BlockReference   xref = new BlockReference(insertpoint, xrefID);
                            BlockTableRecord BTR  = Trans.GetObject(LT.BlockTableRecordId, OpenMode.ForWrite) as BlockTableRecord;
                            BTR.AppendEntity(xref);
                            Trans.AddNewlyCreatedDBObject(xref, true);
                        }

                        //Layout LT = Layoutlist[0] as Layout;
                        //BlockTableRecord BTR = Trans.GetObject(LT.BlockTableRecordId, OpenMode.ForWrite) as BlockTableRecord;
                        //BTR.AppendEntity(xref);
                        // Trans.AddNewlyCreatedDBObject(xref,true);
                    }


                    Trans.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception Ex)
                {
                    ed.WriteMessage("出错啦!{0}", Ex.ToString());
                }
                finally
                {
                    Trans.Dispose();
                }
            }
        }