1
$\begingroup$

More precisely: what is the "directory" or "section" of a text file?

This code is not working:

file_path = os.path.abspath(Input_File_Path)
text_path = 'texts'
text_name = 'Sample_Text'

bpy.ops.wm.append(
   filepath=os.path.join(file_path, text_path, text_name),
   directory=os.path.join(file_path, text_path),
   filename=text_name
) 

I guess the problem lies at the text_path.

When in Blender I look for bpy.data.texts['Sample_Text'].filepath, I get '' although the text exists.

Could someone point me in the right direction?

$\endgroup$
6
  • $\begingroup$ It helps if you post the error Traceback if you want help debugging the error. $\endgroup$
    – Jakemoyo
    May 19, 2022 at 12:24
  • $\begingroup$ That is the funny thing: no Error but also no appended text. I can append the text from the specified file via Blender interactively but I'm not able to do the same with python. $\endgroup$
    – Steve
    May 19, 2022 at 17:29
  • $\begingroup$ wm.append is meant for copying data blocks from one blender file to another. (It's the implementation of the append menu entry). If that's what you want, then text_path should be set to "Text" (no s, upper case T) and text_name to the name of the text block in the input file. Is that what you want here? $\endgroup$ May 19, 2022 at 18:31
  • $\begingroup$ Yes, that's exactly what I was looking for. Thank you! I tested different Text_path entries (also 'text') but without the upper case T. With 'Text' it works perfectly. I could not find any reference on this so maybe it would be helpful if you could post this as the Answer. $\endgroup$
    – Steve
    May 19, 2022 at 19:11
  • $\begingroup$ Done. I don't know of a part of the manual that explains this either. $\endgroup$ May 19, 2022 at 20:25

1 Answer 1

1
$\begingroup$

wm.append is meant for copying data blocks from one blender file to another. It is the implementation of the append menu entry.

You can determine how the directory entry you want is spelled by trying an append manually (FileAppend); navigating to a Blend file and looking at what the file browser shows at that point, for example:

File Browser navigated to a Blend file showing the directories.

You can also determine this in the outliner by selecting Blender File as the display mode, but this approach has two exceptions:

  • The names are all spelled as plurals, but as you can see in the above screenshot they're singular as "directories"
  • A directory type will only be present if you have objects of that type in the current blend file.

In your case text_path should be set to "Text" (no s, upper case T) and text_name to the name of the text block in the input file.

Note that names are case sensitive.

$\endgroup$

You must log in to answer this question.

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