0

I want to open + read another script from myScript in the same Blender file.

e.g. i have a csv (in text editor) and want to read that from a script.

because of the comments it tried now this:

MyScript:

import MyData

print(MyData.getData())

MyData:

def getData():
return [
1,2,3,4,5
]


print ("from mydata:", getData())

i got error: ModuleNotFoundError: No module named 'MyData'

John MC
  • 708
  • 2
  • 12
  • Well, accessing a text data block is easy: https://docs.blender.org/api/current/bpy.types.Text.html but executing it when it’s not the same language would be tricky. I do not remember what CSV is.To execute more Python with Python, just use the built-in exec(“code string”) function. – TheLabCat Sep 27 '21 at 13:45
  • @MartyFouts makes Walden Media beaver “oh yeah! There’s a lot more than hope!” sounds Oh yeah, you can definitely read that within blender! However, that doesn’t actually sound like a script, but rather just a data file. Is there some other aspect that makes it executable? – TheLabCat Sep 27 '21 at 13:57
  • @MartyFouts: yes, you understood correct. It exists on both, but for testing purpose and quick changing data i would like to read it as text data block, if possible. – John MC Sep 27 '21 at 14:34
  • ok, found an answer, which works for me here: https://blender.stackexchange.com/questions/33603/importing-python-modules-and-text-files – John MC Sep 27 '21 at 15:00

1 Answers1

1

This worked as a charm for me:

text = bpy.data.texts['Text'].as_string()

Which exactly does, what i wanted: it reads another script in the same blender as text-file, where "Text" is the name of the script

John MC
  • 708
  • 2
  • 12