Add context menu item to IronPython2 component

In Rhino 7 we had some components which had dynamic input arguments named depending on the selected item from the context menu of the component. The items in the context menu were also added dynamically by the component.

I am trying to get these working in Rhino8 as IronPython2 components but have the following issue:

I am not able to add custom items to the context menu. I’m overriding AppendAdditionalComponentMenuItems but it doesn’t seem to do anything.

from ghpythonlib.componentbase import executingcomponent as component

class DynamicComponentTest(component):
    def RunScript(self):
        pass

    def AppendAdditionalComponentMenuItems(self, *args, **kwargs):
        item = menu.Items.Add("menu item #1", None, self.on_item_click)
    
    def on_item_click(self, *args, **kwargs):
        pass

Nothing gets added to the context menu.

Am I doing anything wrong?

Thanks,
Chen

That probably required running the GhPython component in SDK mode. Which isn’t directly available in the new IronPython editor. You can achieve similar functionality by using the Script Instance template. Though that will likely require some rewriting of your existing code:

That might also still not support what you’re trying to achieve. But you can also still use GhPython in Rhino 8, it’s just hidden by default.

Thanks @AndersDeleuran!

I’m coming back to this after a while…
This is indeed not available in GH_ScriptInstance… same for Python3 script components.

Any idea if McNeel decided to get rid of runtime modifying the context menu on Python components? Or is it coming soon?

Thanks,
Chen

@eirannejad might be able to answer those questions.

2 Likes

for future reference, @eirannejad answered here: Python3 component RunScript() parameter names changing

1 Like