mikewolf2k 发表于 2005-10-13 22:41:00

[求助]关于sendcommand的疑问

<P>在vba中用sendcommand,好像与vba执行并不是同步的,比如下面这段代码,多次执行的结果并不是相同的,请问有什么办法能确保sendcommand的语句在acad中执行完毕后再执行sendcommand下一句vb代码?</P>
<P>Sub bb()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 0 &amp; "," &amp; 0 &amp; """ ""2"" ""0"" """ &amp; "0" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 1 &amp; "," &amp; 1 &amp; """ ""2"" ""0"" """ &amp; "1" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 2 &amp; "," &amp; 2 &amp; """ ""2"" ""0"" """ &amp; "2" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 3 &amp; "," &amp; 3 &amp; """ ""2"" ""0"" """ &amp; "3" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 4 &amp; "," &amp; 4 &amp; """ ""2"" ""0"" """ &amp; "4" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 5 &amp; "," &amp; 5 &amp; """ ""2"" ""0"" """ &amp; "5" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 6 &amp; "," &amp; 6 &amp; """ ""2"" ""0"" """ &amp; "6" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 7 &amp; "," &amp; 7 &amp; """ ""2"" ""0"" """ &amp; "7" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 8 &amp; "," &amp; 8 &amp; """ ""2"" ""0"" """ &amp; "8" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 9 &amp; "," &amp; 9 &amp; """ ""2"" ""0"" """ &amp; "9" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lsp = "(command ""text"" ""mc"" """ &amp; 10 &amp; "," &amp; 10 &amp; """ ""2"" ""0"" """ &amp; "10" &amp; """)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveDocument.SendCommand lsp &amp; vbCr</P>
<P>End Sub<BR></P>

alin 发表于 2005-10-16 13:31:00

就为了生成几个简单的文字,不用那么复杂吧。读你的程序的人会有麻烦的。

lgf727 发表于 2005-10-16 16:15:00

没有办法

mikewolf2k 发表于 2005-10-16 18:50:00

alin发表于2005-10-16 13:31:00static/image/common/back.gif就为了生成几个简单的文字,不用那么复杂吧。读你的程序的人会有麻烦的。

<BR>我只是举例说明连续写text时会出现问题,当然不是实际上这么用。

雪山飞狐_lzh 发表于 2005-10-16 20:02:00

<P>一定要可以这样</P>
<P>&nbsp;&nbsp;&nbsp; lsp = "(progn (setvar ""cmdecho"" 0) "<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 0 &amp; "," &amp; 0 &amp; """ ""2"" ""0"" """ &amp; "0" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 1 &amp; "," &amp; 1 &amp; """ ""2"" ""0"" """ &amp; "1" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 2 &amp; "," &amp; 2 &amp; """ ""2"" ""0"" """ &amp; "2" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 3 &amp; "," &amp; 3 &amp; """ ""2"" ""0"" """ &amp; "3" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 4 &amp; "," &amp; 4 &amp; """ ""2"" ""0"" """ &amp; "4" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 5 &amp; "," &amp; 5 &amp; """ ""2"" ""0"" """ &amp; "5" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 6 &amp; "," &amp; 6 &amp; """ ""2"" ""0"" """ &amp; "6" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 7 &amp; "," &amp; 7 &amp; """ ""2"" ""0"" """ &amp; "7" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 8 &amp; "," &amp; 8 &amp; """ ""2"" ""0"" """ &amp; "8" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 9 &amp; "," &amp; 9 &amp; """ ""2"" ""0"" """ &amp; "9" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(command ""text"" ""mc"" """ &amp; 10 &amp; "," &amp; 10 &amp; """ ""2"" ""0"" """ &amp; "10" &amp; """)"<BR>&nbsp;&nbsp;&nbsp; lsp = lsp &amp; "(setvar ""cmdecho"" 1))"<BR>&nbsp;&nbsp;&nbsp; Dim fso As New FileSystemObject<BR>&nbsp;&nbsp;&nbsp; Dim ts As TextStream<BR>&nbsp;&nbsp;&nbsp; Set ts = fso.CreateTextFile("d:\mycmd.lsp")<BR>&nbsp;&nbsp;&nbsp; ts.Write lsp<BR>&nbsp;&nbsp;&nbsp; ts.Close<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.SendCommand "(load ""d:\mycmd.lsp"")" &amp; vbCr<BR>&nbsp;&nbsp;&nbsp; Kill "d:\mycmd.lsp"</P>
<P>&nbsp;</P>

cbse_smy 发表于 2005-10-17 13:54:00

这个问题我很就遇到了,我是求各一个任意线条的均分点,因为CAD中没有这样的函数,所以只有用SendCommand,但是经常出错,如果单步执行,则从不出错。

mikewolf2k 发表于 2005-10-17 18:45:00

<P>请版主指定5楼代码要加载什么库。</P>
<P>另外我的程序是写一个文本,然后用vb对该文本进行一些设置,比如字高、字宽等。必须等lisp执行完后再执行下一句vb代码,这样可以吗?</P>

alin 发表于 2005-10-17 21:20:00

Microsoft Scripting Runtime

mikewolf2k 发表于 2005-10-17 22:11:00

还是有问题,一步步执行可以,连续执行不行。而且一步步执行的结果也不对,同样各次运行的结果也不一定相同。
页: [1]
查看完整版本: [求助]关于sendcommand的疑问