Hi @ivelin.peychev
no, the whole script is NOT executed again. Your class is instantiated only once at the beginning, and then RunScript() is run once for every time it is needed (may be thousand of times per solution).
If you want to set some logic at component creation or deletion, you can override Python’s initialization/deletion methods:
def __init__(self):
def __enter__(self): #alternative
def __exit__(self):
Also, you may override:
def __del__(self):
but that one relies on the Garbage Collector, and may happen in a very remote time from apparent deletion of the component (use with extreme caution: throwing exceptions in a Garbage Collector call will immediately close the program, and bugs are hard to debug).
Do not rely on what happens in the external scope when using the SKD-mode (object-oriented mode). It’s an implementation detail.
See an example here.
init-exit-sample.gh (6.5 KB)
Thanks,
Giulio
–
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
EDIT: in 6.7 and onward, the external scope will only evaluate once to make the behavior more apparent. See RH-47124.