明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2253|回复: 3

[求助]VB.NET C#使用AxDbDocument 报错

[复制链接]
发表于 2009-9-13 18:32 | 显示全部楼层 |阅读模式

VS2005 中VB遇到的问题cad2009版本
Imports CAD = Autodesk.AutoCAD.Interop
Imports CADCommon = Autodesk.AutoCAD.Interop.Common

Dim axc As Object '或者定义成CADCommon.AxDbDocument

axc = New CADCommon.AxDbDocument()

执行第2句是报错,尝试读取或写入受保护的内存。这通常指示其他内存已损坏

或者使用

axc = Microsoft.VisualBasic.Interaction.CreateObject("ObjectDBX.AxDbDocument.17")

报错 无法创建ActiveX组建,429错误

但是上述两种方法我在VBA里面都是可以正常运行的

Dim DBsor As AxDbDocument

Set DBsor = New AxDbDocument

或者

If Left(Version, 2) = "15" Then '2000-2002
        Set DBsor = CreateObject("ObjectDBX.AxDbDocument.1")
    ElseIf Left(Version, 2) = "16" Then '2004
        Set DBsor = CreateObject("ObjectDBX.AxDbDocument.16")
    ElseIf Left(Version, 2) = 17 Then '2009
        Set DBsor = CreateObject("ObjectDBX.AxDbDocument.17")
    End IF

这两种方法在VBA中都是可以正常运行的,并且后来的使用DBsor 的图形操作也都成功了

VS2005 中C#遇到的同样问题cad2009版本

using AutoCAD=Autodesk.AutoCAD.Interop;
using AXDBLib = Autodesk.AutoCAD.Interop.Common;

public AXDBLib.AxDbDocumentClass AXDB1 //或者定义成Object

AXDB1 = new Autodesk.AutoCAD.Interop.Common.AxDbDocumentClass();

执行第2句是报错,尝试读取或写入受保护的内存。这通常指示其他内存已损坏

发表于 2009-9-13 18:47 | 显示全部楼层

ObjectDbx必须在Cad环境下才能用,先获取AutoCad的Application,

再试下
App.GetInterfaceObject("ObjectDBX.AxDbDocument")

不过2009怎么还用Com?

 楼主| 发表于 2009-9-13 20:29 | 显示全部楼层

Imports CAD = Autodesk.AutoCAD.Interop
Imports CADCommon = Autodesk.AutoCAD.Interop.Common   

 rivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim capp As CAD.AcadApplication ' Autodesk.AutoCAD.Interop.AcadApplication
        capp = New Autodesk.AutoCAD.Interop.AcadApplication()

        'capp = CreateObject("AutoCAD.Application")
        'capp = GetObject(, "AutoCAD.Application")
        capp.Visible = True
        Dim axc As CADCommon.AxDbDocument 'Object ' ' Autodesk.AutoCAD.Interop.Common.AxDbDocument
        Dim pa As String
        pa = "D:\Drawing1.dwg"

        'On Error Resume Next
        'axc = New CADCommon.AxDbDocument()
        axc = capp.GetInterfaceObject("ObjectDBX.AxDbDocument.17")
        'axc = Microsoft.VisualBasic.Interaction.CreateObject("ObjectDBX.AxDbDocument.17")
        'MsgBox(Err.Description & Err.Number)
        axc.Open(pa)
        'capp.Documents.Add()
        Dim o1(0 To 2) As Double
        Dim o2(0 To 2) As Double
        o1(0) = 1
        o1(1) = 1
        o1(2) = 1
        o2(0) = 100
        o2(1) = 100
        o2(2) = 100
        axc.ModelSpace.AddLine(o1, o2)
        axc.SaveAs(pa)
    End Sub

谢谢,我已经按照您的方法GetInterfaceObject("ObjectDBX.AxDbDocument.17")在VB.net中实现了AxDbDocument使用

那为什么说2009还用com,那应该用什么呢?

发表于 2009-9-13 20:39 | 显示全部楼层

这里主要是关于讨论ObjectArx.Net开发的:)

Com的最好发到VBA\VB版

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-10 23:59 , Processed in 0.140318 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表