[求助]VB.NET C#使用AxDbDocument 报错
<p>VS2005 中VB遇到的问题cad2009版本<br/>Imports CAD = Autodesk.AutoCAD.Interop<br/>Imports CADCommon = Autodesk.AutoCAD.Interop.Common</p><p>Dim axc As Object '或者定义成CADCommon.AxDbDocument </p><p>axc = New CADCommon.AxDbDocument()</p><p>执行第2句是报错,尝试读取或写入受保护的内存。这通常指示其他内存已损坏</p><p>或者使用</p><p>axc = Microsoft.VisualBasic.Interaction.CreateObject("ObjectDBX.AxDbDocument.17")</p><p>报错 无法创建ActiveX组建,429错误</p><p>但是上述两种方法我在VBA里面都是可以正常运行的</p><p>Dim DBsor As AxDbDocument</p><p>Set DBsor = New AxDbDocument</p><p>或者</p><p>If Left(Version, 2) = "15" Then '2000-2002<br/> Set DBsor = CreateObject("ObjectDBX.AxDbDocument.1")<br/> ElseIf Left(Version, 2) = "16" Then '2004<br/> Set DBsor = CreateObject("ObjectDBX.AxDbDocument.16")<br/> ElseIf Left(Version, 2) = 17 Then '2009<br/> Set DBsor = CreateObject("ObjectDBX.AxDbDocument.17")<br/> End IF</p><p>这两种方法在VBA中都是可以正常运行的,并且后来的使用DBsor 的图形操作也都成功了</p><p></p><p>VS2005 中C#遇到的同样问题cad2009版本</p><p>using AutoCAD=Autodesk.AutoCAD.Interop;<br/>using AXDBLib = Autodesk.AutoCAD.Interop.Common;</p><p>public AXDBLib.AxDbDocumentClass AXDB1 //或者定义成Object </p><p>AXDB1 = new Autodesk.AutoCAD.Interop.Common.AxDbDocumentClass();</p><p>执行第2句是报错,尝试读取或写入受保护的内存。这通常指示其他内存已损坏</p><p></p><p><cq></cq></p> <p>ObjectDbx必须在Cad环境下才能用,先获取AutoCad的Application,</p><p>再试下<br/>App.GetInterfaceObject("ObjectDBX.AxDbDocument")</p><p>不过2009怎么还用Com?</p> <p>Imports CAD = Autodesk.AutoCAD.Interop<br/>Imports CADCommon = Autodesk.AutoCAD.Interop.Common </p><p> Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click<br/> Dim capp As CAD.AcadApplication ' Autodesk.AutoCAD.Interop.AcadApplication<br/> capp = New Autodesk.AutoCAD.Interop.AcadApplication()</p><p> 'capp = CreateObject("AutoCAD.Application")<br/> 'capp = GetObject(, "AutoCAD.Application")<br/> capp.Visible = True<br/> Dim axc As CADCommon.AxDbDocument 'Object ' ' Autodesk.AutoCAD.Interop.Common.AxDbDocument<br/> Dim pa As String<br/> pa = "D:\Drawing1.dwg"</p><p> 'On Error Resume Next<br/> 'axc = New CADCommon.AxDbDocument()<br/> axc = capp.GetInterfaceObject("ObjectDBX.AxDbDocument.17")<br/> 'axc = Microsoft.VisualBasic.Interaction.CreateObject("ObjectDBX.AxDbDocument.17")<br/> 'MsgBox(Err.Description & Err.Number)<br/> axc.Open(pa)<br/> 'capp.Documents.Add()<br/> Dim o1(0 To 2) As Double<br/> Dim o2(0 To 2) As Double<br/> o1(0) = 1<br/> o1(1) = 1<br/> o1(2) = 1<br/> o2(0) = 100<br/> o2(1) = 100<br/> o2(2) = 100<br/> axc.ModelSpace.AddLine(o1, o2)<br/> axc.SaveAs(pa)<br/> End Sub</p><p>谢谢,我已经按照您的方法GetInterfaceObject("ObjectDBX.AxDbDocument.17")在VB.net中实现了AxDbDocument使用</p><p>那为什么说2009还用com,那应该用什么呢?</p> <p>这里主要是关于讨论ObjectArx.Net开发的:)</p><p>Com的最好发到VBA\VB版</p>
页:
[1]