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
Solved! Go to Solution.
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.
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.
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.MainWin
dow.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