from link
An overload Editor.GetWindow() extension method.
public static PromptWindowResult GetWindow(this Editor ed, string message, string secondMessage)
public static PromptWindowResult GetWindow(this Editor ed, string messageAndKeywords, string globalKeywords, string secondMessage)
public static PromptWindowResult GetWindow(this Editor ed, PromptWindowOptions options)
The PromptWindowOptions type provides the same features as PromptPointOptions more a SecondMessage read/write property.
The PromptWindowResult type offers the same properties as PromptResult (Stauts and StringResult) plus Value of type Extents3d (current UCS coordinates).
using System;
using Autodesk.AutoCAD.DatabaseServices;
namespace Autodesk.AutoCAD.EditorInput
{
public static class EditorExtensions
{
public static PromptWindowResult GetWindow(this Editor ed, string message, string secondMessage)
{
PromptWindowOptions options = new PromptWindowOptions(message, secondMessage);
return ed.GetWindow(options);
}
public static PromptWindowResult GetWindow(this Editor ed, string messageAndKeywords, string globalKeywords, string secondMessage)
{
PromptWindowOptions options = new PromptWindowOptions(messageAndKeywords, globalKeywords, secondMessage);
return ed.GetWindow(options);
}
public static PromptWindowResult GetWindow(this Editor ed, PromptWindowOptions options)
{
if (ed == null)
throw new ArgumentNullException("ed");
if (options == null)
throw new ArgumentNullException("options");
Extents3d value = new Extents3d();
PromptPointResult result = ed.GetPoint(options);
if (result.Status == PromptStatus.Keyword)
return new PromptWindowResult(result.Status, result.StringResult);
if (result.Status != PromptStatus.OK)
return new PromptWindowResult(result.Status);
value.AddPoint(result.Value);
result = ed.GetCorner(options.SecondMessage, result.Value);
if (result.Status != PromptStatus.OK)
return new PromptWindowResult(result.Status);
value.AddPoint(result.Value);
return new PromptWindowResult(result.Status, value);
}
}
public class PromptWindowOptions : PromptPointOptions
{
public string SecondMessage { get; set; }
public PromptWindowOptions(string message, string secondMessage)
: base(message)
{
this.SecondMessage = secondMessage;
}
public PromptWindowOptions(string messageAndKeywords, string globalKeywords, string secondMessage)
: base(messageAndKeywords, globalKeywords)
{
this.SecondMessage = secondMessage;
}
}
public class PromptWindowResult
{
public string StringResult { get; private set; }
public PromptStatus Status { get; private set; }
public Extents3d Value { get; private set; }
internal PromptWindowResult(PromptStatus status, Extents3d value)
{
this.Status = status;
this.Value = value;
}
internal PromptWindowResult(PromptStatus status, string keyword)
: this(status)
{
this.StringResult = keyword;
}
internal PromptWindowResult(PromptStatus status)
: this(status, new Extents3d()) { }
}
}
A test command example:
[CommandMethod("Test")]
public void Test()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptWindowOptions options =
new PromptWindowOptions(
"\nSpecify first corner [Extents/Previous]: ",
"Extents Previous",
"\nSpecify opposite corner");
options.AllowNone = true;
dynamic acadApp = Application.AcadApplication;
while (true)
{
PromptWindowResult result = ed.GetWindow(options);
switch (result.Status)
{
case PromptStatus.Keyword:
if (result.StringResult == "Extents")
acadApp.Zoomextents();
else
acadApp.ZoomPrevious();
break;
case PromptStatus.OK:
var exts = result.Value;
exts.TransformBy(ed.CurrentUserCoordinateSystem);
acadApp.ZoomWindow(exts.MinPoint.ToArray(), exts.MaxPoint.ToArray());
break;
default:
return;
}
}
}