- UID
- 14
- 积分
- 8264
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-4
- 最后登录
- 1970-1-1
|
发表于 2004-1-11 15:32:41
|
显示全部楼层
最初由 ShiwJeff 发布
[B]请教,多义线的长度属性是怎么得到的,还有曲线。
我不会lisp,希望用vb运用,得到多义线的长度。 [/B]
转贴一个Pline的,支持任意曲线的要用到vlax函数,VBA论坛有过讨论,引入个cls类文件
Curve
Curve.cls is a wrapper module that grants objected-oriented access to VisualLISP's VLAX-CURVE functions. Using Curve, you can determine such things as the length of a spline, the segment of a polyline selected by the user or the coordinates of a point a given distance along the perimeter of an arc.
Use of this module also requires the use of the VLAX class module. For more information on VLAX-CURVE functions and their operation, look up the appropriate function in the VisualLISP online help.
 - [php]
- Public Function GetPLineLength(PLine As AcadObject) As Double
- Dim intCrdCnt As Integer, varCoords As Variant, dblLength As Double
- Dim dblChord As Double, dblInclAng As Double, dblAng As Double, dblRad As Double
- Dim Pt1 As Variant, Pt2 As Variant, tmp, Points, i As Long
- varCoords = PLine.Coordinates
- On Error Resume Next
- If PLine.Type <> 0 Then
- If Err.Number = 0 Then
- MsgBox "Cannot get length from this type of polyline.", vbExclamation, "GetPLineLength"
- Exit Function
- End If
- End If
- On Error GoTo 0
-
- If PLine.Closed Then
- tmp = PLine.Coordinate(0)
- For i = LBound(tmp) To UBound(tmp)
- ReDim Preserve varCoords(LBound(varCoords) To UBound(varCoords) + 1)
- varCoords(UBound(varCoords)) = tmp(i)
- Next
- End If
-
- Points = SplitPoints(varCoords, UBound(PLine.Coordinate(0)))
-
- For intCrdCnt = LBound(Points) To UBound(Points) - 1
- If PLine.ObjectName = "AcDb3dPolyline" Or PLine.GetBulge = 0 Then
- dblLength = dblLength + Distance(Points(intCrdCnt), Points(intCrdCnt + 1))
- Else
- dblChord = Distance(Points(intCrdCnt), Points(intCrdCnt + 1))
- dblInclAng = Atn(Abs(PLine.GetBulge(intCrdCnt))) * 4
- dblAng = (dblInclAng / 2) - ((Atn(1) * 4) / 2)
- dblRad = (dblChord / 2) / (Cos(dblAng))
- dblLength = dblLength + (dblInclAng * dblRad)
- End If
- Next
-
- GetPLineLength = dblLength
- End Function
-
- [/php]
Purpose
Returns the length of a polyline
Arguments
A polyline object
Example
Debug.Print GetPLineLength(objPline)
Notes
This function supports bulges
This function will not work with splined or fitted polylines
Author
R. Robert Bell |
|