原文见:http://forums.autodesk.com/t5/NET/Dynamic-Input/td-p/1339772
目前AutoCAD未公开实现Dynamic Input的API,要实现和AutoCAD同样的效果,可以使用一个未公开的函数acedSetDynInputDisplayMessage
以下是C#代码:
using System;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using System.Threading;
using System.Globalization;
using System.Runtime.InteropServices;
#endregion
namespace RSNNAcadApp.Test
{
public class Test
{
//this is an undocumented api exported from acad.exe. Use it at your
own risk.
//
// Setting this flag tells AutoCAD to display the last string output
to the command line
//in the Dynamic Input prompt window (one time only.)
[DllImport("acad.exe",
EntryPoint="?acedSetDynInputDisplayMessage@@YA_N_N@Z")]
private static extern bool acedSetDynInputDisplayMessage(bool
displayMessageOnce);
private double m_dist; //last distance chosen (per-document)
private bool m_firstTime = true; //first invocation of "test"?
(per-document)
//use a non-static command method so the enclosing class (Test) will
be instantiated
//for each document
[CommandMethod("test")]
public void DoIt()
{
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
PromptDistanceOptions opt1 = new PromptDistanceOptions("Abstand
zeigen");
opt1.AllowNegative = false;
opt1.AllowZero = false;
opt1.AllowNone = false;
opt1.UseDashedLine = true;
if (!m_firstTime)
opt1.DefaultValue = m_dist;
PromptDoubleResult res = ed.GetDistance(opt1);
if (res.Status == PromptStatus.OK)
{
m_dist = res.Value;
ed.WriteMessage(String.Format("Abstand = {0}",
m_dist.ToString()));
acedSetDynInputDisplayMessage(true);
}
m_firstTime = false;
}
void MyPointFilter(object sender, PointFilterEventArgs e)
{
e.Result.ToolTipText = String.Format("Abstand = {0}",
m_dist.ToString());
}
}
}