.NET

Reply
Valued Contributor
hoathuongphuoc
Posts: 59
Registered: ‎11-05-2013
Message 1 of 4 (152 Views)

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

152 Views, 3 Replies
11-05-2013 02:14 AM

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.

Valued Contributor
hoathuongphuoc
Posts: 59
Registered: ‎11-05-2013
Message 2 of 4 (130 Views)

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

11-05-2013 05:45 PM in reply to: hoathuongphuoc

is this difficult matter? 

Mentor
mzakiralam
Posts: 225
Registered: ‎11-09-2012
Message 3 of 4 (114 Views)

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

11-06-2013 06:25 AM 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

 

Valued Contributor
hoathuongphuoc
Posts: 59
Registered: ‎11-05-2013
Message 4 of 4 (102 Views)

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

11-06-2013 06:47 PM in reply to: mzakiralam

Thanks very much

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community