private static IEnumerable <string> GetPrinterList() { try { using (var cad = new AutoCadConnector()) { 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; layout.RefreshPlotDeviceInfo(); var plots = (string[])layout.GetPlotDeviceNames(); if (cad.Application.Documents.Count > 0) { doc.Close(false, ""); } return(plots); } } catch (Exception ex) { MessageBox.Show(string.Format("程序运行出错,错误描述:{0}", ex.Message), @"批量打印", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
private void cbSize_SelectedIndexChanged(object sender, EventArgs e) { 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; layout.ConfigName = cbPrinterList.Text; layout.CanonicalMediaName = mediaNameDictionary[cbSize.Text]; double w, h; layout.GetPaperSize(out w, out h); layout.PlotRotation = w > h ? AcPlotRotation.ac0degrees : AcPlotRotation.ac90degrees; layout.RefreshPlotDeviceInfo(); lblPaperSize.Text = string.Format("打印尺寸:{0}*{1}", Math.Ceiling(w), Math.Ceiling(h)); } catch (Exception ex) { MessageBox.Show(string.Format("调用CAD程序出错!\n错误描述:{0}", ex.Message), @"批量打印", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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); } } }