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