用未公开的函数acedSetDynInputDisplayMessage来实现动态显示

使用未公开API实现AutoCAD DynamicInput效果
本文介绍了一种使用未公开API在AutoCAD中实现与DynamicInput相同功能的方法,通过C#代码实现距离输入提示窗口的自定义显示。

原文见: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.Edit​or;
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());
}
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值