Exemplo n.º 1
0
        /// <summary>
        /// Сохранить копию документа
        /// </summary>
        /// <param name="swModelMan"></param>
        /// <param name="folder">Папка сохранения</param>
        /// <param name="name">Имя файла с расширением</param>
        /// <returns></returns>
        public static bool SaveCopy(SwModelManager swModelMan, string folder = null, string name = null)
        {
            bool      ret     = false;
            int       lineNum = 13;
            const int offset  = 23;

            Console.CursorLeft = 0;

            if (string.IsNullOrEmpty(folder))
            {
                folder = swModelMan.FolderPath;
            }

            if (string.IsNullOrEmpty(name))
            {
                name = swModelMan.FileName;
            }


            StringManager.ClearLine(lineNum);
            Console.Write($"{"Сохранение копии: ",offset}");

            ret = swModelMan.SaveAsCopy(folder + name);

            Console.Write(ret ? " OK\n" : " Не сохранено\n");
            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Сохранить развёртку
        /// </summary>
        /// <param name="swModelMan"></param>
        /// <param name="folder">Папка сохранения</param>
        /// <param name="name">Имя файла с расширением</param>
        /// <returns></returns>
        public static bool SaveDXF(SwModelManager swModelMan, string folder = null, string name = null)
        {
            bool      ret     = false;
            int       lineNum = 12;
            const int offset  = 23;

            Console.CursorLeft = 0;
            //Console.CursorTop = lineNum;

            if (string.IsNullOrEmpty(folder))
            {
                folder = swModelMan.FolderPath;
            }

            if (string.IsNullOrEmpty(name))
            {
                name = swModelMan.FileNameWhithoutExt + ".dxf";
            }


            StringManager.ClearLine(lineNum);
            Console.Write($"{"Сохранение DXF: ",offset}");

            if (swModelMan.PrpMan.isSheet)
            {
                ret = swModelMan.Export.SaveDxf(folder + name);
            }

            Console.Write(ret ? " OK\n" : " Не сохранено\n");
            return(ret);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Сохранить PDF из чертежа с тем же именем
        /// </summary>
        /// <param name="swModelMan"></param>
        /// <param name="folder">Папка сохранения</param>
        /// <param name="name">Имя файла с расширением</param>
        /// <returns></returns>
        public static bool SavePDF(SwModelManager swModelMan, string folder = null, string name = null)
        {
            bool      ret     = false;
            int       lineNum = 14;
            const int offset  = 23;

            Console.CursorLeft = 0;

            if (string.IsNullOrEmpty(folder))
            {
                folder = swModelMan.FolderPath;
            }

            if (string.IsNullOrEmpty(name))
            {
                name = swModelMan.FileNameWhithoutExt + ".pdf";
            }


            StringManager.ClearLine(lineNum);
            Console.Write($"{"Сохранение PDF: ",offset}");

            DrawingDoc DrawDoc;

            string drawName    = Path.ChangeExtension(swModelMan.FileName, "SLDDRW");
            var    openedDraw  = SwProcess.swApp.GetOpenDocument(drawName);
            bool   docIsOpened = false;

            if (!(openedDraw is null))
            {
                docIsOpened = true;
            }

            if (SwFileManager.OpenDraw(swModelMan.FilePath, out DrawDoc))
            {
                var model = (ModelDoc2)DrawDoc;

                ret = swModelMan.Export.SavePdf(DrawDoc, folder + name, true);

                if (!docIsOpened)
                {
                    SwProcess.swApp.CloseDoc(model.GetTitle());
                }
            }

            Console.Write(ret ? " OK\n" : " Не сохранено\n");
            return(ret);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Напечатать имя файла
        /// </summary>
        /// <param name="swModelMan"></param>
        /// <returns></returns>
        public static bool ShowDocName(SwModelManager swModelMan)
        {
            bool ret     = false;
            int  lineNum = 4;

            Console.CursorLeft = 0;
            Console.CursorTop  = lineNum;
            Console.WriteLine("Отсутствует");
            if (!(swModelMan is null))
            {
                StringManager.ClearLine(lineNum);
                Console.WriteLine("{0, 23} {1}", "Имя документа: ", swModelMan.FileName);
                ret = true;
            }
            return(ret);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Напечатать тип детали
        /// </summary>
        /// <param name="swModel"></param>
        /// <returns></returns>
        public static bool ShowDocType(SwModelManager swModelMan)
        {
            swDocumentTypes_e docType;
            bool ret     = false;
            int  lineNum = 3;

            Console.CursorLeft = 0;
            Console.CursorTop  = lineNum;
            Console.WriteLine("Открытый документ отсутствует");
            if (!(swModelMan is null))
            {
                docType = swModelMan.DocType;

                StringManager.ClearLine(lineNum);
                Console.WriteLine("{0, 23} {1}", "Тип открытой детали: ", StringManager.DocTypeName(docType));
                ret = true;
            }

            return(ret);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Написать список параметров сборки или детали
        /// </summary>
        /// <param name="swModelMan"></param>
        public static void ShowProp(SwModelManager swModelMan)
        {
            bool      ret     = false;
            const int offset  = 23;
            int       lineNum = 6;

            Console.CursorTop = lineNum;
            swDocumentTypes_e doctype = swModelMan.DocType;

            if (doctype == swDocumentTypes_e.swDocPART || doctype == swDocumentTypes_e.swDocASSEMBLY)
            {
                string NameProp    = swModelMan.PrpMan.Title;
                string parnNum     = swModelMan.PrpMan.GetParam("Обозначение");
                string configName  = swModelMan.PrpMan.GetActiveConf;
                bool   isDrawExist = SwFileManager.isDrawExcist(swModelMan.FilePath);
                bool   isSheet     = swModelMan.PrpMan.isSheet;

                string DrawIsFound  = isDrawExist ? "Найден" : "Не найден";
                string isSheetMetal = isSheet ? $"Листовая - {swModelMan.PrpMan.GetSheetThickness}мм" : "Не листовая";

                //Clear console below
                for (int i = lineNum; i < lineNum + 5; ++i)
                {
                    StringManager.ClearLine(i);
                }

                Console.CursorLeft = 0;
                Console.CursorTop  = lineNum;

                Console.WriteLine($"{"Обозначение: ",offset} {parnNum}");
                Console.WriteLine($"{"Наименование: ",offset} {NameProp}");
                Console.WriteLine($"{"Активная конфигурация: ",offset} {configName}");
                Console.WriteLine($"{"Одноимённый чертёж: ",offset} {DrawIsFound}");
                Console.WriteLine($"{"Тип детали: ",offset} {isSheetMetal}");
            }
            else
            {
                Console.WriteLine($"{"Имя чертежа: ",offset} {swModelMan.swModel.GetTitle()}");
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            ISldWorks swApp;
            ModelDoc2 swModel;

            string rootFolder;
            string workFolder;
            string name;
            string partName;

            AppConsole.Greenings(Version);
            AppConsole.RunSW();
            AppConsole.LoadSwApp();


            do
            {
                //Загрузить активный документ
                swModel = AppConsole.LoadActiveDoc();
                var part = new SwModelManager(swModel);

                //Получить информацию из открытого документа
                name     = part.PrpMan.GetParam("Наименование");
                partName = part.PrpMan.GetParam("Обозначение");

                workFolder = WorkFolder.FolderPath ?? part.FolderPath;


                //Отобразить информацию на экране
                AppConsole.ShowDocType(part);
                AppConsole.ShowDocName(part);
                AppConsole.ShowProp(part);

                //Экспорт
                if ((int)part.DocType == 1 || (int)part.DocType == 2)
                {
                    Console.CursorTop = 18;
                    AppConsole.SwitchColor(AppConsole.ColorMode.Info);
                    Console.WriteLine($"Рабочая папка\n{workFolder}");
                    AppConsole.SwitchColor(AppConsole.ColorMode.Default);
                    Console.CursorTop = 11;
                    Console.WriteLine("Чтобы изменить рабочую папку - Ввод. Для продолжения кнопку пробел");
                    var userAnswer = Console.ReadKey(true);

                    if (userAnswer.Key == ConsoleKey.Spacebar && part.DocType == swDocumentTypes_e.swDocPART)
                    {
                        // Создать директорию
                        if (!Directory.Exists(workFolder))
                        {
                            Directory.CreateDirectory(workFolder);
                        }

                        if (partName.Length > 3 && name.Length > 3)
                        {
                            string savingName = partName + " - " + name;
                            AppConsole.SaveDXF(part, workFolder, savingName + ".dxf");

                            AppConsole.SaveCopy(part, workFolder, savingName + part.GetFileExtension);

                            AppConsole.SavePDF(part, workFolder, savingName + ".pdf");
                        }
                        else
                        {
                            AppConsole.SwitchColor(AppConsole.ColorMode.Warning);
                            Console.WriteLine("Отсутствует обозначение или описание");
                            AppConsole.SwitchColor(AppConsole.ColorMode.Default);
                        }
                    }

                    //Изменить рабочую папку
                    else if (userAnswer.Key == ConsoleKey.Enter)
                    {
                        WorkFolder.FolderPath = WorkFolder.GetFolderDialog(workFolder);
                        for (int i = 18; i < 25; i++)
                        {
                            AppConsole.StringManager.ClearLine(i);
                        }
                    }
                    else
                    {
                        AppConsole.SwitchColor(AppConsole.ColorMode.Warning);
                        Console.WriteLine("Сохранение из сборки не поддерживается");
                        AppConsole.SwitchColor();
                    }
                }
                else
                {
                    AppConsole.SwitchColor(AppConsole.ColorMode.Warning);
                    Console.WriteLine("\nСохранение невозможно.");
                    AppConsole.SwitchColor();
                }
            }while (AppConsole.ReloadModel());

            Console.WriteLine("Пока-пока");
            Thread.Sleep(400);
        }