How to take size(width, hight) by event click in autocad

How to take size(width, hight) by event click in autocad

Anonymous
Not applicable
559 Views
3 Replies
Message 1 of 4

How to take size(width, hight) by event click in autocad

Anonymous
Not applicable

Hello Everyone,

Everyone can help me. How can i take size(width, hight) of rectangle in file autocad when i click it. And then will show this information on form in vb.net. I hope everyone can help me. Thanks very much.

0 Likes
560 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

is this difficult matter? 

0 Likes
Message 3 of 4

Anonymous
Not applicable

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

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Thanks very much

0 Likes