- 积分
- 3387
- 明经币
- 个
- 注册时间
- 2011-6-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.Geometry;
- namespace _01
- {
- public class Class1
- {[CommandMethod("cd")]
- public void closeAndSave()
- {
- Document doc;
- Database db;
- for (int i = 0; i <= 10; i++)
- {
- doc = newdwg();
- using (DocumentLock docl = doc.LockDocument())
- {
- db = doc.Database;
- dwl(db);
- }
- sclose(doc, i);
- }
-
- }
- private void sclose(Document doc,int i)
- {
- doc.Database.SaveAs("d:\\00 dwg\\"+i+".DWG",DwgVersion.Current);
- doc.CloseAndDiscard();
- }
- private void dwl(Database db)
- {
- Point3d p1 = Point3d.Origin;
- double r = 100;
- Circle c = new Circle();
- c.Center = p1;
- c.Radius = r;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = tr.GetObject(db.BlockTableId,OpenMode.ForRead) as BlockTable;
- BlockTableRecord btr=tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite)as BlockTableRecord;
- btr.AppendEntity(c);
- tr.AddNewlyCreatedDBObject(c, true);
- tr.Commit();
- }
- }
- private Document newdwg()
- {
- string strTemplatePath = "acad.dwt";
- DocumentCollection acDocMgr = Application.DocumentManager;
- Document acDoc = acDocMgr.Add(strTemplatePath);
- return acDocMgr.MdiActiveDocument = acDoc;
- }
- }
- }
- ----------------------------
- vs2010+CAD2012,运行时,每次得打开默认的文件才能保存一个新生成的文件,不知道哪里有问题了,请高手帮忙把脉。非常感谢
|
|