Thank you very much for your help, it's truly crucial to me.
I tested your code and found that it works if the runtime environment is CAD 2020+ VS 2017, yielding results consistent with those in the video you provided,it's great.
Unfortunately, in the case of CAD 2014+VS 2010, the code doesn't work as expected. The window reappears instantly after being hidden and doesn't wait.
The only notable difference between the two environments is that in the 2014 environment, the Editor class does not have a Commad() method.
So, i can only use the EditorInputExtension extension method.
I suspect that there might be some distinction between EditorInputExtension.Commad() and Editor.Commad(), but my knowledge in this area is limited, and I'm unable to resolve this issue. Do you have any suggestions?
I need to use CAD 2014, and in fact, I need to develop plugins for CAD 2014, 2016, and 2020 simultaneously.
Or maybe there's a difference in the StartUserInteraction method in different versions?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
namespace MyTest
{
static class EditorInputExtension
{
public static PromptStatus Command(this Editor editor, params object[] args)
{
if (editor == null)
throw new ArgumentNullException("Editor Extension");
return runCommand(editor, args);
}
static Func<Editor, object[], PromptStatus> runCommand = GenerateRunCommand();
static Func<Editor, object[], PromptStatus> GenerateRunCommand()
{
MethodInfo method =
typeof(Editor).GetMethod("RunCommand", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
var instance = Expression.Parameter(typeof(Editor), "instance");
var args = Expression.Parameter(typeof(object[]), "args");
return Expression.Lambda<Func<Editor, object[], PromptStatus>>(Expression.Call(instance, method, args), instance, args).Compile();
}
}
}