请高手们帮忙看段代码
public static void NewDrawing(){
string strTemplatePath = "kcv.dwt";
DocumentCollection acDocMgr = Application.DocumentManager;
Document acDoc = acDocMgr.Add(strTemplatePath);
acDocMgr.MdiActiveDocument = acDoc;
Database db = acDoc.Database;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
Circle cir = new Circle(new Point3d(1, 1, 0), Vector3d.ZAxis, 1.0);
btr.AppendEntity(cir);
trans.AddNewlyCreatedDBObject(cir, true);
trans.Commit();
}我想用上面的代码实现:以kcv.dwt为模板 新建一个文件 并在这个文件里画一个圆 ,实现不了,请大家帮忙看看该怎么改,谢谢
<p><strong><span style="COLOR: #660000;">CommandFlags.</strong></span><strong>Session</strong></p> <pre class="codeLine"><br/>版主我 前面加上了 <br/>还是不能正常运行</pre> <p>这里可以去掉</p><p>acDocMgr.MdiActiveDocument = acDoc;</p><p>没办法试,你先看下吧</p> <p>还是不行</p><p>谢谢版主热心解答</p>
public static void Test()
{
string strTemplatePath = "acad.dwt";
DocumentCollection acDocMgr = Application.DocumentManager;
Document acDoc = acDocMgr.Add(strTemplatePath);
//acDocMgr.MdiActiveDocument = acDoc;
Database db = acDoc.Database;
using (acDoc.LockDocument())
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
Circle cir = new Circle(new Point3d(1, 1, 0), Vector3d.ZAxis, 1.0);
btr.AppendEntity(cir);
trans.AddNewlyCreatedDBObject(cir, true);
trans.Commit();
}
}
}
<p> 谢谢版主</p>
页:
[1]