求助一个打印相关的问题
基于cad2007的开发,现在设计的一个功能是只打印需要的实体,我实现的方式是先把获取到要打印的实体复制到新建的图层里,然后关闭其他图层的可打印属性,打印之后再删除打印图层和里面的东西。目前这些步骤都已经实现,但是打印的时候会出现打印出来全都是空白的问题,分步调试之后发现复制和关闭其他图层可打印都没有问题,这一步完成我保存了图,然后用这张图跳过了之前的步骤从打印开始调试,打印出来的也没有任何问题。但是这两个步骤一起进行,就会打印出来全是空白。我尝试了在中间regen和redraw,没有起到任何作用。有没有大佬知道这是什么原因导致的?
using (Transaction tr = db.TransactionManager.StartTransaction()) public void Output(string xmbh, string fw, string szc, ObjectId[] Ids, ObjectId[] AllIds)
{
var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
var db = doc.Database;
using (doc.LockDocument())
{
//新建图层,复制打印项,改图层打印属性
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable blt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blt, OpenMode.ForWrite);
ObjectIdCollection objectIds = new ObjectIdCollection();
foreach (var p in Ids)
{
var a = tr.GetObject(p, OpenMode.ForWrite);
if (a is Polyline pl)
{
pl.UpgradeOpen();
pl.ConstantWidth = 0.05;
pl.DowngradeOpen();
}
DBObject b = (DBObject)a.Clone();
objectIds.Add(btr.AppendEntity((Entity)b));
tr.AddNewlyCreatedDBObject(b, true);
}
LayerTable table = tr.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;
if (!table.Has("打印层"))
{
LayerTableRecord record = new LayerTableRecord();
record.Name = "打印层";
ObjectId tbid = table.Add(record);
tr.AddNewlyCreatedDBObject(record, true);
Group grp = new Group();
grp.Append(objectIds);
grp.SetLayer(tbid);
}
foreach (ObjectId id in table)
{
LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(id, OpenMode.ForWrite);
if (ltr.Name != "打印层")
{
ltr.IsPlottable = false;
}
}
tr.Commit();
}
var ext = Ids.GetExtents(SCTPWYJ);
string outputFolder = Path.Combine("C:\\WorkFile", xmbh);
Directory.CreateDirectory(outputFolder);
// 输出JPG
string outputFile = Path.Combine(outputFolder, $"层图_{fw}_{szc}.jpg");
_plot.Plot(ext.MinPoint, ext.MaxPoint, outputFile);
// 输出DWG
string outputFile2 = Path.Combine(outputFolder, $"层图_{fw}_{szc}.dwg");
_dos.SaveAs(Ids, outputFile2);
//还原
using (var tr = db.TransactionManager.StartTransaction())
{
BlockTable blt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blt, OpenMode.ForWrite);
foreach (ObjectId entId in btr)
{
Entity entity = tr.GetObject(entId, OpenMode.ForRead) as Entity;
if (entity.Layer == "打印层")
{
entity.UpgradeOpen();
try
{
entity.Erase();
}
catch
{
continue;
}
}
}
LayerTable table = tr.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;
foreach (ObjectId id in table)
{
LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(id, OpenMode.ForWrite);
if (ltr.Name == "打印层")
{
ltr.Erase(true);
continue;
}
ltr.IsPlottable = true;
}
tr.Commit();
}
}
} 是不是坐标系的问题
应该不是,我直接获取的图上实体集合的坐标作为打印区域。
页:
[1]