0
$\begingroup$

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'

$\endgroup$
4
  • $\begingroup$ Well, accessing a text data block is easy: 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. $\endgroup$
    – TheLabCat
    Sep 27, 2021 at 13:45
  • $\begingroup$ @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? $\endgroup$
    – TheLabCat
    Sep 27, 2021 at 13:57
  • $\begingroup$ @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. $\endgroup$
    – John MC
    Sep 27, 2021 at 14:34
  • $\begingroup$ ok, found an answer, which works for me here: blender.stackexchange.com/questions/33603/… $\endgroup$
    – John MC
    Sep 27, 2021 at 15:00

1 Answer 1

1
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ txt = D.texts.get("Text") assigns the data block to txt if present. $\endgroup$
    – brockmann
    Sep 28, 2021 at 6:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .