- 积分
- 367
- 明经币
- 个
- 注册时间
- 2011-9-25
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 杜斌 于 2011-10-20 21:12 编辑
程序的原理是这样:
在一个DWG文件中,有多张图纸。A3,A4等都有。将图框做成块。在程序中遍历所有图框块,找到每张图纸的位置,然后打印相应该的窗口。
这个算法我想来想去应该是没有问题。于是尝试着写了出来。主要代码如下。
using System;
....
using Autodesk.AutoCAD.PlottingServices;
namespace AllBlock
{
public class Class1
{
public static Document doc = Application.DocumentManager.MdiActiveDocument;
public Database db = doc.Database;
public Editor ed = doc.Editor;
public int index = 1;
[CommandMethod("ba")]
public void ba()
{
ObjectIdCollection objIdColl = GetSheet();
if (objIdColl == null)
{
return;
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
foreach (ObjectId objId in objIdColl)
{
BlockReference bref = tr.GetObject(objId, OpenMode.ForRead) as BlockReference;
Extents3d exSize = bref.GeometricExtents;
Point2d pStart = Point3dToPoint2d(exSize.MinPoint);
Point2d pEnd = Point3dToPoint2d(exSize.MaxPoint);
if (bref.Name == "a4") //区分A3和A4
{
int a = Plot(pStart, pEnd, bref.Rotation, 4);
}
else
{
int a = Plot(pStart, pEnd, bref.Rotation, 3);
}
}
}
}
private ObjectIdCollection GetSheet()
{}
private int Plot(Point2d pMin, Point2d pMax, double angle, int size)
{
//检查打印状态
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
//开启打印引擎
using (PlotEngine pe = PlotFactory.CreatePublishEngine())
{
/////....
}
}
return 0;
}
private Point2d Point3dToPoint2d(Point3d p3d)
{
}
}
}
|
|