Try this one instead
Public Sub TextPoint()
Dim doc As Document = acadApp.DocumentManager.MdiActiveDocument
'' Get the current document editor
Dim ed As Editor = doc.Editor
'' Get the current database
Using db As Database = HostApplicationServices.WorkingDatabase
'' Get the current transaction
Dim tr As Transaction = db.TransactionManager.StartTransaction
'' using transaction
Using (tr)
Try
'' Create a TypedValue array to define the filter criteria
Dim typefilter As TypedValue() = New TypedValue() {New TypedValue(DxfCode.Start, "TEXT")}
'' Assign the filter criteria to a SelectionFilter object
Dim filter As SelectionFilter = New SelectionFilter(typefilter)
Dim pso As PromptSelectionOptions = New PromptSelectionOptions()
pso.AllowDuplicates = False
pso.RejectObjectsFromNonCurrentSpace = True
'' Request for objects to be selected in the drawing area
Dim res As PromptSelectionResult = ed.GetSelection(pso, filter)
Dim oSset As SelectionSet = Nothing
'' If the prompt status is OK, objects were selected
If (res.Status = PromptStatus.OK) Then
'' get selection set
oSset = res.Value
'' show result
ed.WriteMessage(vbLf & "Number of objects selected: {0}", oSset.Count.ToString())
Else
ed.WriteMessage(vbLf & "Number of objects selected: 0")
'' exit if nothing selected
Return
End If
Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
'' iterate through selected texts
For Each obj As SelectedObject In oSset
Dim id As ObjectId = obj.ObjectId
''Cast obj as entity
Dim ent As Entity = TryCast(tr.GetObject(id, OpenMode.ForRead), Entity)
If (Not ent Is Nothing) Then
'' Cast entity as dbtext
Dim txt As DBText = TryCast(tr.GetObject(id, OpenMode.ForRead), DBText)
' Create Point object if text is numeric
If IsNumeric(txt.TextString) Then
Dim pt As Point3d = New Point3d(txt.Position.X, txt.Position.Y, CDbl(txt.TextString))
' Place Point object in current space
Dim ptobj As DBPoint = New DBPoint(pt)
btr.AppendEntity(ptobj)
' Add to transaction
tr.AddNewlyCreatedDBObject(ptobj, True)
End If
End If
Next
' Commit transaction
tr.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
ed.WriteMessage("Error: {0}" & vbLf & "Stack trace: {1}", ex.Message, ex.StackTrace)
End Try
End Using ''dispose transaction
End Using ''dispose database
End Sub
¬'J'¬