Skip to main content
added 472 characters in body
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

Its running modal

The file browser as noted in question code when invoked is running modally.

print("execute", self.filepath)

in your execute method where you set the class property, will notice in output

No file selected
execute some/file/path

because the filebrowser has been invoked and is running modally, the last print in script is executed before the new print.

If however we change test call to

bpy.ops.open.file(filepath="wink")
print(OpenBrowser.selected_file)

we get

execute wink
No file selected

Which reminds us that it is a slippery slope to set a class property from an instance, ie it doesn't work so instead

self.__class__.selected_file = self.filepath

outputs:

execute wink
wink

or perhaps better still, make a class method to set it.

Window Manager Last Time Props

Another option would be to use the output of WindowManager.operator_properties_last

>>> props = C.window_manager.operator_properties_last("open.file")
>>> props.filepath
'/home/batfinger/Documents/wildhorses.txt'

which if not run prior (or get the name wrong)

>>> props = C.window_manager.operator_properties_last("open.pile") is None
True

SpaceFileBrowser.params

Finally as shown in this answer re a check method https://blender.stackexchange.com/a/207665/15543 can get the current filepath directly from the filebrowser space while it has context.

Its running modal

The file browser as noted in question code when invoked is running modally.

print("execute", self.filepath)

in your execute method where you set the class property, will notice in output

No file selected
execute some/file/path

because the filebrowser has been invoked and is running modally, the last print in script is executed before the new print.

If however we change test call to

bpy.ops.open.file(filepath="wink")
print(OpenBrowser.selected_file)

we get

execute wink
No file selected

Which reminds us that it is a slippery slope to set a class property from an instance, ie it doesn't work so instead

self.__class__.selected_file = self.filepath

outputs:

execute wink
wink

or perhaps better still, make a class method to set it.

Window Manager Last Time Props

Another option would be to use the output of WindowManager.operator_properties_last

>>> props = C.window_manager.operator_properties_last("open.file")
>>> props.filepath
'/home/batfinger/Documents/wildhorses.txt'

which if not run prior (or get the name wrong)

>>> props = C.window_manager.operator_properties_last("open.pile") is None
True

Its running modal

The file browser as noted in question code when invoked is running modally.

print("execute", self.filepath)

in your execute method where you set the class property, will notice in output

No file selected
execute some/file/path

because the filebrowser has been invoked and is running modally, the last print in script is executed before the new print.

If however we change test call to

bpy.ops.open.file(filepath="wink")
print(OpenBrowser.selected_file)

we get

execute wink
No file selected

Which reminds us that it is a slippery slope to set a class property from an instance, ie it doesn't work so instead

self.__class__.selected_file = self.filepath

outputs:

execute wink
wink

or perhaps better still, make a class method to set it.

Window Manager Last Time Props

Another option would be to use the output of WindowManager.operator_properties_last

>>> props = C.window_manager.operator_properties_last("open.file")
>>> props.filepath
'/home/batfinger/Documents/wildhorses.txt'

which if not run prior (or get the name wrong)

>>> props = C.window_manager.operator_properties_last("open.pile") is None
True

SpaceFileBrowser.params

Finally as shown in this answer re a check method https://blender.stackexchange.com/a/207665/15543 can get the current filepath directly from the filebrowser space while it has context.

added 472 characters in body
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

Its running modal

The file browser as noted in question code when invoked is running modally.

print("execute", self.filepath)

in your execute method where you set the class property, will notice in output

No file selected
execute some/file/path

because the filebrowser has been invoked and is running modally, the last print in script is executed before the new print.

If however we change test call to

bpy.ops.open.file(filepath="wink")
print(OpenBrowser.selected_file)

we get

execute wink
No file selected

Which reminds us that it is a slippery slope to set a class property from an instance, ie it doesn't work so instead

self.__class__.selected_file = self.filepath

outputs:

execute wink
wink

or perhaps better still, make a class method to set it.

Window Manager Last Time Props

Another option would be to use the output of WindowManager.operator_properties_last

>>> props = C.window_manager.operator_properties_last("open.file")
>>> props.filepath
'/home/batfinger/Documents/wildhorses.txt'

which if not run prior (or get the name wrong)

>>> props = C.window_manager.operator_properties_last("open.pile") is None
True

Its running modal

The file browser as noted in question code when invoked is running modally.

print("execute", self.filepath)

in your execute method where you set the class property, will notice in output

No file selected
execute some/file/path

because the filebrowser has been invoked and is running modally.

If however we change test call to

bpy.ops.open.file(filepath="wink")
print(OpenBrowser.selected_file)

we get

execute wink
No file selected

Which reminds us that it is a slippery slope to set a class property from an instance, ie it doesn't work so instead

self.__class__.selected_file = self.filepath

outputs:

execute wink
wink

or perhaps better still, make a class method to set it.

Its running modal

The file browser as noted in question code when invoked is running modally.

print("execute", self.filepath)

in your execute method where you set the class property, will notice in output

No file selected
execute some/file/path

because the filebrowser has been invoked and is running modally, the last print in script is executed before the new print.

If however we change test call to

bpy.ops.open.file(filepath="wink")
print(OpenBrowser.selected_file)

we get

execute wink
No file selected

Which reminds us that it is a slippery slope to set a class property from an instance, ie it doesn't work so instead

self.__class__.selected_file = self.filepath

outputs:

execute wink
wink

or perhaps better still, make a class method to set it.

Window Manager Last Time Props

Another option would be to use the output of WindowManager.operator_properties_last

>>> props = C.window_manager.operator_properties_last("open.file")
>>> props.filepath
'/home/batfinger/Documents/wildhorses.txt'

which if not run prior (or get the name wrong)

>>> props = C.window_manager.operator_properties_last("open.pile") is None
True
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

Its running modal

The file browser as noted in question code when invoked is running modally.

print("execute", self.filepath)

in your execute method where you set the class property, will notice in output

No file selected
execute some/file/path

because the filebrowser has been invoked and is running modally.

If however we change test call to

bpy.ops.open.file(filepath="wink")
print(OpenBrowser.selected_file)

we get

execute wink
No file selected

Which reminds us that it is a slippery slope to set a class property from an instance, ie it doesn't work so instead

self.__class__.selected_file = self.filepath

outputs:

execute wink
wink

or perhaps better still, make a class method to set it.