明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2518|回复: 5

问了几次了,多段线的长度怎么获得

[复制链接]
发表于 2003-6-12 21:55:00 | 显示全部楼层 |阅读模式
劳烦版主回答了几次,
但我运行时却报错呀

贴出我的源程序

  1. Sub Count_len()
  2.     ' 创建新的选择集
  3.     Dim sset As AcadSelectionSet

  4. For i = 0 To ThisDrawing.SelectionSets.Count - 1
  5. ThisDrawing.SelectionSets.Item(i).Clear
  6. ThisDrawing.SelectionSets.Item(i).Delete
  7. Next
  8. On Error Resume Next
  9.     Set sset = ThisDrawing.SelectionSets.Add("SS0")
  10.    sset.SelectOnScreen
  11.      Dim entry As AcadEntity
  12.     Dim l_text As String
  13.     Dim l_l As Double
  14.     Dim Arc_count As Integer
  15.     Dim Line_count As Integer
  16.     For Each entry In sset
  17.         '如果是多段线或曲线的长度,就不行了
  18.         If entry.ObjectName = "AcDbArc" Then
  19.         l_text = l_text & "+" & entry.ArcLength
  20.         l_l = l_l + entry.ArcLength
  21.         Arc_count = Arc_count + 1
  22.         ElseIf entry.ObjectName = "AcDbLine" Then
  23.         l_text = l_text & "+" & entry.Length
  24.         l_l = l_l + entry.Length
  25.         Line_count = Line_count + 1
  26.         End If
  27.     Next entry

  28. ThisDrawing.Utility.Prompt vbCrLf & Arc_count & "个弧," & Line_count & "条直线. 共" & Arc_count + Line_count & "个对象." & vbCrLf & l_text & "=" & l_l & vbCrLf
  29. End Sub
发表于 2003-6-12 20:31:00 | 显示全部楼层

必须结合VLAX类开处理,实用函数栏目中有相关的函数

 楼主| 发表于 2003-6-12 21:58:00 | 显示全部楼层

劳烦版主把我上面的程序改改

谢谢
发表于 2003-7-10 01:00:00 | 显示全部楼层
用2004吧,里面可以直接调用pline的length属性。
发表于 2003-7-10 06:57:00 | 显示全部楼层
导入vlax.cls类后,在thisdrawing模块中输入以下代码,运行则可:
  1. Sub GetLength()
  2.     Dim obj As AcadEntity
  3.     Dim pnt As Variant
  4.     ThisDrawing.Utility.GetEntity obj, pnt, "选取曲线:"
  5.     Dim leng As Double
  6.     leng = GetCurveLength(obj)
  7.     MsgBox "所选曲线的长度为 " & leng, , "明经通道VBA示例"
  8. End Sub

  9. Public Function GetCurveLength(curve As AcadEntity) As Double

  10.     Dim obj As VLAX, retVal
  11.    
  12.     Set obj = New VLAX
  13.     obj.EvalLispExpression "(setq curve (handent " & Chr(34) & curve.Handle & Chr(34) & "))"
  14.     obj.EvalLispExpression "(setq curvelength (vlax-curve-getDistAtParam curve " & _
  15.                            "(vlax-curve-getEndParam curve)))"
  16.     retVal = obj.GetLispSymbol("curvelength")
  17.     obj.NullifySymbol "curve", "curvelength"
  18.     Set obj = Nothing
  19.     GetCurveLength = CDbl(retVal)

  20. End Function
发表于 2003-9-22 22:27:00 | 显示全部楼层
可一先分解再获得嘛
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 12:31 , Processed in 0.171987 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表