有没有比以下代码更简洁一点的方法,或者以下代码如何再简练一点?
- ''' <summary>
- ''' 获取单行文字或多行文字的外包矩形角点坐标
- ''' 0为左下角点,1为右下角点,2为右上角点,3为左上角点
- ''' </summary>
- ''' <param name="id">单行文字或多行文字的ID</param>
- ''' <returns></returns>
- ''' <remarks></remarks>
- Public Shared Function GetTextBounds(ByVal id As ObjectId) As Point3dCollection
- Dim tmpPoint As New Point3dCollection
- Using trans As Transaction = db.TransactionManager.StartTransaction
- Dim ent As Entity = trans.GetObject(id, OpenMode.ForWrite)
- Dim Angle As Double
- If TypeOf ent Is DBText Then
- Dim tmpText As DBText = ent
- Angle = tmpText.Rotation
- tmpText.Rotation = 0
- With tmpPoint
- .Add(tmpText.GeometricExtents.MinPoint)
- .Add(New Point3d(tmpText.GeometricExtents.MaxPoint.X, tmpText.GeometricExtents.MinPoint.Y, tmpText.GeometricExtents.MinPoint.Z))
- .Add(tmpText.GeometricExtents.MaxPoint)
- .Add(New Point3d(tmpText.GeometricExtents.MinPoint.X, tmpText.GeometricExtents.MaxPoint.Y, tmpText.GeometricExtents.MinPoint.Z))
- End With
- tmpText.Rotation = Angle
- For i As Integer = 0 To tmpPoint.Count - 1
- tmpPoint.Item(i) = tmpPoint.Item(i).RotateBy(Angle, Vector3d.ZAxis, tmpText.Position)
- Next
- ElseIf TypeOf ent Is MText Then
- Dim tmpText As MText = ent
- Angle = tmpText.Rotation
- tmpText.Rotation = 0
- With tmpPoint
- .Add(tmpText.GeometricExtents.MinPoint)
- .Add(New Point3d(tmpText.GeometricExtents.MaxPoint.X, tmpText.GeometricExtents.MinPoint.Y, tmpText.GeometricExtents.MinPoint.Z))
- .Add(tmpText.GeometricExtents.MaxPoint)
- .Add(New Point3d(tmpText.GeometricExtents.MinPoint.X, tmpText.GeometricExtents.MaxPoint.Y, tmpText.GeometricExtents.MinPoint.Z))
- End With
- tmpText.Rotation = Angle
- For i As Integer = 0 To tmpPoint.Count - 1
- tmpPoint.Item(i) = tmpPoint.Item(i).RotateBy(Angle, Vector3d.ZAxis, tmpText.Location)
- Next
- End If
- trans.Commit()
- End Using
- Return tmpPoint
- End Function
|