Hi ,
With below code you can start to select a rectange and afterwards get length and width of that. Here I have create a message box to show length and width of a rectangle. I hope you can start with this code and later customize your requirement.
<CommandMethod("TST")> Public Sub RectangleSize()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim _length As Double = Nothing
Dim _area As Double = Nothing
Dim _width As Double = Nothing
Dim peo As PromptEntityOptions = New PromptEntityOptions(vbLf & "Please select a rectangle:")
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then
Return
End If
Using tx As Transaction = db.TransactionManager.StartTransaction()
Dim ent As Entity = tx.GetObject(per.ObjectId, OpenMode.ForRead)
If TypeOf ent Is Polyline Then
Dim pl As Polyline = TryCast(ent, Polyline)
If pl.Closed Then
Dim pt1 As Point2d = pl.GetPoint2dAt(0)
Dim pt2 As Point2d = pl.GetPoint2dAt(1)
Dim pt3 As Point2d = pl.GetPoint2dAt(2)
Dim distance1 As Double = pt1.GetDistanceTo(pt2)
distance1 = Math.Abs(distance1)
Dim distance2 As Double = pt2.GetDistanceTo(pt3)
distance2 = Math.Abs(distance2)
If distance1 > distance2 Then
_length = distance1
Else
_length = distance2
End If
_area = pl.Area
_width = _area / _length
MsgBox(_length & vbTab & _width)
End If
End If
tx.Commit()
End Using
End Sub