乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 39|回复: 2

vb.net调用AUTOCAD画线生成的DLL,不能调用

[复制链接]

6

主题

17

帖子

3

银币

初来乍到

Rank: 1

铜币
41
发表于 2012-2-23 15:18:00 | 显示全部楼层 |阅读模式
我先问的是这个意思,就是我用 vb.net编制了一个连接CAD画图的程序,编译后生成DLL。然后我重新用VB.NET做一窗体程序引用他,但为什么就不成功呢?
下面是画线代码:
Imports Autodesk..Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Public Class Class1
    Public Sub AddLine()
        ConnectToAcad()
        '' 获得当前文档和数据库   Get the current document and database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
        Dim sPoint As Point3d = New Point3d(0, 1, 1)
        Dim ePoint As Point3d = New Point3d(4, 1, 1)
        ''启动一个事务   Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            '' 以只读方式打开块表   Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
            '' 以写方式打开模型空间块表记录   Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                            OpenMode.ForWrite)
            '' 创建一条起点为(5,5,0),终点为(12,3,0)的直线  Create a line that starts at 5,5 and ends at 12,3
            'Dim acLine As Line = New Line(New Point3d(5, 5, 0), New Point3d(12, 3, 0))
            Dim acLine As Line = New Line(sPoint, ePoint)
            acLine.SetDatabaseDefaults()
            '' 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(acLine)
            acTrans.AddNewlyCreatedDBObject(acLine, True)
            '' 保存新对象到数据库中   Save the new object to the database
            acTrans.Commit()
        End Using
    End Sub
    Public Sub ConnectToAcad()
        Dim acAppComObj As AcadApplication
        Dim strProgId As String = "AutoCAD.Application.18"
        On Error Resume Next
        '' 获得一个正在运行的 AutoCAD 的实例  Get a running instance of AutoCAD
        acAppComObj = GetObject(, strProgId)
        '' 如果没有正在运行的实例将出现一个错误 An error occurs if no instance is running
        If Err.Number > 0 Then
            Err.Clear()
            '' 创建一个新的AutoCAD的实例  Create a new instance of AutoCAD
            acAppComObj = CreateObject("AutoCAD.Application.18")
            '' 检查 AutoCAD 的实例是否被创建  Check to see if an instance of AutoCAD was created
            If Err.Number > 0 Then
                Err.Clear()
                ''如果 AutoCAD 的实例没有创建,那么发出一个信息并退出  If an instance of AutoCAD is not created then message and exit
                MsgBox("Instance of 'AutoCAD.Application' could not be created.")
                Exit Sub
            End If
        End If
        ''显示应用程序并返回名字和版本号  Display the application and return the name and version
        acAppComObj.Visible = True
        acAppComObj.WindowState = AcWindowState.acMax
        'MsgBox("Now running " & acAppComObj.Name & " version " & acAppComObj.Version)
        ''获得活动的文档   Get the active document
        Dim acDocComObj As AcadDocument
        acDocComObj = acAppComObj.ActiveDocument
        ''可选的,加载你的程序集并启动你的命令,如果你的程序集已经被加载,那就仅仅只启动命令
        '' Optionally, load your assembly and start your command or if your assembly
        '' is demandloaded, simply start the command of your in-process assembly.
        'acDocComObj.SendCommand("(command " & Chr(34) & "NETLOAD" & Chr(34) & " " & _
        '                        Chr(34) & "c:/myapps/mycommands.dll" & Chr(34) & ") ")
        'acDocComObj.SendCommand("MyCommand ")
    End Sub
End Class
译后生成了  drline.dll文件
调用:
Imports drLine.Class1
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim aa As New drLine.Class1
        aa.AddLine()  ‘出错’出错’
    End Sub
End Class
回复

使用道具 举报

4

主题

20

帖子

1

银币

初来乍到

Rank: 1

铜币
36
发表于 2012-2-23 18:53:00 | 显示全部楼层
。。。你这个没法看啊,你在你的aa.addline里加个断点,然后用调试模式启动CAD再加载DLL运行,运行到断点的地方会停住,然后你单步,就能看出来哪过不去了。。这个整个函数都出错,不好看啊
回复

使用道具 举报

5

主题

21

帖子

3

银币

初来乍到

Rank: 1

铜币
41
发表于 2012-5-24 23:44:00 | 显示全部楼层
看你的代码是用COM来写的,但你的代码既有.NET托管的代码又有COM方式的代码,不知道是不是这个原因.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-6-29 19:07 , Processed in 0.706934 second(s), 59 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表