FxPlug open file dialog using a push button

I am trying to develop a plug in for motion in Objective-c using the FxPlug template and so far I have been having issues with getting "NSOpenPanel" to be called from a push button in order to get a file dialog window, similar to the "File" generator present in Motion.

[paramAPI addPushButtonWithName: @"MIDI file"
parameterID: 1
selector: @selector(MIDI_func)
parameterFlags: kFxParameterFlag_DEFAULT]

I have tried to call NSOpenPanel through "dispatch_async" so that it would run on the main thread and thus not crash but when I press the button it appears not to work

- (void)MIDI_func {

    NSLog(@"Button pressed");

    dispatch_async(dispatch_get_main_queue(), ^{

        NSOpenPanel* openDlg = [NSOpenPanel openPanel];
        [openDlg setCanChooseFiles:YES];
        [openDlg setAllowsMultipleSelection:NO];
        [openDlg setCanChooseDirectories:NO];


        if ([openDlg runModal] == NSModalResponseOK) {
            NSArray* urls = [openDlg URLs];

            for(NSInteger i = 0; i < [urls count]; i++ ) {
                NSString* url = [urls objectAtIndex:i];
                NSLog(@"Url: %@", url);
            }
        }
    });
}

How can I achieve this or is there a function in the FxPlug SDK that will let me open a file dialog from the host application?

I have also tried changing from dispatch_async to dispatch_sync in order to wait for input in the file dialog but it only created a file panel service called from the plugin instead of the host app so it is not visible.

Hi David,

I have a similar problem, and this is the only post I can find about it! Did you ever manage to get this working?

THanks

我有办法,但是我的问题没人帮我解决

FxPlug open file dialog using a push button
 
 
Q