fix: execute automation commands in AutoCAD command context
This commit is contained in:
@@ -264,23 +264,30 @@ internal sealed class FirstLimitedApplyAutomationCoordinator
|
||||
catch (System.Exception ex) { FailFromCallback("ContextVerification", ex, "AUTOMATION_CONTEXT_FAILED"); }
|
||||
}
|
||||
|
||||
private void Queue(string command)
|
||||
{
|
||||
if (IsTerminal || document is null) return;
|
||||
transitions.Add("CommandQueued:" + command);
|
||||
document.SendStringToExecute(command + "\n", true, true, false);
|
||||
}
|
||||
private void Queue(string command) => _ = DispatchCommandAsync(command, false);
|
||||
private void QueueReadinessBarrier()
|
||||
{
|
||||
_ = DispatchCommandAsync("PHP_REC_AUTOMATION_READY", true);
|
||||
}
|
||||
private async Task DispatchCommandAsync(string command, bool readiness)
|
||||
{
|
||||
if (IsTerminal || document is null) return;
|
||||
var active = AcadApplication.DocumentManager.MdiActiveDocument;
|
||||
if (active is null || !string.Equals(active.Name, document.Name, StringComparison.OrdinalIgnoreCase))
|
||||
var expected = document;
|
||||
transitions.Add(readiness ? "ReadinessCommandDispatchRequested" : "CommandDispatchRequested:" + command);
|
||||
try
|
||||
{
|
||||
Complete(false, "AUTOMATION_READINESS_DOCUMENT_NOT_ACTIVE");
|
||||
return;
|
||||
await AcadApplication.DocumentManager.ExecuteInCommandContextAsync(async _ =>
|
||||
{
|
||||
transitions.Add("CommandContextEntered:" + command);
|
||||
var active = AcadApplication.DocumentManager.MdiActiveDocument;
|
||||
if (active is null || !string.Equals(active.Name, expected.Name, StringComparison.OrdinalIgnoreCase))
|
||||
throw new InvalidOperationException("AUTOMATION_COMMAND_DOCUMENT_NOT_ACTIVE");
|
||||
transitions.Add(readiness ? "ReadinessBarrierQueued" : "CommandQueued:" + command);
|
||||
await active.Editor.CommandAsync(command);
|
||||
transitions.Add("CommandInvocationReturned:" + command);
|
||||
}, null);
|
||||
}
|
||||
transitions.Add("ReadinessBarrierQueued");
|
||||
document.SendStringToExecute("PHP_REC_AUTOMATION_READY\n", true, false, false);
|
||||
catch (System.Exception exception) { FailFromCallback("CommandDispatcher", exception, "AUTOMATION_COMMAND_CONTEXT_FAILED"); }
|
||||
}
|
||||
private void OnCommandEnded(object sender, CommandEventArgs e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user