file selector callback function ?

hello blenderheads,

I think I’m wrong in the way I use it :


I have a loadFile(file) function, so everything works fine.
how can I send another argument to the function ?

loadFile(file,evt) for example doesn’t work.
also, how can I read the result of a return of a callback function :

def loadFile(file)
   return filename, status, blah

how could I retrieve filename, status, and blah after the fileselector call ?

(for the moment I go through global variables.)

I had to deal with that in my Meshfoot script.

What I discovered was that you can not reliably execute any code after a call to the selector, so I ended up with an even handler like this.

    if evt == DO_BROWSE:
        Blender.Window.FileSelector(process_browse, 'Select an OBJ file')
        # NOTE: Just because we called the file selector does not mean the code flow has stopped.
        # Nothing else can be done after the call to the FileSelector.

Then, as you mention use globals in the callback function to take care of any extra parameters you require.

Here is my Meshfoot process_browse.

def process_browse(passedFileName):
    # Global Draw.objects.
    global name,version
    global txtFootageName,txtFootagePath,sldFootageEnd

    # Global footage container.
    #global mfFootage,gCurrentFootageIndex

    cfi = Meshfoot_LIB_v01.gCurrentFootageIndex
    localmfFootage = Meshfoot_LIB_v01.mfFootage[cfi]
    outputText ("User selected file [" + passedFileName + "]")
    fileParts = passedFileName.split("\\")
    localmfFootage.file_name = passedFileName
    localmfFootage.footage_name = fileParts[-1]                        # Temporarily save here, gets parsed down further.
    l1 = len(localmfFootage.footage_name)
    if l1 > 0:
        l2 = len(passedFileName)
        outputText("Operating on Footage Index:" + str(cfi))
        localmfFootage.footage_path = passedFileName[:(l2-l1)]
        moreParts = localmfFootage.footage_name.split(".")
        localmfFootage.footage_extension = "." + moreParts[-1]
        l1 = len(localmfFootage.footage_extension)
        l2 = len(localmfFootage.footage_name)
        localmfFootage.footage_name = localmfFootage.footage_name[:(l2-l1)]                        # Remove extension.
        localmfFootage.footage_name = removeTrailingNumbers(localmfFootage.footage_name)        # Get rid of trailing number sequence.
        txtFootageName.val = localmfFootage.footage_name
        txtFootagePath.val = localmfFootage.footage_path
        # Try to figure out how many frames are in this "Browsed" to OBJ sequence.
        tempFound, tempSkipped = reviewFileSequence(localmfFootage)
        if tempFound > 1:
            sldFootageEnd.val = localmfFootage.footage_start + (tempFound-1)                                                            # Assign the found count to the footage end slider.
            localmfFootage.footage_end = sldFootageEnd.val
            # Time to load all those OBJ files into memory.
            localScene = Scene.GetCurrent()
            r = loadMeshSequence (localmfFootage, localScene)
            if r == True:
                reviewFootage(localmfFootage)        # Set status flags for this footage.
                synchINIToGUI()                        # Write the internal information to the INI, then populate GUI from INI.
                r = MsgBox (name + " - Version: " + version,"Problem loading OBJ sequence.") 
            r = MsgBox (name + " - Version: " + version,"No OBJ sequence detected.")
        outputText ("Problem parsing footage file name [" + passedFileName + "]")


thanks atom,
so it seems there’s no other way then.
it’s a bit odd, no, this global thing … ?