Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5800

GHPython OnClicked

$
0
0

Hi All,
I’m new GH.
I’m trying to create a component by python. And take value from OnClicked.
So I set value k = 1 and output by a. But it’s warning “1. Solution exception:global name ‘k’ is not defined”.
Any ideas ?

from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System
import Rhino
import rhinoscriptsyntax as rs

class MyComponent(component):

def AppendAdditionalComponentMenuItems(self, menu):
    item = Grasshopper.Kernel.GH_Component.Menu_AppendGenericMenuItem(
        menu, "This is an Additonal Menu!!", self.OnClicked, self.Icon_24x24, None, True, False);
    item.ToolTipText = "Additonal Menu";
def OnClicked(self, obj, args):
    try:
        k = 1
    except Exception, ex:
        System.Windows.Forms.MessageBox.Show(str(ex))
def RunScript(self, x, y):
    a = k
    # return outputs if you have them; here I try it for you:
    return a

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5800