本帖最后由 cooolseee 于 2016-7-19 08:58 编辑
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Collections;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.Windows;
- using DotNetARX;
- namespace 工具
- {
- public class Tools
- {
- #region 新建dwg文档
- //[CommandMethod("dwgCreat", CommandFlags.Session)]
- public static Document dwgCreat()
- {
- DocumentCollection docs = Application.DocumentManager;
- Document doc = docs.Add("acad.dwt");
- //docs.MdiActiveDocument = doc;
- return doc;
- }
- #endregion 新建dwg文档
- }
- public class 测试
- {
- [CommandMethod("AAA", CommandFlags.Session)]
- public void AAA()
- {
- for (int i = 0; i < 100; )
- {
- Circle cir = new Circle();
- cir.Center = new Point3d(0, 0, 0);
- cir.Radius = 10;
- #region 初始化绘图环境
- DocumentCollection docs = Application.DocumentManager;
- Document doc = Tools.dwgCreat();
- Database db = doc.Database;
- Editor ed = doc.Editor;
- DocumentLock docl = doc.LockDocument();//这句要不要
- #endregion 初始化绘图环境
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- db.AddToModelSpace(cir);
- trans.Commit();
- }
- if (docs.MdiActiveDocument != doc)
- docs.MdiActiveDocument = doc;
- db.SaveAs("D:\\DWG\\" + i+ ".dwg", DwgVersion.AC1800);
- doc.CloseAndDiscard();
- i++;
- }
- }
- }
- }
上面的代码不确定锁定文档需不需要,如果需要,没有解锁文档对不对,请高手指点。测试没什么问题,就是用同样的原理,在我的程序中, 就会出现1楼描述的问题
|