导入vlax.cls类后,在thisdrawing模块中输入以下代码,运行则可:
- Sub GetLength()
- Dim obj As AcadEntity
- Dim pnt As Variant
- ThisDrawing.Utility.GetEntity obj, pnt, "选取曲线:"
- Dim leng As Double
- leng = GetCurveLength(obj)
- MsgBox "所选曲线的长度为 " & leng, , "明经通道VBA示例"
- End Sub
- Public Function GetCurveLength(curve As AcadEntity) As Double
- Dim obj As VLAX, retVal
-
- Set obj = New VLAX
- obj.EvalLispExpression "(setq curve (handent " & Chr(34) & curve.Handle & Chr(34) & "))"
- obj.EvalLispExpression "(setq curvelength (vlax-curve-getDistAtParam curve " & _
- "(vlax-curve-getEndParam curve)))"
- retVal = obj.GetLispSymbol("curvelength")
- obj.NullifySymbol "curve", "curvelength"
- Set obj = Nothing
- GetCurveLength = CDbl(retVal)
- End Function
|