[求助]关于sendcommand的疑问
<P>在vba中用sendcommand,好像与vba执行并不是同步的,比如下面这段代码,多次执行的结果并不是相同的,请问有什么办法能确保sendcommand的语句在acad中执行完毕后再执行sendcommand下一句vb代码?</P><P>Sub bb()<BR> lsp = "(command ""text"" ""mc"" """ & 0 & "," & 0 & """ ""2"" ""0"" """ & "0" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 1 & "," & 1 & """ ""2"" ""0"" """ & "1" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 2 & "," & 2 & """ ""2"" ""0"" """ & "2" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 3 & "," & 3 & """ ""2"" ""0"" """ & "3" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 4 & "," & 4 & """ ""2"" ""0"" """ & "4" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 5 & "," & 5 & """ ""2"" ""0"" """ & "5" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 6 & "," & 6 & """ ""2"" ""0"" """ & "6" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 7 & "," & 7 & """ ""2"" ""0"" """ & "7" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 8 & "," & 8 & """ ""2"" ""0"" """ & "8" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 9 & "," & 9 & """ ""2"" ""0"" """ & "9" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr<BR> lsp = "(command ""text"" ""mc"" """ & 10 & "," & 10 & """ ""2"" ""0"" """ & "10" & """)"<BR> ActiveDocument.SendCommand lsp & vbCr</P>
<P>End Sub<BR></P> 就为了生成几个简单的文字,不用那么复杂吧。读你的程序的人会有麻烦的。 没有办法 alin发表于2005-10-16 13:31:00static/image/common/back.gif就为了生成几个简单的文字,不用那么复杂吧。读你的程序的人会有麻烦的。
<BR>我只是举例说明连续写text时会出现问题,当然不是实际上这么用。 <P>一定要可以这样</P>
<P> lsp = "(progn (setvar ""cmdecho"" 0) "<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 0 & "," & 0 & """ ""2"" ""0"" """ & "0" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 1 & "," & 1 & """ ""2"" ""0"" """ & "1" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 2 & "," & 2 & """ ""2"" ""0"" """ & "2" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 3 & "," & 3 & """ ""2"" ""0"" """ & "3" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 4 & "," & 4 & """ ""2"" ""0"" """ & "4" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 5 & "," & 5 & """ ""2"" ""0"" """ & "5" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 6 & "," & 6 & """ ""2"" ""0"" """ & "6" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 7 & "," & 7 & """ ""2"" ""0"" """ & "7" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 8 & "," & 8 & """ ""2"" ""0"" """ & "8" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 9 & "," & 9 & """ ""2"" ""0"" """ & "9" & """)"<BR> lsp = lsp & "(command ""text"" ""mc"" """ & 10 & "," & 10 & """ ""2"" ""0"" """ & "10" & """)"<BR> lsp = lsp & "(setvar ""cmdecho"" 1))"<BR> Dim fso As New FileSystemObject<BR> Dim ts As TextStream<BR> Set ts = fso.CreateTextFile("d:\mycmd.lsp")<BR> ts.Write lsp<BR> ts.Close<BR> ThisDrawing.SendCommand "(load ""d:\mycmd.lsp"")" & vbCr<BR> Kill "d:\mycmd.lsp"</P>
<P> </P> 这个问题我很就遇到了,我是求各一个任意线条的均分点,因为CAD中没有这样的函数,所以只有用SendCommand,但是经常出错,如果单步执行,则从不出错。 <P>请版主指定5楼代码要加载什么库。</P>
<P>另外我的程序是写一个文本,然后用vb对该文本进行一些设置,比如字高、字宽等。必须等lisp执行完后再执行下一句vb代码,这样可以吗?</P> Microsoft Scripting Runtime 还是有问题,一步步执行可以,连续执行不行。而且一步步执行的结果也不对,同样各次运行的结果也不一定相同。
页:
[1]