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