RE: Menu with a Callback to rebuild Itself?

2013-02-13 Thread Matt Lind
I've solved that problem here with a separate plugin.

Related to past discussions, I usually set up my workgroup like this:

Workgroup
Application
Plugins
Commands
Events
Filters
Properties
Operators
Queries
ShaderDefs
Etc...
0_NC_ToolsUpdate.js


I have one plugin which resides in the root of /Plugins whose only job is to 
update plugins in the subfolders of /Plugins (0_NC_ToolsUpdate.js).  Whenever 
the plugin is run, all the subfolders are deleted and replaced with the latest 
version from source control, then UpdatePlugins() is called to refresh the 
Softimage session.  If you want to go more granular to target specific plugins, 
or use different logic to decide what to update, you can do that too inside of 
your update tool.

I just make sure to name the update plugin with a leading zero to ensure it 
gets parsed first in the workgroup upon startup of Softimage.  If you have any 
commands or other plugins which need to be parsed before others, then put them 
in a subfolder called '0_startup' or whatever you like.  I have one plugin 
(command) which defines all global variables for our custom tools and put that 
tool in 0_startup to ensure it's loaded first so other tools requesting 
information will have it available upon initialization.

Just like the issue you're encountering with the menu not being able to update 
itself, the update tools plugin (0_NC_ToolsUpdate.js) is updated periodically 
using an event which is triggered on termination of Softimage.

Matt







From: softimage-boun...@listproc.autodesk.com 
[mailto:softimage-boun...@listproc.autodesk.com] On Behalf Of Bradley Gabe
Sent: Tuesday, February 12, 2013 2:18 PM
To: softimage@listproc.autodesk.com
Subject: Menu with a Callback to rebuild Itself?

In the past, I've been able to reset custom Menus by isolating their init 
callbacks into a Plugin, then running:
Application.UnloadPlugin(MenuPath)
Application.LoadPlugin(MenuPath)

which effectively resets the Menu.

Now I have a situation where I need to be able to rebuild the Menu by running a 
callback item that lives within that same Menu.
Obviously, Softimage doesn't like this, and crashes out to desktop if I try to 
Unload the Plugin from which the Plugin itself is being called.

However, I thought there might be ways around this. I tried creating an Event 
that watches for when a Command has completed. Then I could run a command from 
that Menu, and it would be the Event, and not the Menu callback that does the 
Plugin Unload/Load. Sadly, this is also leading to a crash to desktop.

Does anyone have a strategy for me to try?

-B



Re: Menu with a Callback to rebuild Itself?

2013-02-12 Thread Stefan Kubicek

I'm not surpsised it crashes as the code it tries to execute has been pulled 
away from under it's feet when the plugin was unloaded. The only thing I can 
think of is implementing the loading/unloading in a different plugin (as part 
of the same workgroup or addon) that implements a timer event with a minimal 
delay and a repetition counter of 1. Unloading the menu plugin would then arm 
the timer in the second plugin (which does not get unloaded) , making sure the 
menu plugin is reloaded through the executed timer code.
Because timers are processed as part of the regular event loop (afaik), and 
there is only one such loop, it is always executed after everything else has 
been executed (except other, later armed timer events), which should avoid any 
race conditions. That's at least what's been working for me in the past for 
related stuff.



In the past, I've been able to reset custom Menus by isolating their init
callbacks into a Plugin, then running:

Application.UnloadPlugin(MenuPath)
Application.LoadPlugin(MenuPath)

which effectively resets the Menu.

Now I have a situation where I need to be able to rebuild the Menu by
running a callback item that lives within that same Menu.
Obviously, Softimage doesn't like this, and crashes out to desktop if I try
to Unload the Plugin from which the Plugin itself is being called.

However, I thought there might be ways around this. I tried creating an
Event that watches for when a Command has completed. Then I could run a
command from that Menu, and it would be the Event, and not the Menu
callback that does the Plugin Unload/Load. Sadly, this is also leading to a
crash to desktop.

Does anyone have a strategy for me to try?

-B




--
---
Stefan Kubicek   Co-founder
---
  keyvis digital imagery
 Wehrgasse 9 - GrĂ¼ner Hof
   1050 Vienna  Austria
Phone:+43/699/12614231
--- www.keyvis.at  ste...@keyvis.at ---
--  This email and its attachments are
--confidential and for the recipient only--