我在cad命令行里加载dll,能够生成需要的图形.保存!问题出在我全部关闭cad时.cad 出现如图所示情况!.请大侠帮忙一下!谢谢!(虽然下次打开cad都没问题,但是每次都出现这样的对话框,感觉很烦人!希望高手能告知破解的方法! 不胜感激! 附上代码!(主要就是在当前cad 图形中加入圆,加入外部块,文字等) using System; using System.Collections.Generic; using System.Text; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Geometry; using System.IO; using Autodesk.AutoCAD.DatabaseServices; namespace ClassLibrary2 { public
class Class1 { [CommandMethod("HelloWorld")] public
void HelloWorld() { int kk; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; string name1; ed.WriteMessage("Hello World"); Circle circle; //这个是我们要加入到模型空间的圆 BlockTableRecord btr;//要加入圆,我们必须打开模型空间 BlockTable bt; //要打开模型空间,我们必须通过块表(BlockTable)来访问它 //我们使用一个名为‘Transaction’的对象,把函数中有关数据库的操作封装起来 Transaction trans; //使用TransactionManager的StartTransaction()成员来开始事务处理 trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction(); //现在创建圆……请仔细看这些参数——注意创建Point3d对象的‘New’和Vector3d的静态成员ZAxis circle = new Circle(new Point3d(10, 10, 0), Vector3d.ZAxis, 2); circle.ColorIndex = 2; bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead); //使用当前的空间Id来获取块表记录——注意我们是打开它用来写入 btr = (BlockTableRecord)trans.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite); //现在使用btr对象来加入圆 btr.AppendEntity(circle); trans.AddNewlyCreatedDBObject(circle, true); //并确定事务处理知道要加入圆! DBText mytext = new DBText(); mytext.TextString = "B3-052-01-00"; mytext.HorizontalMode = TextHorizontalMode.TextLeft; mytext.VerticalMode = TextVerticalMode.TextVerticalMid; mytext.AlignmentPoint = new Point3d(3.286, 88.7556, 0); mytext.Height = 12; mytext.WidthFactor = 2; btr.AppendEntity(mytext); trans.AddNewlyCreatedDBObject(mytext, true); Document doc = Application.DocumentManager.MdiActiveDocument; string fname = "c:\\123.dwg";// "C:\\12341.DWG"; if (!File.Exists(fname)) fname = HostApplicationServices.Current.FindFile(fname, doc.Database, FindFileHint.Default); Database db = new Database(false, false); db.ReadDwgFile(fname, FileShare.Read, true, null); ObjectId idBTR = doc.Database.Insert("test", db, false); BlockReference bref = new BlockReference(Point3d.Origin, idBTR); btr.AppendEntity(bref); trans.AddNewlyCreatedDBObject(bref, true); trans.Commit(); trans.Dispose(); } else { return; } } } } |