Here is quickly made an example if you need it
'__________________ RunApp.vb______________________'
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports System.Windows.Forms
<Assembly: CommandClass(GetType(FormVB.RunApp))>
Namespace FormVB
Public Class RunApp
<CommandMethod("RunMe", CommandFlags.Modal)> _
Public Shared Sub InitForm()
Dim frm As New Form1
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage("InitForm command started")
Dim result As DialogResult = Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frm)
End Sub
End Class
End Namespace
'__________________Form1.vb______________________'
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.IO
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports System.Windows.Forms
Public Class Form1
Private leg As Double = New Double
Private Sub btnAcad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAcad.Click
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim usered As EditorUserInteraction = ed.StartUserInteraction(Me)
Using (usered)
Dim tr As Transaction = db.TransactionManager.StartTransaction
Try
If (Me.Modal) Then
Dim docloc As DocumentLock = doc.LockDocument
Using (docloc)
Me.Hide()
Using (tr)
' Do your other things here e.g. pick point
Dim opt As PromptPointOptions = New PromptPointOptions(vbCr & "Pick point :")
Dim res As PromptPointResult = ed.GetPoint(opt)
If (res.Status <> PromptStatus.OK) Then
ed.WriteMessage(vbCr & "User input error. Exit")
ElseIf (res.Status = PromptStatus.Cancel) Then
ed.WriteMessage(vbCr & "Interrupted by user input. Exit")
Return
End If
Dim pt As Point3d = res.Value
Dim txt As DBText = New DBText
txt.SetDatabaseDefaults()
txt.Position = pt
txt.TextString = Me.txtCommand.Text
txt.HorizontalMode = TextHorizontalMode.TextCenter
txt.VerticalMode = TextVerticalMode.TextVerticalMid
txt.AlignmentPoint = pt
Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
btr.AppendEntity(txt)
tr.AddNewlyCreatedDBObject(txt, True)
ed.Regen()
tr.Commit()
End Using
End Using
End If
Catch ex As System.Exception
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message)
Finally
usered.End()
' Display the form again if you need:
'If Me.Visible = False Then Me.Show()
''otherwise close form
Me.Close()
End Try
End Using
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.txtCommand.Text = "Type the text here"
Me.txtCommand.Focus()
End Sub
Private Sub btnSelect_Click(sender As System.Object, e As System.EventArgs) Handles btnSelect.Click
Me.txtLength.Text = ""
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim usered As EditorUserInteraction = ed.StartUserInteraction(Me)
Using (usered)
Dim tr As Transaction = db.TransactionManager.StartTransaction
Try
If (Me.Modal) Then
Me.Hide()
Using (tr)
Dim peo As New PromptEntityOptions(vbLf & "Select a polyline: ")
peo.SetRejectMessage(vbLf & "Not a polyline...")
peo.AddAllowedClass(GetType(Polyline), True)
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then Return
Dim ent As Entity = TryCast(tr.GetObject(per.ObjectId, OpenMode.ForRead), Entity)
If ent Is Nothing Then Return
Dim pline As Polyline = TryCast(ent, Polyline)
Me.leg = pline.Length
Me.txtLength.Text = String.Format("{0:f3}", Me.leg)
End Using
End If
Catch ex As System.Exception
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message)
Finally
usered.End()
' Display the form again if you need:
If Me.Visible = False Then Me.Show()
''otherwise close form
'Me.Close()
End Try
End Using
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class