马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
问题:
I want to load a submenu when my ObjectARX application is loaded and remove it when it is unloaded. The following code does not work:
[C++] 纯文本查看 复制代码 //[on application load]
acedCommand (RTSTR, _T("_.CUILOAD"), RTSTR,_T("C:/TEST.CUI"), RTNONE) ;
acedMenuCmd (_T("P7=+TEST.POP1")) ;
//[on application unload]
acedCommand (RTSTR, _T("_.CUIUNLOAD"), RTSTR, _T("TEST"), RTNONE) ;
解决方案:
Using acedCommand() within an acrxEntryPoint() or within a reactor is problematic. To get around this limitation, it is possible to use the undocumented function ads_queueexpr(). The following code demonstrates how you would use it to load and unload a menu specific to your application.
The swprintf() expression in an initApp() function prepares a string that will both load the menu (using CUILOAD). Call this from On_kInitAppMsg. To add the POP1 menu in at the POP7 location, it is better to delegate this into the associated .MNL file.
The presence of the ARX application associated to the .MNU file loaded is tested
in the MNL file. If it is not present, unload the menu. The problem is that
during the AcRx::kUnloadAppMsg message, an AutoLISP expression is queued.
Unfortunately, this expression is evaluated only when AutoCAD will be next in
ready state. During a quit sequence AutoCAD will never be in ready state again,
so the expression will never be evaluated. The solution to that problem is to
delegate the menu unload operation to the next time AutoCAD starts. To do this,
associate an .MNL file to our menu, which checks the presence of the ARX
application. If it is not present, then unload the partial loaded menu as
demonstrated here.
;; Associated .mnl file, Note: If S::STARTUP is included in an MNL file, it is called when you enter a new drawing or open an existing drawing
(defun-q MyMenuFunc ()
(if (/= (member "myapp.arx" (arx)) nil) ;notice the name of the arx is all lower case for this if statement
(menucmd "p7=+TEST.POP1") ;; if ARX app present, push POP1 into position 7
(command "_.menuunload" "TEST") ;; else unload the menu
)
(princ)
)
(if S::STARTUP
(if (equal (type S::STARTUP) 'LIST)
(setq S::STARTUP (append S::STARTUP MyMenuFunc))
)
(setq S::STARTUP MyMenuFunc)
)
|