- 积分
- 239
- 明经币
- 个
- 注册时间
- 2021-12-22
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2021-12-22 17:07:17
|
显示全部楼层
- 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[BlockTableRecord.ModelSpace], 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[BlockTableRecord.ModelSpace], 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();
- }
- }
- }
|
|