I am having trouble with the EditorinputExtensionMethods. I'm not sure what I'm doing wrong, but when I call the editor.Command(parameters), absolutely nothing happens. I have access to the editor, because the editor.WriteMessage command works. I am calling the editor.Command from a button click on a windows form in a module loaded into AutoCAD with NETLOAD. Any insight would be greatly appreciated! Code is inserted below.
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Reflection
Imports System.Linq.Expressions
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Data.SqlServerCe
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension
Module EditorInputExtensionMethods
<System.Runtime.CompilerServices.Extension> _
Public Function Command(editor As Editor, ParamArray args As Object()) As PromptStatus
If editor Is Nothing Then
Throw New ArgumentNullException("editor")
End If
Return runCommand(editor, args)
End Function
Dim runCommand As Func(Of Editor, Object(), PromptStatus) = GenerateRunCommand()
Private Function GenerateRunCommand() As Func(Of Editor, Object(), PromptStatus)
Dim method As MethodInfo = GetType(Editor).GetMethod( _
"RunCommand", BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public)
Dim instance As ParameterExpression = Expression.Parameter(GetType(Editor), "editor")
'Dim instance As ParameterExpression = Expression.Parameter(GetType(Editor), "instance")
Dim args As ParameterExpression = Expression.Parameter(GetType(Object()), "args")
Return Expression.Lambda(Of Func(Of Editor, Object(), PromptStatus)) _
(Expression.Call(instance, method, args), instance, args).Compile()
End Function
End Module
Public Class frmMhsApp
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim doc As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
ed.Command("._line", New Point3d(0, 0, 0), New Point3d(5, 5, 0))
ed.WriteMessage("Message Test")
End Sub