Bpy.ops.text.open() results in 0 Users

Hi. I get the Text File into Blender with:
That works, but the new Textblock is marked red, and .users is 0. ???
Saving the blend, and reopen does solve this, but it look weird to me.

Do i have to register the File somewhere?

S’up Doc? You could try:
Scanned for fake user stuff but the above is the best I found.

Thank you. But no, that does not work. I get an Error:
“RuntimeError: Operator bpy.ops.text.make_internal.poll() failed, context is incorrect”

Sorry, i forgot to say, i already use the internal Option with the open comand.
bpy.ops.text.open(filepath=f, internal=True)


Looked again, try:

If for the BGE try asking in the sub forum here.

Is this what you’re doing? I did the same exact thing and I don’t get the 0 users error.

path_to_file = "/Users/My_Name/Desktop/my_file_to_load.py"

bpy.ops.text.open(filepath = path_to_file, internal=True)

Yes, that’s exactly what i’m doing. This is strange.
The only Thing i can do wrong here ist the Filepath. But i have also a String as you do.

bpy.data.texts[‘Text’].use_fake_user gives False, as all other Scripts.

No, its not Game Engine. :slight_smile:

Edit :::::::::::::

I tried now in a plain blend File, and a fresh Script. That works. ???
But out of my AddOn, it fails with this effect.

Edit :::::::::::::

When running as plain Script with Alt+P, out of the Text Editor, it works. But not if i click my AddOn Button with this Function.

Edit :::::::::::::

Ok, i knowed i remember right. Because this did not happened in my earlier Versions. So i’ve tried it again in Blender 2.74, and there it worked correctly. That means it could be a Bug?

Ok, i think this is a Blender Bug. Because i can confirm this out of a fresh blend. It happens, when loading outside the Text Editor. Here is a Script you can try: OpenBug.py (1.0 KB)

It creates a Button in the Scene Properties. Place a *.txt on the C: Drive, run the Script with Alt+P and load the txt with the Button. You need to rename the File to load in the Script.

Edit :::::::::::::
Ok, i’ve reported a Bug.

I don’t have time to look at your file right now ,but I doubt this is a bug.

See if this works

path_to_file = "/Users/MyName/Desktop/file_to_load.py"

loaded_text_file = bpy.data.texts.load(filepath = path_to_file, internal=True)

loaded_text_file.use_fake_user = True

I was able to get the 0 users error, if I run the code without the “use_fake_user”.

Here’s a operator in scene properties if you want to test it.
I think your issue was trying to use a text operator outside of text editor. You prolly have to have a text editor open and run from the text editor for it to work.

import bpy

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the scene properties window"""
    bl_label = "Load Text"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def draw(self, context):
        layout = self.layout


class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Load Text"

    def execute(self, context):
        path_to_file = "/Users/MyName/Desktop/file_to_load.py"

        loaded_text_file = bpy.data.texts.load(filepath = path_to_file, internal=True)

        loaded_text_file.use_fake_user = True
        return {'FINISHED'}

def register():

def unregister():

if __name__ == "__main__":

Thank you. But it is not intended that scripts have a fake user. Even with 0 users the loaded Script is saved with the *.blend. And on the next reload, the Problem is gone. So, it looks only cosmetic to me. I call the function out of a Node-AddOn. I want do make a Tutorial Video about this AddOn and i just want to make sure i do not make any mistakes.

The same Script work without this Problem in 2.74. I think this is a Bug.

maybe was this?
bpy.ops.text.resolve_conflict(resolution=’IGNORE’) ##When external text is out of sync, resolve the conflict

But it seems the Problem is gone. It works without a Problem in UpBGE 0.2.5. But good to know. Thank You anyway.