chpmould 发表于 2010-6-8 00:00:00

VB调用LISP程序

<font face="Verdana" color="#0000ff">请教各位高手,首先当我们打开CAD之后,然后运行一个VB程序来调用一个LISP程序如何实现!!!</font>

guohq 发表于 2010-6-8 08:32:00

<p>伪代码</p>
<p>set cad = getobject()</p>
<p>cad.ActiveDocument.sendcommond "lisp命令"</p>

chpmould 发表于 2010-6-8 17:50:00

楼上的朋友能否具体一点啊,VB我不熟

guohq 发表于 2010-6-9 00:17:00

<p><font face="Verdana">第一步:在VBAIDE里先定义 GetCurveLen宏</font></p>
<p><font face="Verdana"></font>&nbsp;</p>
<p><font face="Verdana">Public Sub GetCurveLen()<br/>&nbsp;&nbsp;&nbsp; '利用VLisp计算曲线长度<br/>&nbsp;&nbsp;&nbsp; Dim LispPath As String<br/>&nbsp;&nbsp;&nbsp; LispPath = "c:\Getlen.LSP" 'Lisp文件的路径<br/>&nbsp;&nbsp;&nbsp; Dim tempS As String, tempR As Double<br/>&nbsp;&nbsp;&nbsp; tempS = ThisDrawing.GetVariable("users5")<br/>&nbsp;&nbsp;&nbsp; tempR = ThisDrawing.GetVariable("userr5")<br/>&nbsp;&nbsp;&nbsp; Dim obj As AcadEntity, pt As Variant<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.GetEntity obj, pt, "选择对象:"<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.SetVariable "users5", obj.Handle&nbsp; '将对象的句柄放在系统变量里<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.SendCommand "(load " &amp; Chr(34) &amp; Replace(LispPath, "\", "/") &amp; Chr(34) &amp; ")" &amp; vbCr<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; MsgBox "曲线长度为:" &amp; CStr(ThisDrawing.GetVariable("userr5")) '到userr5里取值<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ThisDrawing.SetVariable "users5", tempS '还原系统变量<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.SetVariable "userR5", tempR '还原系统变量<br/>End Sub</font></p>
<p>&nbsp;</p>
<p>第二步:复制下面代码存为*.lsp文件,注意文件名、路径要与上面的lisppath变量相一致</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face="Verdana">(defun GetLen( / obj len)<br/>&nbsp; ;;功能:计算曲线长度<br/>&nbsp; (vl-load-com)<br/>&nbsp; (setq obj (vlax-ename-&gt;vla-object (handent (getvar "users5"))));;把对对象的句柄放在users5<br/>&nbsp; (setq len (vlax-curve-getDistAtParam obj (vlax-curve-getendParam obj)))<br/>&nbsp; (setvar "userr5" len);;把对对象的长度放在userr5<br/>&nbsp; )<br/>(GetLen)</font></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>然后运行 GetCurveLen宏</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>这是一个VBA的例子,VB操作与此类似</p>

chpmould 发表于 2010-6-9 22:45:00

对VBA不熟,看不明白,不过还是谢谢你的热心帮助。。。

就爱CAD 发表于 2010-6-10 08:36:00

楼主有点搞笑,VB不熟,VBA也不熟,那还谈什么VB调用lisp啊??

chpmould 发表于 2010-6-10 18:38:00

<p>&nbsp;</p>
<p>以前一直用VB编写其它东东。。。并不是完全不会VB。。。</p>
<p>&nbsp;</p>
<p>我以前没有用过VB编写CAD,但会一点LISP,所以有了此想法。。。</p>
页: [1]
查看完整版本: VB调用LISP程序