The following is a demo (I am currently in HIGER, so the copyright is it, huh, huh). The principle is to print DWG to a printer. To enable automatic printer, you must support automatic saving, the following parameter creator is supported.
If you want to debug it, just create a project and add a FORM ~~~~~~~~~~~
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using Autodesk. AutoCAD. Interop;
Using System. IO;
Namespace WindowsFormsApplication1
{
Public partial class Form1: Form
{
AcadApplicationClass app; // resident application
Public Form1 ()
{
InitializeComponent ();
Try
{
App = new AcadApplicationClass ();
}
Catch
{
MessageBox. Show ("Start AutoCAD object failed! Installed? ");
Button1.Enabled = false;
Return;
}
}
Private void button#click (object sender, EventArgs e)
{
If (! File. Exists (textBox1.Text ))
{
MessageBox. Show ("File is not exists ");
Return;
}
AcadDocument doc;
Try
{
Doc = app. Documents. Open (textBox1.Text, null, null); // Open the file
}
Catch (Exception error)
{
MessageBox. Show ("Can't open the file." + error. Message );
Return;
}
Doc. ModelSpace. Layout. PlotType = Autodesk. AutoCAD. Interop. Common. AcPlotType. acExtents; // define the print range to automatically extend the whole Graph
Doc. ModelSpace. Layout. ConfigName = textBox3.Text; // select the printer
Doc. ModelSpace. Layout. CanonicalMediaName = comboBox1.Text; // you can specify the image size.
Doc. Plot. NumberOfCopies = 1; // number of copies printed
Try
{
Doc. Plot. PlotToDevice (null );
}
Catch (Exception error)
{
MessageBox. Show ("Send to printer failed." + error. Message );
Return;
}
Finally
{
Doc. Close (false, null );
}
}
Private void form=formclosing (object sender, FormClosingEventArgs e)
{
If (app! = Null)
Try
{
App. Quit ();
}
Catch {}
} Www.2cto.com
Private void button2_Click_1 (object sender, EventArgs e)
{
OpenFileDialog d = new OpenFileDialog ();
D. Filter = "AutoCAD Drawing (*. dwg) | *. dwg ";
If (d. ShowDialog () = DialogResult. OK)
{
TextBox1.Text = d. FileName;
}
}
}
}