Can multiple clones share the same external Python script?

Hi forum,

Is it possible for multiple cloned components to use the same external Python file, so I only need to edit one .py for all of them?

Also, what does the “Document Link” behavior do?

In my understanding, for a script to run in VC, it must need to be loaded into VC first, rather than calling an external code file directly, though you could do an update function to update the same script inside all clones at once.

As for the “Document Link” behavior, I don’t know much about it, and to be honest, it looks more like deprecated behavior.:joy:

Thanks, BAD, for your reply!
Sad to hear that :worried:
Do you mean something like this? That is, instead of writing the script content directly in VC, load it from an external file to replace it — and reload it whenever I make changes to the file?

# In each clones' script behavior
from vcScript import *

uri = "shared_script.py"
comp = getComponent()

script = comp.findBehaviour("SHARED_SCRIPT")
if not script:
  script = comp.createBehaviour(VC_SCRIPT, "SHARED_SCRIPT")

# maybe on button pressed or some event happened
script.Script = ""
with open(uri, 'r') as f:
  script.Script = f.read()

Yes, that’s probably what I meant, it’s based on what you said about “use the same external Python file”, but of course with the conversion, you can pass the scripts edited in VC to the components you want at the right time.

2 Likes

Thanks again, BAD :hand_with_index_finger_and_thumb_crossed:
Maybe this will also help me manage the script versions — at least they’ll always stay the same at the right time.

1 Like