Original Title: Add menu items outside AppendAdditionalComponentMenuItems.
(not accepted by the forum -> “Title seems unclear, is it a complete sentence?”)
Hello,
I’m looking to add entries to a component’s context menu outside of the usual logic via GH_Component.AppendAdditionalComponentMenuItems
.
I am updating my C# script debugger (https://github.com/corbane/Ghx.CSharpScript) and would like to be able to add options to the components menu via the CSX script.
My problem is that all of these updates are done by its script and after component initialization, so after calling GH_Component.AppendAdditionalComponentMenuItems
.
I tried various things, like:
public class CsxComponent : GH_Component
{
ToolStripDropDown m_menu;
protected override void AppendAdditionalComponentMenuItems (ToolStripDropDown menu)
{
//...
m_menu = menu;
}
void OnUpdateCodeSource ()
{
foreach (var option in m_codeSource) {
Menu_AppendItem (m_menu, option.Name, ...);
// I have try here some specific Windows.Forms function like
// - m_menu.ResumeLayout (true);
// - m_menu.Refresh ();
}
}
}
At runtime, m_menu.Items
is assigned, but when Grasshopper is refreshed, the new item is deleted.
I know this is a very special case but if anyone has any idea how to fix this that would be really great !!
thanks, jmv.