Question re: Send Command Executes after exiting command method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
I'm working on the Civil3D add-in, and I want to send a command to select elements and then run the next line of codes using the selected objects.
In this previous thread, I got an answer on how to save the selected objects into a variable. https://forums.autodesk.com/t5/net/how-to-receive-selected-object-data-from-autocad-with-mouse/m-p/1...
But I'm having a hard time running the next line of code because the SendStringToCommand is asycnrhonous.
Then I ran into this thread, which was recommended in several other threads.
https://forums.autodesk.com/t5/net/send-command-executes-after-exiting-command-method/td-p/3882929
But when I use the wrapper, I get 'null' value for the MethodInfo method and that throws an error (message: {"Value cannot be null.\r\nParameter name: method"}.
Does anyone know why this is giving me null value? Is it because I'm using C3D? Or versioning issue?
Or is there any other way to run the GETOBJECT command and run next line of code in this example?
namespace exampleTool
{
public static class EditorInputExtensionMethods
{
public static PromptStatus Command_(this Editor editor, params object[] args)
{
if (editor == null)
throw new ArgumentNullException("editor");
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 = System.Linq.Expressions.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();
}
}
public partial class NewMainWindow : System.Windows.Window
{
private void Get_Object(object sender, RoutedEventArgs e)
{
_document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor editor = _document.Editor;
editor.Command_("._GETOBJECT");
// next code runs..
}
ObjectId[] _currentSelection;
[CommandMethod("GETOBJECT")]
public void GetObject()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
DocumentLock dl = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
var ed = doc.Editor;
// Request for objects to be selected in the drawing area
PromptSelectionOptions pso = new PromptSelectionOptions();
pso.MessageForAdding = "Select Pipes";
PromptSelectionResult acSSPrompt = ed.GetSelection(pso);
_currentSelection = null;
if (acSSPrompt.Status != PromptStatus.OK)
return;
_currentSelection = acSSPrompt.Value.GetObjectIds();
}
}
}
Thanks!