private const int VK_SPACE = 32;
private const int VK_ESCAPE = 27;
const int WM_CHAR = 258;
/// </summary>
private const int MK_SHIFT = 4;
/// <summary>
/// The w m_ rbuttonup
/// </summary>
private const int WM_RBUTTONUP = 517;
/// <summary>
/// The w m_ lbuttonup
/// </summary>
private const int WM_LBUTTONUP = 514;
/// <summary>
/// The w m_ lbuttondown
/// </summary>
private const int WM_LBUTTONDOWN = 513;
/// <summary>
/// The w m_ rbuttondown
/// </summary>
private const int WM_RBUTTONDOWN = 516;
/// <summary>
/// Handles the PreTranslateMessage event of the Application control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PreTranslateMessageEventArgs"/> instance containing the event data.</param>
private void Application_PreTranslateMessage(object sender, PreTranslateMessageEventArgs e)
{
var wp = e.Message.wParam.ToInt64();
if (e.Message.message == WM_CHAR && wp == VK_SPACE)
{
System.Windows.Interop.MSG msg = e.Message;
negate = true;
msg
.wParam = new IntPtr
(VK_ESCAPE
); e.Message = msg;;
}
if (e.Message.message == WM_RBUTTONDOWN && (wp != 6 && wp != MK_SHIFT))
{
e.Handled = true;
}
if (e.Message.message == WM_RBUTTONUP && wp != MK_SHIFT)
{
Application.PreTranslateMessage -= Application_PreTranslateMessage;
e.Handled = true;
endCommand = true;
Application.DocumentManager.MdiActiveDocument.SendCancel();
}
}
int angle = 60;
bool negate = false;
private bool endCommand = false;
[CommandMethod("parc")]
public async void parc()
{
negate = false;
endCommand = false;
PromptPointOptions ppo
= new PromptPointOptions
("\nSelect Point"); ppo.Keywords.Add("Angle");
PromptPointResult ppr = Ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.Keyword)
{
PromptIntegerOptions pio
= new PromptIntegerOptions
("\nEnter Angle"); pio.AllowNegative = true;
pio.DefaultValue = angle;
PromptIntegerResult pir = Ed.GetInteger(pio);
if (pir.Status != PromptStatus.OK) return;
angle = pir.Value;
ppo.Keywords.Clear();
ppr = Ed.GetPoint(ppo);
}
if (ppr.Status != PromptStatus.OK) return;
try
{
Application.PreTranslateMessage += Application_PreTranslateMessage;
await Ed.CommandAsync("_.PLINE", ppr.Value, "A");
while (Settings.Variables.CMDNAMES.ToUpper().IndexOf("PLINE", System.StringComparison.Ordinal) >= 0)
{
try
{
if (negate)
{
negate = false;
angle = angle * -1;
}
await Ed.CommandAsync("A", angle, Editor.PauseToken);
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
if (ex.ErrorStatus != ErrorStatus.UserBreak)
{
throw;
}
if (endCommand)
{
throw;
}
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
if (ex.ErrorStatus != ErrorStatus.UserBreak)
{
throw;
}
}
finally
{
Application.PreTranslateMessage -= Application_PreTranslateMessage;
}
}