|
发表于 2021-1-25 14:10:00
|
显示全部楼层
public partial class CSendSynchronization
{
#if AC2006 || AC2007 || AC2008 || AC2009 || AC20081 || AC2011 || AC2012
///
/// 发送命令
///
///
///
[DllImport("acad.exe", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ads_queueexpr")]
private static extern int Ads_queueexpr(string strExpr);//非同步,这个在08/12发送lisp不会出错,但是发送bo命令出错了..
///
/// 发送命令,设置CommandFlags.Session可以同步,
/// 发送lisp也可以,但是非同步,在自动执行函数上面会非同步
///
///
public static void SendString(string str)
{
try
{
Ads_queueexpr(str + "\n");
}
catch (Exception ee)
{
//自执行发送lisp都是在最后的(异步执行)
var ed = Acap.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage(Environment.NewLine + "发送命令失败,导致加载失败!");
ed.WriteMessage(Environment.NewLine + "" + ee.Message + Environment.NewLine);
}
}
#else
///
/// 发送命令
///
/// 发送lisp加载命令
///
public static void SendString(string str)
{
Document dc = Acap.DocumentManager.MdiActiveDocument;
string commands = str + "\n";
try
{
dc.SendStringToExecute(commands, false, false, false);//08所有都flase会有问题,出现报错
}
catch (System.Exception ee)
{
//自执行发送lisp都是在最后的(异步执行)
var ed = dc.Editor;
ed.WriteMessage(ee.Message);
ed.WriteMessage(Environment.NewLine + "发送命令失败,导致加载失败!");
ed.WriteMessage(Environment.NewLine + ee.Message);
}
}
#endif
}
调用时候 SendString($"(load \"{fe}\")"); |
|