Esempio n. 1
0
        private void OutputImageMenuItem_Click(object sender, EventArgs e)
        {
            // pick the place where o output the image type
            Autodesk.AutoCAD.Windows.SaveFileDialog dialog = new Autodesk.AutoCAD.Windows.SaveFileDialog("RenderToImage", null, "jpg;png;tif;bmp", "BlockViewSnapshotBrowseDialog", Autodesk.AutoCAD.Windows.SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension);
            // if all is ok?
            if (DialogResult.OK == dialog.ShowDialog())
            {
                // create an offscreen device
                using (Device device = new Device())
                {
                    // get the size of the GS view
                    Size size = mPreviewCtrl.ClientRectangle.Size;
                    // resize the device to this
                    device.OnSize(size);
                    device.BackgroundColor = Color.Black;
                    device.SetLogicalPalette(GSUtil.MyAcadColorMs);
                    device.OnRealizeBackgroundPalette();
                    device.OnRealizeForegroundPalette();

                    // make a copy of the gs view
                    using (Autodesk.AutoCAD.GraphicsSystem.View view = mPreviewCtrl.mpView.Clone(true, true))
                    {
                        try
                        {
                            // add it to the device
                            device.Add(view);
                            // now render the image to a bitmap

                            //using( System.Drawing.Bitmap bitmap = view.RenderToImage() )
                            //{
                            // now save it out!!
                            //bitmap.Save( dialog.Filename );
                            //}
                            using (Bitmap bitmap = view.GetSnapshot(mPreviewCtrl.ClientRectangle))
                            {
                                bitmap.Save(dialog.Filename);
                            }
                        }
                        finally
                        {
                            // do a clear up
                            device.EraseAll();
                        }
                    }
                }
            }
        }
        private void click_Extract(object sender, EventArgs e)
        {
            int CardColumn        = 2;
            int TagColumn         = 4;
            int DescriptionColumn = 5;
            int SlotRowWidth      = 34;

            List <IO_Block> Selected_Cards = new List <IO_Block>();

            ListView.CheckedIndexCollection holder = lv_IOCards.CheckedIndices;

            foreach (int index in holder)
            {
                Selected_Cards.Add(IO_Blocks[index]);
            }

            Excel.Application ExcelApp = new Excel.Application();
            ExcelApp.Visible        = false;
            ExcelApp.ScreenUpdating = false;
            ExcelApp.EnableEvents   = false;

            Excel.Workbook ExcelWB = ExcelApp.Workbooks.Open(tb_Path.Text);
            ExcelApp.Calculation = Excel.XlCalculation.xlCalculationManual;
            Excel.Sheets ExcelSheets = ExcelWB.Sheets;

            foreach (IO_Block card in Selected_Cards)
            {
                int test = SlotRowWidth * Int32.Parse(card.slot) + 3;
                ExcelSheets[1].Cells[SlotRowWidth * Int32.Parse(card.slot) + 3, CardColumn].Value = card.partNumber;

                int portCount = 0;
                for (int i = 0; i < card.portDescriptions.Length; i++)
                {
                    if (!String.IsNullOrEmpty(card.portDescriptions[i]))
                    {
                        ExcelSheets[1].Cells[SlotRowWidth * Int32.Parse(card.slot) + 4 + portCount, DescriptionColumn].Value = card.portDescriptions[i];
                        portCount++;
                    }
                }
                ExcelApp.DisplayAlerts = false;

                Excel.Range rng = ExcelSheets[1].Range[ExcelSheets[1].Cells[SlotRowWidth * Int32.Parse(card.slot) + 4, DescriptionColumn], ExcelSheets[1].Cells[SlotRowWidth * Int32.Parse(card.slot) + 35, DescriptionColumn]];
                rng.Replace(@"\P", " ", Excel.XlLookAt.xlPart);
                rng.Replace(@" \P", " ", Excel.XlLookAt.xlPart);
                rng.Copy();

                ExcelSheets[1].Cells[SlotRowWidth * Int32.Parse(card.slot) + 4, TagColumn].PasteSpecial(Excel.XlPasteType.xlPasteValues, Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false);

                rng = ExcelSheets[1].Range[ExcelSheets[1].Cells[SlotRowWidth * Int32.Parse(card.slot) + 4, TagColumn], ExcelSheets[1].Cells[SlotRowWidth * Int32.Parse(card.slot) + 35, TagColumn]];
                rng.Replace("  ", "_", Excel.XlLookAt.xlPart);
                rng.Replace(" ", "_", Excel.XlLookAt.xlPart);
                rng.Replace("-", "_", Excel.XlLookAt.xlPart);
                rng.Replace("SPARE", "", Excel.XlLookAt.xlPart);

                ExcelApp.DisplayAlerts = true;
            }
            ExcelWB.Worksheets[1].Cells[3, 2].Select();

            Autodesk.AutoCAD.Windows.SaveFileDialog sfd = new Autodesk.AutoCAD.Windows.SaveFileDialog("Save IO Export Excel file as:", "IOExport", "xlsm", "ExcelFiles", Autodesk.AutoCAD.Windows.SaveFileDialog.SaveFileDialogFlags.DoNotWarnIfFileExist);
            System.Windows.Forms.DialogResult       dr  = sfd.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                ExcelWB.SaveAs(sfd.Filename, Type.Missing, Type.Missing, Type.Missing, true, false, Excel.XlSaveAsAccessMode.xlNoChange, Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing);

                ExcelApp.EnableEvents   = true;
                ExcelApp.Visible        = true;
                ExcelApp.ScreenUpdating = true;
                ExcelApp.Calculation    = Excel.XlCalculation.xlCalculationAutomatic;

                ExcelWB.Unprotect();
                ExcelApp.Run("ExternalUpdate");
                ExcelWB.Protect();
                this.Close();
            }
            else
            {
                ExcelWB.Close(false, Type.Missing, Type.Missing);
                this.Close();
            }
        }
