.NET

Reply
Contributor
matrax1405
Posts: 24
Registered: ‎04-09-2014
Message 1 of 4 (213 Views)
Accepted Solution

Visual studio and visual basic get properties

213 Views, 3 Replies
04-09-2014 10:16 AM

Hi could help me with this exercise please, but I want to do a Windows Form in visual studio then connect AutoCAD using VISUAL BASIC and when clicking to give the line attributes display in a tectbox or label.you could help me please

*Expert Elite*
dgorsman
Posts: 5,210
Registered: ‎10-12-2006
Message 2 of 4 (190 Views)

Re: Visual studio and visual basic get properties

04-09-2014 12:14 PM in reply to: matrax1405

Usually its best to start at the start: define the problem.

 

- what types of objects are being worked with?  Lines and circles?  Text?  Vertical content?  Third-party objects? 

- what information is available?  Can it be read from an object, or does it have to come from the user, or from a data source?

- what do you want to do with them?  What would it look like?

- what type of user input is required?

 

Once the problem is defined, then you can start getting into detail about the "how".

- what do you know? 

- What do you NOT know, and need to figure out?

 

Once you've got an idea of what you do (and more imporantly DON'T) know, you can peel back the layers of work.  Build in logical steps so each can be tested before going on to the next.  Sometimes you end up hitting a wall you can't get around, and have to back up and redo work.  Sometimes you have to do more research to see if what you are trying to do is appropriate, effective, and/or reasonable.

 

Finally, you end up at the end: with working code.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Contributor
matrax1405
Posts: 24
Registered: ‎04-09-2014
Message 3 of 4 (175 Views)

Re: Visual studio and visual basic get properties

04-09-2014 02:14 PM in reply to: dgorsman

Hi first of all thank you very much for answering looks attached a video that I found just what I do not found the solution I hope I can help.
The video shows how to get the length of a line and a polyline by selecting it, and apart to get the value but touching 2 point line in the plane.

I have to do this in visual basic creating a form with visual studio 2012 and AutoCAD 2014

really really appreciate it if you can help me. :mansad:

Mentor
mzakiralam
Posts: 231
Registered: ‎11-09-2012
Message 4 of 4 (122 Views)

Re: Visual studio and visual basic get properties

04-15-2014 05:09 AM in reply to: matrax1405

Hi ,

Please try below code for your problem. To invoke the winform, code is below:

 

 <CommandMethod("tst")> Public Sub TestForm()
        Dim frm As TESTFORM = New TESTFORM()
        Application.ShowModelessDialog(Application.MainWindow.Handle, frm, False)
    End Sub

 

to get properties and place text code is below:

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Public Class TESTFORM

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        'to get properties
        Me.Hide()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim peo As PromptEntityOptions = New PromptEntityOptions(vbLf & "Select line or polyline: ")
        Dim per As PromptEntityResult = ed.GetEntity(peo)
        If per.Status <> PromptStatus.OK Then
            Return
        End If
        Using docLock As DocumentLock = doc.LockDocument
            Using tx As Transaction = db.TransactionManager.StartTransaction()
                Dim ent As Entity = tx.GetObject(per.ObjectId, OpenMode.ForRead)
                If TypeOf ent Is Line Then
                    Dim ln As Line = TryCast(ent, Line)
                    TextBox1.Text = TextBox1.Text & "Line Length: " & ln.Length & vbNewLine
                ElseIf TypeOf ent Is Polyline Then
                    Dim pl As Polyline = TryCast(ent, Polyline)
                    TextBox1.Text = TextBox1.Text & "Polyline Length: " & pl.Length & vbNewLine
                End If
                tx.Commit()
            End Using
        End Using
        Me.Show()
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        'to place text
        Me.Hide()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim ppo As PromptPointOptions = New PromptPointOptions(vbLf & "Select a point to place text: ")
        Dim ppr As PromptPointResult = ed.GetPoint(ppo)
        Using docLock As DocumentLock = doc.LockDocument
            Using tx As Transaction = db.TransactionManager.StartTransaction()
                Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead)
                Dim btr As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                Dim mtxt As MText = New MText()
                mtxt.Location = ppr.Value
                mtxt.Attachment = AttachmentPoint.MiddleCenter
                mtxt.TextHeight = 1.5
                mtxt.Contents = TextBox1.Text
                mtxt.ColorIndex = 256
                btr.AppendEntity(mtxt)
                tx.AddNewlyCreatedDBObject(mtxt, True)
                tx.Commit()
            End Using
        End Using
        Me.Show()
    End Sub
End Class

 

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 or visit the Installation and Licensing Forum to get help installing your software.