求直线长度
环境:AutoCAD2006+VS2008要求:求0图层所有直线长度
代码如下:
<CommandMethod("testFilSel")> Public Sub testSelection2()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'定义过滤条件
'实体类型
Dim value1 As TypedValue = New TypedValue(DxfCode.Start, "LINE")
'图层
Dim value2 As TypedValue = New TypedValue(DxfCode.LayerName, "0")
'Dim value3 As TypedValue = New TypedValue(DxfCode.Color, "1")
Dim values() As TypedValue = {value1, value2}
Dim sfilter As New SelectionFilter(values)
' 返回选择集的用户提示类.
Dim resSel As PromptSelectionResult = ed.SelectAll(sfilter)
' 得到选择集对象.
Dim sSet As SelectionSet = resSel.Value
' 得到选择集中所有对象的ObjectId集合.
Dim ids As ObjectId() = sSet.GetObjectIds()
Using trans As Transaction = db.TransactionManager.StartTransaction()
' 遍历选择集.
For Each sSetEntId As ObjectId In ids
Dim ent As Entity = trans.GetObject(sSetEntId, OpenMode.ForWrite)
' 这里怎么写
'Dim l As Double
Next
trans.Commit()
End Using
End Sub
求曲线长度的通用代码:
ent.GetDistanceAtParameter(ent.EndParam) Dim sum As Double
For Each sSetEntId As ObjectId In ids
Dim ent As Line = trans.GetObject(sSetEntId, OpenMode.ForWrite)
sum += ent.Length
Next trans.GetObject(sSetEntId, OpenMode.ForRead)即可……
随手复制了,呵呵
另外,如果没有对数据库有更改,只是查询的话
trans.Commit()也可以去掉 本帖最后由 hnzgs 于 2011-1-14 14:07 编辑
感谢楼上两位。
是不是版本不一样,我用的CAD2006+vs2008,
调试提示:
“Length”不是“Autodesk.AutoCAD.DatabaseServices.Line”的成员
这样实现不知道是否有误差
Dim vec As Vector3d = ent.GeomExtents.MaxPoint - ent.GeomExtents.MinPoint
Length = Length + vec.Length
多谢飞狐版主~~~ 参考着学习了~~呵呵~ 新手上路,看到楼上那些交流觉得C#好难学啊
页:
[1]