gsteven 发表于 2009-9-13 18:32:00

[求助]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/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set DBsor = CreateObject("ObjectDBX.AxDbDocument.1")<br/>&nbsp;&nbsp;&nbsp; ElseIf Left(Version, 2) = "16" Then '2004<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set DBsor = CreateObject("ObjectDBX.AxDbDocument.16")<br/>&nbsp;&nbsp;&nbsp; ElseIf Left(Version, 2) = 17 Then '2009<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set DBsor = CreateObject("ObjectDBX.AxDbDocument.17")<br/>&nbsp;&nbsp;&nbsp; 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>

雪山飞狐_lzh 发表于 2009-9-13 18:47:00

<p>ObjectDbx必须在Cad环境下才能用,先获取AutoCad的Application,</p><p>再试下<br/>App.GetInterfaceObject("ObjectDBX.AxDbDocument")</p><p>不过2009怎么还用Com?</p>

gsteven 发表于 2009-9-13 20:29:00

<p>Imports CAD = Autodesk.AutoCAD.Interop<br/>Imports CADCommon = Autodesk.AutoCAD.Interop.Common&nbsp;&nbsp;&nbsp;</p><p>&nbsp;Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim capp As CAD.AcadApplication ' Autodesk.AutoCAD.Interop.AcadApplication<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; capp = New Autodesk.AutoCAD.Interop.AcadApplication()</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'capp = CreateObject("AutoCAD.Application")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'capp = GetObject(, "AutoCAD.Application")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; capp.Visible = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim axc As CADCommon.AxDbDocument 'Object ' ' Autodesk.AutoCAD.Interop.Common.AxDbDocument<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim pa As String<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pa = "D:\Drawing1.dwg"</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'On Error Resume Next<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'axc = New CADCommon.AxDbDocument()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axc = capp.GetInterfaceObject("ObjectDBX.AxDbDocument.17")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'axc = Microsoft.VisualBasic.Interaction.CreateObject("ObjectDBX.AxDbDocument.17")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'MsgBox(Err.Description &amp; Err.Number)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axc.Open(pa)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'capp.Documents.Add()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim o1(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim o2(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o1(0) = 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o1(1) = 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o1(2) = 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o2(0) = 100<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o2(1) = 100<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o2(2) = 100<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axc.ModelSpace.AddLine(o1, o2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axc.SaveAs(pa)<br/>&nbsp;&nbsp;&nbsp; End Sub</p><p>谢谢,我已经按照您的方法GetInterfaceObject("ObjectDBX.AxDbDocument.17")在VB.net中实现了AxDbDocument使用</p><p>那为什么说2009还用com,那应该用什么呢?</p>

雪山飞狐_lzh 发表于 2009-9-13 20:39:00

<p>这里主要是关于讨论ObjectArx.Net开发的:)</p><p>Com的最好发到VBA\VB版</p>
页: [1]
查看完整版本: [求助]VB.NET C#使用AxDbDocument 报错