找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1542|回复: 0

[分享] Use of Window.Focus in AutoCAD 2014

[复制链接]

已领礼包: 593个

财富等级: 财运亨通

发表于 2013-5-26 23:57:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Use of Window.Focus in AutoCAD 2014                                                        By Balaji Ramamoorthy
The new API in AutoCAD 2014 includes the Window.Focus method. This method is very useful if you were using palette to call a command that requires AutoCAD to prompt for user input. In earlier versions of AutoCAD, the AutoCAD editor did not receive focus until the editor was clicked. This was a bit troublesome as it required an additional mouse click. The way to overcome it was to either call the "SetFocus" Win32 API through a dllimport or to use an internal undocumented method : "Internal.Utils.SetFocusToDwgView".
With AutoCAD 2014, the "Window.Focus" method can be used instead. As an example, if you had a button in the palette to insert a block named "Autodesk", then you can use the Window.Focus method from the button click callback method as :
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using AAA = Autodesk.AutoCAD.ApplicationServices;
  3. private void InsertBlockBtn_Click(object sender, EventArgs e)
  4. {
  5.     AAA.Document activeDoc
  6.             = AAA.Application.DocumentManager.MdiActiveDocument;
  7.     dynamic acadDocObj = activeDoc.GetAcadDocument();
  8.     activeDoc.Window.Focus();
  9.     acadDocObj.SendCommand(String.Format("-Insert\nAutodesk\n"));

  10.     //            or

  11.     //object acadDocObj = activeDoc.GetAcadDocument();
  12.     //activeDoc.Window.Focus();
  13.     //object[] OnedataArry = new object[1];
  14.     //OnedataArry[0] = String.Format("-Insert\nAutodesk\n");
  15.     //acadDocObj.GetType().InvokeMember(
  16.     //  "SendCommand",
  17.     //  System.Reflection.BindingFlags.InvokeMethod,
  18.     //  null, acadDocObj, OnedataArry
  19.     //);

  20. }


论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-17 22:25 , Processed in 0.172583 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表