LoveArx 发表于 2017-4-14 22:07:52

加载/卸载指定的菜单


问题:
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:


//
acedCommand (RTSTR, _T("_.CUILOAD"), RTSTR,_T("C:/TEST.CUI"), RTNONE) ;
acedMenuCmd (_T("P7=+TEST.POP1")) ;
//
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.

**** Hidden Message *****

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)
)

longer1000 发表于 2017-4-15 10:55:01

啥也不说了,感谢楼主分享哇!

lw5297590 发表于 2017-4-15 12:01:15

啥也不说了,感谢楼主分享哇!

青梅煮茶 发表于 2017-4-16 16:21:32

确实是难得好帖啊,顶先

炫翔 发表于 2017-4-28 16:28:41

回复学习

cdm1999 发表于 2018-3-25 21:51:52

飘过学习.........

xinxirong 发表于 2018-3-26 07:02:06

确实是难得好帖啊,顶先

xilihutude 发表于 2018-3-28 09:35:26

Thanks for sharing!

windlkx 发表于 2018-4-23 13:54:23

谢谢分享,学习arx的菜单加载方法~~

userzhl 发表于 2018-4-23 14:24:13

学习一下

愤怒的菜鸟 发表于 2018-8-14 09:54:33

看看,学习下菜单

why1025 发表于 2018-8-14 21:57:11

11111111111111111111111

topone4 发表于 2018-8-21 18:03:05

回复看看帖子,学习学些。。。。

qmqyqj 发表于 2018-11-21 22:16:30

我就想知道怎么卸载菜单

819534890 发表于 2018-11-22 14:41:22

回复学习学习,谢谢
页: [1] 2
查看完整版本: 加载/卸载指定的菜单