Convert rhinoiside code to python!

Hello, i tried to convert this c# code to python without success, any help very appreciated

  private void RunScript(ref object Receive_pt)

    Receive_pt = pt;


  // <Custom additional code> 

  Point3d pt;
  bool registered = false;

  IGH_Component comp = null;

  void Receive(IGH_Component component)
      Rhino.Runtime.HostUtils.RegisterNamedCallback("ToRiR_pt", RiRhino);

      comp = component;
      registered = true;

  void RiRhino(object sender, Rhino.Runtime.NamedParametersEventArgs args)
    Point3d values;
    if (args.TryGetPoint("point", out values))
      pt = values;


Python try

def Receive():
    registered = False
    component = gh.Kernel.IGH_Component
    if registered:
      rh.Runtime.HostUtils.RegisterNamedCallback("ToRiR_pt", RiRhino);
      comp = component
      registered = True

def RiRhino():
    args = rh.Runtime.NamedParametersEventArgs()
    if args.TryGetPoint("point"):
       pt = args[1]

    return point

Receive_str = RiRhino()


I can see two things without testing : you are setting registered to False inside the function, not outside as in C#, and the C# test is if not registered : you have reversed it in Python

Thank you @Dancergraham
When i set registered outside the function, i got an error:

Runtime error (UnboundLocalException): Local variable 'registered' referenced before assignment.


Something wrong with ghenv and component and more and i can’t configure the problem. (8.7 KB)

You can pass the value of registered in to the function as a second argument to clear that error…

Thank you Graham i will try