1
$\begingroup$

I have created a function that requires a file path input, I found a way to have the user input a file location but I am not sure how to access it. I thought it was assigned to the bpy.types.Scene.conf_path but I do not get the directory when its printed. Here is my code.

import bpy
class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

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

        obj = context.object
        col = layout.column()
        col.prop(context.scene, 'conf_path')


def register():
    bpy.utils.register_class(HelloWorldPanel)
    bpy.utils.register_module(__name__)
    bpy.types.Scene.conf_path = bpy.props.StringProperty \
      (
      name = "XML Location",
      default = "",
      description = "Define the root path of the project",
      subtype = 'DIR_PATH'
      )

def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)
    bpy.utils.unregister_module(__name__)
    del bpy.types.Scene.conf_path


if __name__ == "__main__":
    register()

I appreciate any help or direction. Thanks

$\endgroup$
2
  • $\begingroup$ Can you elaborate on the print statement? After setting should be reflected via py console: C.scene.conf_path Note this is an instance not the class. Don't use register class and register module together. Registering registerable classes with register_class is what register_module is doing for you.. (register_module has been ditched for 2.8) seriously consider starting from 2.8 at this point in time. Finally, On formatting, open braces are also considered a line continuation by python $\endgroup$
    – batFINGER
    Apr 12, 2019 at 4:48
  • $\begingroup$ You are right I was not printing the right thing. When I printed C.scene.conf_path. it worked. Thank you sooo much this saves me so much time. $\endgroup$
    – Nburgess
    Apr 12, 2019 at 12:58

1 Answer 1

0
$\begingroup$

I was not calling the information properly. It is not under bpy.types.Scene.conf_path but rather C.scene.conf_path.

$\endgroup$

You must log in to answer this question.

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