明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1679|回复: 1

vla-runmacro的使用问题

[复制链接]
发表于 2007-4-23 08:44:00 | 显示全部楼层 |阅读模式

下面的VBA小程序在IDE环境下可以正常运行, 可用vla-runmacro调用时,不能正常运行, 不知道是什么原因.

1. VBA小程序

内容: 连续指定圆心, 画半径5的圆, 画错时输入u删除, 按回车健中止程序.

'文件名设定为 uuu.dvb, 内容如下

Option Explicit

Public Sub UUU()

    Dim circleObj As AcadCircle

    Dim centerPoint(0 To 2) As Double

    Dim radius As Double

    Dim keywordList As String

    Dim inputString As String

    Dim i As Integer

    Dim ifloop As Integer

    Dim returnPnt As Variant

    keywordList = "Undo"

    radius = 5#

    ifloop = 0

    i = 0

Do

  ThisDrawing.StartUndoMark

MARKUNDO:

  On Error GoTo myerror

  ThisDrawing.Utility.InitializeUserInput 128, keywordList

  returnPnt = ThisDrawing.Utility.GetPoint(, "圆心:")

  centerPoint(0) = returnPnt(0)

  centerPoint(1) = returnPnt(1)

  centerPoint(2) = returnPnt(2)

  Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius)

  ThisDrawing.EndUndoMark

Loop While ifloop = 0

myerror:

  If Err Then

     Err.Clear

     inputString = ThisDrawing.Utility.GetInput

     Select Case inputString

        Case "Undo"

           ThisDrawing.EndUndoMark

           ThisDrawing.SendCommand "_Undo 2 "

           ThisDrawing.StartUndoMark

           Resume MARKUNDO

        Case ""

           Exit Sub

        Case Else

           MsgBox "无效关键字:" & inputString, vbOKOnly, "Input keyword"

           ThisDrawing.Utility.InitializeUserInput 128, keywordList

           i = i + 1

           If i <= 1 Then

               Resume

           Else

               ThisDrawing.EndUndoMark

               Exit Sub

           End If

     End Select

  End If

End Sub

 

2. 用vla-runmacro调用上面的VBA宏(我把上面的VBA文件uuu.dvb定义在硬盘的C的根目录下)

   (vl-load-com)

   (vla-runmacro (vlax-get-acad-object) "c:\\uuu.dvb!uuu")

运行时,可以正常画圆, 但当画错要修改时, 输入u, 就出错.

错误总是与  ThisDrawing.SendCommand "_Undo 2 "  语句有关, 不知道什么原因,

恳请指教.

下面的附加文件为 uuu.dvb

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2007-5-1 21:14:00 | 显示全部楼层

自己编写撤消机制,不要用undo。

这应该很简单。可以这样做,添加对象时记住对象的ID,撤消时就删除指定的ID的对象。

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

本版积分规则

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

GMT+8, 2025-2-22 18:47 , Processed in 0.254006 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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