明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1231|回复: 4

求助:这些代码生成DLL,无法调用

[复制链接]
发表于 2009-5-21 11:28:00 | 显示全部楼层 |阅读模式

VBA代码:

Dim aa As New 工程1.Class1
Sub ff()
aa.xuexi3
End Sub

VB代码:

Option Explicit

Public Function addline(ByVal document As AcadDocument, ByVal ptSt As Variant, ByVal ptEn As Variant) As AcadLine

    Set addline = document.ModelSpace.addline(ptSt, ptEn)

End Function

 

Sub ABC()

On error resume next

Dim objline As AcadLine

Dim acadapp As AcadApplication

Dim acaddoc As AcadDocument

Set acaddoc = acadapp.ActiveDocument

Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double

pt1(0) = 10: pt1(1) = 10: pt1(2) = 0

pt2(0) = 150: pt2(1) = 150: pt2(2) = 0

     Set objline = acaddoc.ModelSpace.addline(pt1, pt2)

objline.Update

End Sub

 

Sub xuexi3()

Dim acadapp As Object 'AcadApplication '

Dim acaddoc As Object

Set acadapp = GetObject(, "AutoCAD.Application")

Set acaddoc = acadapp.ActiveDocument

acadapp.WindowState = acMax

Call ABC

End Sub

发表于 2009-5-21 12:32:00 | 显示全部楼层

应该把acadapp 、acaddoc 声明为模块级变量

 楼主| 发表于 2009-5-21 13:47:00 | 显示全部楼层

将两句提前

Dim acadapp As AcadApplication

Dim acaddoc As AcadDocument

不行;改为

public acadapp As AcadApplication

public acaddoc As AcadDocument

也不行.

发表于 2009-5-21 14:07:00 | 显示全部楼层

Option Explicit

private acadapp As AcadApplication

Sub ABC()
On error resume next

Dim doc As AcadDocument
Set doc = acadapp.ActiveDocument

Dim objline As AcadLine
Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double
pt1(0) = 10: pt1(1) = 10: pt1(2) = 0
pt2(0) = 150: pt2(1) = 150: pt2(2) = 0
Set objline = doc.ModelSpace.addline(pt1, pt2)

End Sub

Sub xuexi3()
Set acadapp = GetObject(, "AutoCAD.Application")
acadapp.WindowState = acMax
Call ABC
End Sub

 楼主| 发表于 2009-5-21 14:50:00 | 显示全部楼层
多谢板主,可以实现了,我的邮箱:sjsjgcl@163.com
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-26 03:21 , Processed in 0.161508 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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