本帖最后由 Liszt 于 2011-6-10 17:44 编辑
为什么向未激活的dwg文档中 添加实体,可以添加成功,但是看不到它的显示?
代码如下:
- [CommandMethod("t4")]
- public static void Test4()
- {
- //新建dwg文档
- string sLocalRoot = Application.GetSystemVariable("LOCALROOTPREFIX") as string;
- string sTemplatePath = sLocalRoot + "Template\\acad.dwt";
- // Create a new drawing to copy the objects to
- DocumentCollection acDocMgr = App.DocumentManager;
- acNewDoc = acDocMgr.Add(sTemplatePath);
- Database acDbNewDoc = acNewDoc.Database;
- //向未激活的文档中添加实体
- foreach (Document doc in acDocMgr)
- {
- if (!doc.IsActive)//未激活
- {
- Database Db = doc.Database;
- //Lock the document
- using (DocumentLock docLock = doc.LockDocument())
- {
- // Start a transaction
- using (Transaction acTrans = Db.TransactionManager.StartTransaction())
- {
- BlockTable acBlkTbl;
- BlockTableRecord acBlkTblRec;
- // Open Model space for write
- acBlkTbl = acTrans.GetObject(Db.BlockTableId,
- OpenMode.ForRead) as BlockTable;
- acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite) as BlockTableRecord;
- Point3d ptStart, ptEnd;
- ptStart = new Point3d(0,0,0);
- ptEnd = new Point3d(100, 100, 100);
- // Define the new line
- Line acLine = new Line(ptStart, ptEnd);
- // Add the line to the drawing
- acBlkTblRec.AppendEntity(acLine);
- acTrans.AddNewlyCreatedDBObject(acLine, true);
- // Commit the changes and dispose of the transaction
- acTrans.Commit();
- }
- }
- }
- }
- }
截图如下:
在Drawing2.dwg中已经加入了直线,但是无法显示..只有保存Drawing2.dwg,关闭后再次打开才看得到。
如何能够在加入实体之后立刻就能看到?(注:加入实体(如直线)时Drawing2.dwg已打开但是未激活)
|