- 积分
- 73549
- 明经币
- 个
- 注册时间
- 2001-6-7
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2004-10-30 20:59:00
|
显示全部楼层
- Sub GetSelectCurveLength()
- Dim SS As AcadSelectionSet
- Set SS = CreateSelectionSet
- Dim varType As Variant
- Dim varData As Variant
- BuildFilter varType, varData, 0, _
- "ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,POLYLINE,SPLINE"
- SS.SelectOnScreen varType, varData
- Dim objEntity As AcadEntity
- Dim dblLength As Double
- For Each objEntity In SS
- dblLength = dblLength + GetCurveLength(objEntity)
- Next
- MsgBox "所选曲线的总长度为 " & dblLength, , "明经通道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
- Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes())
- Dim fType() As Integer, fData()
- Dim index As Long, i As Long
-
- index = LBound(gCodes) - 1
-
- For i = LBound(gCodes) To UBound(gCodes) Step 2
- index = index + 1
- ReDim Preserve fType(0 To index)
- ReDim Preserve fData(0 To index)
- fType(index) = CInt(gCodes(i))
- fData(index) = gCodes(i + 1)
- Next
- typeArray = fType: dataArray = fData
- End Sub
- Function CreateSelectionSet(Optional SSetName As String = "mjtd") As AcadSelectionSet
- On Error Resume Next
- ThisDrawing.SelectionSets(SSetName).Delete
- Set CreateSelectionSet = ThisDrawing.SelectionSets.Add(SSetName)
- End Function
|
|