Beispiel #1
0
        private void cbPrinterList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (IsInit)
            {
                return;
            }
            if (cbPrinterList.SelectedIndex < 0)
            {
                return;
            }

            using (var cad = new AutoCadConnector())
            {
                try
                {
                    AcadDocument doc;
                    if (cad.Application.Documents.Count > 0)
                    {
                        doc = cad.Application.Documents.Item(0) ?? cad.Application.Documents.Add();
                    }
                    else
                    {
                        doc = cad.Application.Application.Documents.Add();
                    }

                    AcadLayout layout = doc.ModelSpace.Layout;

                    if (cbPrinterList.Text != @"无" || string.IsNullOrEmpty(cbPrinterList.Text))
                    {
                        layout.RefreshPlotDeviceInfo();
                        layout.ConfigName = cbPrinterList.Text;
                        var p = (string[])layout.GetCanonicalMediaNames();
                        cbSize.Items.Clear();
                        mediaNameDictionary.Clear();
                        foreach (var s in p)
                        {
                            var LocaleMediaName = layout.GetLocaleMediaName(s);
                            cbSize.Items.Add(LocaleMediaName);
                            mediaNameDictionary[LocaleMediaName] = s;
                        }
                        //cbSize.DataSource = p;
                    }
                    else
                    {
                        cbSize.Items.Clear();
                        mediaNameDictionary.Clear();
                    }
                    doc.Close(false, "");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("调用CAD程序出错!\n错误描述:{0}", ex.Message), @"批量打印", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        public static void ToPDF()
        {
            Document activeDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;

            AcadDocument ThisDrawing = activeDoc.GetAcadDocument() as AcadDocument;

            AcadLayout layout    = ThisDrawing.ActiveLayout;
            String     MediaName = layout.CanonicalMediaName;

            if (MediaName.Equals(""))
            {
                activeDoc.Editor.WriteMessage("There is no media set for the active layout.");
                return;
            }
            else
            {
                activeDoc.Editor.WriteMessage("The media for the active layout is: " + MediaName);
            }

            try
            {
                AcadPlotConfiguration oplot = ThisDrawing.PlotConfigurations.Add("PDF", layout.ModelType);

                oplot.PaperUnits = AcPlotPaperUnits.acMillimeters;

                oplot.StyleSheet = "monochrome.ctb";

                oplot.PlotWithPlotStyles = true;

                oplot.ConfigName = "DWG To PDF.pc3";

                oplot.UseStandardScale = true;

                oplot.StandardScale = AcPlotScale.acScaleToFit;

                oplot.PlotType = AcPlotType.acExtents;

                oplot.CenterPlot = true;

                Object    oMediaNames = layout.GetCanonicalMediaNames();
                ArrayList mediaNames  = new ArrayList((string[])oMediaNames);
                foreach (String sName in mediaNames)
                {
                    if (sName.Contains(MediaName))

                    {
                        oplot.CanonicalMediaName = sName;

                        layout.CopyFrom(oplot);

                        layout.PlotRotation = AcPlotRotation.ac0degrees;

                        layout.RefreshPlotDeviceInfo();



                        ThisDrawing.SetVariable("BACKGROUNDPLOT", 0);

                        ThisDrawing.Plot.QuietErrorMode = true;



                        ThisDrawing.Plot.PlotToFile("c://temp//d1.pdf", "DWG To PDF.pc3");

                        oplot.Delete();

                        oplot = null;

                        return;
                    }
                }
            }

            catch (System.Exception es)
            {
                // System.Windows.Forms.MessageBox.Show(es.ToString());
            }
        }