.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

3 REPLIES 3
Reply
Message 1 of 4
hoathuongphuoc
375 Views, 3 Replies

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

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.

3 REPLIES 3
Message 2 of 4

is this difficult matter? 

Message 3 of 4
mzakiralam
in reply to: hoathuongphuoc

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

 

Message 4 of 4
hoathuongphuoc
in reply to: mzakiralam

Thanks very much

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost