How can I assign two values to the output tabs A and B of the Python Script Editor in the “Script Instance template”?
"""Grasshopper Script Instance"""
import System
import Rhino
import Grasshopper
import rhinoscriptsyntax as rs
import math
class MyComponent(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self, x: int, y: int):
# Calculate results
result1 = x + y
result2 = x * y
# Assign results to output variables
A = result1 # First output
B = result2 # Second output
@eirannejad Oh, I see. Thank you for the reply, but can it be intuitive, like the C# script editor? What if I have a series of return variables? Then, I always have to take care of their order, which will be very frustrating.
“Intuitive” is subjective. RunScript follows idiomatic function calls for each language. A function that takes two arguments and returns two values is defined similar to:
Accepting a dictionary {"A": A, "B": B} as the return value would help with the “order” problem but that would break any script that has one output parameter of type dictionary.
The only other way this could work is to inject A and B as variables on the MyComponent class. Then you would have to reference them as self.A and self.B which is even more typing, and it would break the pattern that is already established and been in use for many years in the older scripting component.