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