明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1992|回复: 8

[求助]关于sendcommand的疑问

[复制链接]
发表于 2005-10-13 22:41:00 | 显示全部楼层 |阅读模式

在vba中用sendcommand,好像与vba执行并不是同步的,比如下面这段代码,多次执行的结果并不是相同的,请问有什么办法能确保sendcommand的语句在acad中执行完毕后再执行sendcommand下一句vb代码?

Sub bb()
      lsp = "(command ""text"" ""mc"" """ & 0 & "," & 0 & """ ""2"" ""0"" """ & "0" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 1 & "," & 1 & """ ""2"" ""0"" """ & "1" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 2 & "," & 2 & """ ""2"" ""0"" """ & "2" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 3 & "," & 3 & """ ""2"" ""0"" """ & "3" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 4 & "," & 4 & """ ""2"" ""0"" """ & "4" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 5 & "," & 5 & """ ""2"" ""0"" """ & "5" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 6 & "," & 6 & """ ""2"" ""0"" """ & "6" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 7 & "," & 7 & """ ""2"" ""0"" """ & "7" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 8 & "," & 8 & """ ""2"" ""0"" """ & "8" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 9 & "," & 9 & """ ""2"" ""0"" """ & "9" & """)"
      ActiveDocument.SendCommand lsp & vbCr
      lsp = "(command ""text"" ""mc"" """ & 10 & "," & 10 & """ ""2"" ""0"" """ & "10" & """)"
      ActiveDocument.SendCommand lsp & vbCr

End Sub

发表于 2005-10-16 13:31:00 | 显示全部楼层
就为了生成几个简单的文字,不用那么复杂吧。读你的程序的人会有麻烦的。
发表于 2005-10-16 16:15:00 | 显示全部楼层
没有办法
 楼主| 发表于 2005-10-16 18:50:00 | 显示全部楼层
alin发表于2005-10-16 13:31:00就为了生成几个简单的文字,不用那么复杂吧。读你的程序的人会有麻烦的。

我只是举例说明连续写text时会出现问题,当然不是实际上这么用。
发表于 2005-10-16 20:02:00 | 显示全部楼层

一定要可以这样

    lsp = "(progn (setvar ""cmdecho"" 0) "
    lsp = lsp & "(command ""text"" ""mc"" """ & 0 & "," & 0 & """ ""2"" ""0"" """ & "0" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 1 & "," & 1 & """ ""2"" ""0"" """ & "1" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 2 & "," & 2 & """ ""2"" ""0"" """ & "2" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 3 & "," & 3 & """ ""2"" ""0"" """ & "3" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 4 & "," & 4 & """ ""2"" ""0"" """ & "4" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 5 & "," & 5 & """ ""2"" ""0"" """ & "5" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 6 & "," & 6 & """ ""2"" ""0"" """ & "6" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 7 & "," & 7 & """ ""2"" ""0"" """ & "7" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 8 & "," & 8 & """ ""2"" ""0"" """ & "8" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 9 & "," & 9 & """ ""2"" ""0"" """ & "9" & """)"
    lsp = lsp & "(command ""text"" ""mc"" """ & 10 & "," & 10 & """ ""2"" ""0"" """ & "10" & """)"
    lsp = lsp & "(setvar ""cmdecho"" 1))"
    Dim fso As New FileSystemObject
    Dim ts As TextStream
    Set ts = fso.CreateTextFile("d:\mycmd.lsp")
    ts.Write lsp
    ts.Close
    ThisDrawing.SendCommand "(load ""d:\mycmd.lsp"")" & vbCr
    Kill "d:\mycmd.lsp"

 

发表于 2005-10-17 13:54:00 | 显示全部楼层
这个问题我很就遇到了,我是求各一个任意线条的均分点,因为CAD中没有这样的函数,所以只有用SendCommand,但是经常出错,如果单步执行,则从不出错。
 楼主| 发表于 2005-10-17 18:45:00 | 显示全部楼层

请版主指定5楼代码要加载什么库。

另外我的程序是写一个文本,然后用vb对该文本进行一些设置,比如字高、字宽等。必须等lisp执行完后再执行下一句vb代码,这样可以吗?

发表于 2005-10-17 21:20:00 | 显示全部楼层
Microsoft Scripting Runtime
 楼主| 发表于 2005-10-17 22:11:00 | 显示全部楼层
还是有问题,一步步执行可以,连续执行不行。而且一步步执行的结果也不对,同样各次运行的结果也不一定相同。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-27 10:34 , Processed in 0.181288 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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