明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2323|回复: 3

一个自动批量打印程序的三个问题,请各位高手帮忙看看

[复制链接]
发表于 2011-10-22 21:21 | 显示全部楼层 |阅读模式
程序的原理是这样:
   在一个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)
        {
        }
    }   
}


本程序一共包含的1个类,4个函数。分别是:
public void ba(),
private ObjectIdCollection GetSheet()
private int Plot(Point2d pMin, Point2d pMax, double angle, int size)
private Point2d Point3dToPoint2d(Point3d p3d)

意思都很好理解。
现在出现了三个问题。
第一:文件中有多张图纸,GetSheet()函数也能将所有图纸全部选择,但无论有多少图纸,每次运行程序只能打印一页。经过多次测试发现关键在于  Plot()方法中的这一句:

if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
        .....
}

这句是在手册上操的,我尝试过去掉这句,但马上就有异常。不去掉这句,怎么也不能打印第二张图纸。

   我还好现在我程序运行结束之后的几秒甚至十几秒之后,Autocad才开启发布作业。我本来的设想是只要运行一次Plot()就进行一次发布作业,这样有多少张图纸就有多少次发布作业。但实际情况和我所想的完全不同。是不是我的算法有问题?究竟能不能实现?

第二个问题是,虽然能够打印一张图纸,但打印出来的东西总是不对。刚开始测试的时候连续地打出白纸。后来怀疑是座标可能有冲突,重设为世界坐标系之后,也不对,虽然有时不再打白纸了。但也不知打印的是哪个区域,反正不是我想要的区域。想来起去真想不出来是为什么。

发表于 2011-10-30 23:18 | 显示全部楼层
哇塞论坛里的高手真多啊 羡慕啊
 楼主| 发表于 2011-10-31 21:51 | 显示全部楼层
已解决,能不能撤了这个贴?
发表于 2022-9-30 08:29 | 显示全部楼层
看看批量打印
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-28 08:05 , Processed in 1.697007 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表