Esempio n. 3
0
        public static void TextToCSV(List <Curve> curveDict)
        {
            SettingsParser settings = SettingsParser.getInstance();

            //более правильный и дорогой вариант см. тут:
            //http://adn-cis.org/forum/index.php?topic=448.0

            App.Document  acDoc = App.Application.DocumentManager.MdiActiveDocument;
            StringBuilder sb    = new StringBuilder();

            string separateLine = ";;;;;;;;;;;;;";    // разделительная строка

            // заголовок
            sb.AppendLine($"{separateLine}\n;;;;;Х;У;;;;;;;\n;;;1;2;3;4;5;;;;;;\n{separateLine}");

            //Основной цикл вывода списка линий
            foreach (Curve сurve in curveDict)
            {
                bool isFirstLine = true;
                //Цикл вывода вершин линий
                foreach (Point point in сurve.Vertixs)
                {
                    if (isFirstLine)
                    {
                        isFirstLine = false;
                        //Вывожу номер кривой вместе с координатами первой вершины
                        sb.AppendLine($";;;участок № { сurve.Number };{ point.Number };{point.Y.ToString(settings.coordinatFormat) };{point.X.ToString(settings.coordinatFormat)};;;;;;;");
                    }
                    else
                    {
                        //Вывожу все остальные вершины
                        sb.AppendLine($";;;;{ point.Number };{point.Y.ToString(settings.coordinatFormat) };{point.X.ToString(settings.coordinatFormat)};;;;;;;");
                    }
                }

                //Вывожу координаты первой точки кривой, а так же ее площадь
                sb.AppendLine($";;;;{ сurve.Vertixs.First().Number };{сurve.Vertixs.First().Y.ToString(settings.coordinatFormat) };{сurve.Vertixs.First().X.ToString(settings.coordinatFormat)};S={сurve.AreaOutput} га;;;;;;");
                sb.AppendLine(separateLine);
            }
            sb.AppendLine($";;;;;;Общая площадь:;{Model.allArea} га;;;;;;");



            //Должен быть выбор пользователя, при этом по умолчанию предложить каталог, в котором находится файл чертежа.
            Win.SaveFileDialog sFile = new Win.SaveFileDialog("Каталог координат земельных участков",
                                                              acDoc.Database.Filename + ".csv",
                                                              "csv",
                                                              "Сохранить данные",
                                                              Win.SaveFileDialog.SaveFileDialogFlags.NoUrls |
                                                              Win.SaveFileDialog.SaveFileDialogFlags.NoShellExtensions |
                                                              Win.SaveFileDialog.SaveFileDialogFlags.NoFtpSites |
                                                              Win.SaveFileDialog.SaveFileDialogFlags.DoNotWarnIfFileExist |
                                                              Win.SaveFileDialog.SaveFileDialogFlags.DoNotTransferRemoteFiles);

            try
            {
                if (sFile.ShowDialog() == System.Windows.Forms.DialogResult.OK && sFile.Filename.Length > 0)
                {
                    outToCSV(sb.ToString(), sFile.Filename);
                }
            }
            catch (Rtm.Exception ex)
            {
                //MessageBox.Show("Error", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                acDoc.Editor.WriteMessage($"\nError! {ex.Message}");
            }
        }