[求助]关于sendcommand的疑问
在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
就为了生成几个简单的文字,不用那么复杂吧。读你的程序的人会有麻烦的。 没有办法
我只是举例说明连续写text时会出现问题,当然不是实际上这么用。 一定要可以这样
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"
这个问题我很就遇到了,我是求各一个任意线条的均分点,因为CAD中没有这样的函数,所以只有用SendCommand,但是经常出错,如果单步执行,则从不出错。 请版主指定5楼代码要加载什么库。
另外我的程序是写一个文本,然后用vb对该文本进行一些设置,比如字高、字宽等。必须等lisp执行完后再执行下一句vb代码,这样可以吗?
Microsoft Scripting Runtime 还是有问题,一步步执行可以,连续执行不行。而且一步步执行的结果也不对,同样各次运行的结果也不一定相同。
页:
[1]