I have tried in several ways and the only one that worked for me was through a modal that extends from ImportHelper
, however I would like to do everything from the main panel:
import bpy
from bpy.props import StringProperty
class MainPanel(bpy.types.Panel):
bl_idname = "Test"
bl_label = "Test File"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = 'View'
def draw(self, context):
layout = self.layout
scene = context.scene
layout.prop(scene, 'file_')
def showPath(self, context):
print("filepath: ", bpy.context.scene.file_)# return only //x_bot.json
print("self.filepath", self.filepath)# return error
def register():
bpy.utils.register_class(MainPanel)
bpy.types.Scene.file_ = bpy.props.StringProperty(
name= "File",
subtype='FILE_PATH',
update=showPath
)
def unregister():
bpy.utils.unregister_class(MainPanel)
if __name__ == "__main__":
register()