0
$\begingroup$

I am currently trying to have the parameter set to Three Levels by default in an InputHelper window. Unfortunately, I can't access the value.

For example, if I try to access bpy.data.screens[“temp.010”].params like in the picture, I get the error that screens has no params.

enter image description here

Let's say I have this basic code to register a UI Panel and with a click on a button, I'm opening a File Browser Window to Import some files. I now want this window to have Resursions: Three Levels enabled by default.

import bpy
import os
from bpy.types import Operator, Panel
from bpy.props import StringProperty, CollectionProperty
from bpy_extras.io_utils import ImportHelper

class ImportDXF(bpy.types.Operator, ImportHelper):
    bl_idname = "object.import_dxf"
    bl_label = "Import DXF"
    bl_options = {'REGISTER', 'UNDO'}

    filename_ext = ".dxf"

    filter_glob: StringProperty(
        default="*.dxf;",
        options={'HIDDEN'},
    )
    files: CollectionProperty(type=bpy.types.PropertyGroup)

    def execute(self, context):
        folder = os.path.dirname(self.filepath)    
        for file in self.files:
            print(f"Importing: {file.name}")
        
        return {'FINISHED'}


class ImportDXFPanel(Panel):
    bl_label = "Import Panel"
    bl_idname = "OBJECT_PT_import_dxf"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Import DXF"

    def draw(self, context):
        layout = self.layout
        layout.operator("object.import_dxf", text="Import")

def register():
    bpy.utils.register_class(ImportDXF)
    bpy.utils.register_class(ImportDXFPanel)

def unregister():
    bpy.utils.unregister_class(ImportDXF)
    bpy.utils.unregister_class(ImportDXFPanel)


if __name__ == "__main__":
    register()
$\endgroup$
5
  • $\begingroup$ can you post some of the relevant code in the question so we can get an idea of the context it's working in? $\endgroup$
    – Jakemoyo
    Commented Nov 16 at 0:22
  • $\begingroup$ @Jakemoyo Sure. I have edited my original post. Thanks :) $\endgroup$
    – Erdorano
    Commented Nov 16 at 14:27
  • $\begingroup$ Yeah, I'm not totally sure, but I don't think that's possible, or if it is it's gonna be fairly complicated. Since you're using the ImportHelper that is basically a wrapper for calling the context.wm.fileselect_add operator which basically opens a modal with some predefined arguments that are hard-coded into the C++/Python API code, as you can see here. $\endgroup$
    – Jakemoyo
    Commented Nov 17 at 16:06
  • $\begingroup$ Maybe there's a way to add pass arguments into a modal before calling it's invoke method but I'm not familiar, Someone with a bit more knowledge of addon dev might correct me, but it seems fairly complex IMO. $\endgroup$
    – Jakemoyo
    Commented Nov 17 at 16:07
  • 1
    $\begingroup$ @Jakemoyo That's unfortunate. Thank you for your help anyway. I'll leave the thread open here and see if anyone else has a solution. If I could make it so that this option is active by default - regardless of my script, that would also be okay. But unfortunately I can't manage to save it as default $\endgroup$
    – Erdorano
    Commented Nov 22 at 8:31

0

You must log in to answer this question.

Browse other questions tagged .