c# 打印,在手册上操的代码加以改进出错
这是我做的一个批量打印程序,在手册上操了打印的代码,编译没问题。运行时有三行代码有异常,这三行是完全在手册上操的。以下是全代码,请各位大侠多多批教,谢谢!using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.PlottingServices;
namespace AllBlock
{
public class Class1
{
//public void Init()
//{
public static Document doc = Application.DocumentManager.MdiActiveDocument;
public static Database db = doc.Database;
public static Editor ed = doc.Editor;
//}
public void ba()
{
//Init();
TypedValue[] tv = new TypedValue;
tv.SetValue(new TypedValue((int)DxfCode.BlockName, "a4"),0);
// 赋值过滤条件给 SelectionFilter 对象 Assign the filter criteria to a SelectionFilter object
SelectionFilter acSelFtr = new SelectionFilter(tv);
// 要求在图形区域中选择对象 Request for objects to be selected in the drawing area
PromptSelectionResult acSSPrompt = ed.SelectAll(acSelFtr);
// 如果提示状态是 OK,对象就被选择了 If the prompt status is OK, objects were selected
if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
Application.ShowAlertDialog("Number of objects selected: " +acSSet.Count.ToString());
using (Transaction tr = db.TransactionManager.StartTransaction())
{
foreach (SelectedObject sobj in acSSet)
{
BlockReference bref = tr.GetObject(sobj.ObjectId, OpenMode.ForRead) as BlockReference;
ed.WriteMessage("\n块的名称是: " + bref.Name);
ed.WriteMessage("\n块的插入位置是:"+ bref.Position.ToString());
Extents3d exSize = bref.GeometricExtents;
Point2d pStart = Point3dToPoint2d(exSize.MinPoint);
Point2d pEnd = Point3dToPoint2d(exSize.MaxPoint);
ed.WriteMessage("\n块的大小是: 长{0},宽{1}", pEnd.X-pStart.X,pEnd.Y-pStart.Y);
ed.WriteMessage("\n块的旋转角度是: " + bref.Rotation * 180 / 3.1415926);
int a = Plot(pStart, pEnd, 0, 3);
}
}
}
else
{
Application.ShowAlertDialog("Number of objects selected: 0");
}
}
private int Plot(Point2d pMin, Point2d pMax, int angle, int size)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//设置布局管理器为当前布局管理器
LayoutManager layoutMan = LayoutManager.Current;
页:
[1]