Page MenuHome

load Text File with Python from GUI Button results in 0 User
Closed, ResolvedPublic

Description

System Information
Win 7 64 - AMD R9 380

Blender Version
Broken: 2.79
Worked: (2.74)

Short description of error
A loaded Text File with Python from GUI Button results in 0 User, and the Textblock ist marked red.

Exact steps for others to reproduce the error
Here is a blend.


Run the Script with Alt+P. It creates a Panel in the scene context of the properties editor.
Place a TXT on the C:\ Drive to load. Load it with the Button. Maybe you need to adjust the Filename in the Script bevore.
See what happens to the loaded Text in the Text Editior.

Regards, Doc

Event Timeline

Philipp Oeser (lichtwerk) triaged this task as Confirmed, Medium priority.

I think this has to do with commit rBa9163f7d222d, rB646aa40cf707 (which only ensured real user for doing it from the UI?).
Also see rB15eb83c8b375.
Doing this from python [via bpy.ops.text.open] would skip this step because SpaceText as well as PropertyPointerRNA are not set in this case.
Doing this from python [via bpy.data.texts.load] would also skip this.

I think something like D3447 fixes this.

Still unsure if bpy.data.texts.load should do the same? Or is this expected to have zero users then?
(I included the fix for bpy.data.texts.load in D3447 as well...)

Am not totally happy with it, but looks like operators creating new datablocks usually ensure they have one user, even if not actually used… Image opening one e.g., which can probably generate some usercount inconsistency in some cases. So guess we can do that unconditionally for text opening op too.

RNA data.xxx.load funcs do not do that though, see data.images.load e.g.