Waiting for something in FileMaker, e.g. polling from a plugin?

7 messages Options
Embed this post
Permalink
Michael Wood-8

Waiting for something in FileMaker, e.g. polling from a plugin?

Reply Threaded More More options
Print post
Permalink
I do not have much experience with FileMaker and FileMaker plugins.
If I call a script that starts an external command to do something,
e.g. scan a document, then I need a way to get FileMaker to do
something when the process is finished.  i.e. I want FileMaker to
automatically insert a reference to the scanned document into a
container field.

Since the external command could take quite a while to run, it would
be best if the user could make use of that time to fill in other
fields etc.  Also it's not possible to know up front how long the scan
will take, because the scanner might first have to warm up.

So, how does one solve this sort of problem in FileMaker?  Is it
possible, for example, to have a plugin that polls for the scanned
document every second until some timeout has been reached and then
inserts the reference into the container field when the file becomes
available?  (Or instead of inserting into a container, calls the
appropriate SuperContainer functions to upload the file to
SuperContainer?)

I would appreciate any ideas on how to deal with problems like the
above in FileMaker.

Thanks in advance.

--
Michael Wood <[hidden email]>
Jesse Barnum-3

Re: Waiting for something in FileMaker, e.g. polling from a plugin?

Reply Threaded More More options
Print post
Permalink
Probably the best way to handle this is by calling a script on the idle handler. FileMaker will
call your plugin frequently (about 60 times a second in my testing), and once your plugin
detects that the scan has finished, it can trigger a script the next time it gets called by the
idle handler. If your plugin polls for the scanned document every second, be sure to make
sure that the document has been closed by the app that created it, so that you're not
working with a partial document.

The script you call in FileMaker can obviously do whatever you want; it can insert a
referenced container field or it can upload the doc to SuperContainer user the SC plugin. It
is also possible to use the evaluate() function directly from your plugin to call other plugin
functions, like the SC upload, without needing to call a script in FileMaker. It's safe to call
plugin functions this way, but be careful about trying to access field data in the idle
hander, it doesn't work reliably.

--Jesse Barnum, 360Works
http://www.360works.com

--- In [hidden email], "Michael Wood" <esiotrot@...> wrote:

>
> I do not have much experience with FileMaker and FileMaker plugins.
> If I call a script that starts an external command to do something,
> e.g. scan a document, then I need a way to get FileMaker to do
> something when the process is finished.  i.e. I want FileMaker to
> automatically insert a reference to the scanned document into a
> container field.
>
> Since the external command could take quite a while to run, it would
> be best if the user could make use of that time to fill in other
> fields etc.  Also it's not possible to know up front how long the scan
> will take, because the scanner might first have to warm up.
>
> So, how does one solve this sort of problem in FileMaker?  Is it
> possible, for example, to have a plugin that polls for the scanned
> document every second until some timeout has been reached and then
> inserts the reference into the container field when the file becomes
> available?  (Or instead of inserting into a container, calls the
> appropriate SuperContainer functions to upload the file to
> SuperContainer?)
>
> I would appreciate any ideas on how to deal with problems like the
> above in FileMaker.
>
> Thanks in advance.
>
> --
> Michael Wood <esiotrot@...>
>

Michael Wood-8

Re: Re: Waiting for something in FileMaker, e.g. polling from a plugin?

Reply Threaded More More options
Print post
Permalink
Hi Jesse

On Wed, Nov 5, 2008 at 5:18 PM, jbarnum <[hidden email]> wrote:
> Probably the best way to handle this is by calling a script on the idle
> handler. FileMaker will
> call your plugin frequently (about 60 times a second in my testing), and
> once your plugin
> detects that the scan has finished, it can trigger a script the next time it
> gets called by the
> idle handler.

Thanks!  That sounds like it should work very well.  I haven't played
around with FM plugins much, but I do vaguely remember something about
the idle handler.  Do you just basically specify in the resources that
one of your functions is your idle handler?

> If your plugin polls for the scanned document every second, be
> sure to make
> sure that the document has been closed by the app that created it, so that
> you're not
> working with a partial document.

Yes, I'll have to make sure of that :)

> The script you call in FileMaker can obviously do whatever you want; it can
> insert a
> referenced container field or it can upload the doc to SuperContainer user
> the SC plugin. It
> is also possible to use the evaluate() function directly from your plugin to
> call other plugin
> functions, like the SC upload, without needing to call a script in
> FileMaker.

Excellent!  Another newbie question:  How does one call a FileMaker
script from the FileMaker plugin?

> It's safe to call
> plugin functions this way, but be careful about trying to access field data
> in the idle
> hander, it doesn't work reliably.

OK, thanks for the warning.

--
Michael Wood <[hidden email]>
Jesse Barnum-3

Re: Waiting for something in FileMaker, e.g. polling from a plugin?

Reply Threaded More More options
Print post
Permalink
Hi Michael - these types of questions get into specific C++ code issues that are best
answered by looking at the plugin API itself and the examples that come with it. If you have
FileMaker Advanced, I believe that those files are included as an extra on the install CD.

Jesse Barnum, 360Works
http://www.360works.com

--- In [hidden email], "Michael Wood" <esiotrot@...> wrote:

>
> Hi Jesse
>
> On Wed, Nov 5, 2008 at 5:18 PM, jbarnum <jesse@...> wrote:
> > Probably the best way to handle this is by calling a script on the idle
> > handler. FileMaker will
> > call your plugin frequently (about 60 times a second in my testing), and
> > once your plugin
> > detects that the scan has finished, it can trigger a script the next time it
> > gets called by the
> > idle handler.
>
> Thanks!  That sounds like it should work very well.  I haven't played
> around with FM plugins much, but I do vaguely remember something about
> the idle handler.  Do you just basically specify in the resources that
> one of your functions is your idle handler?
>
> > If your plugin polls for the scanned document every second, be
> > sure to make
> > sure that the document has been closed by the app that created it, so that
> > you're not
> > working with a partial document.
>
> Yes, I'll have to make sure of that :)
>
> > The script you call in FileMaker can obviously do whatever you want; it can
> > insert a
> > referenced container field or it can upload the doc to SuperContainer user
> > the SC plugin. It
> > is also possible to use the evaluate() function directly from your plugin to
> > call other plugin
> > functions, like the SC upload, without needing to call a script in
> > FileMaker.
>
> Excellent!  Another newbie question:  How does one call a FileMaker
> script from the FileMaker plugin?
>
> > It's safe to call
> > plugin functions this way, but be careful about trying to access field data
> > in the idle
> > hander, it doesn't work reliably.
>
> OK, thanks for the warning.
>
> --
> Michael Wood <esiotrot@...>
>



Kent Lendrum

Re: Re: Waiting for something in FileMaker, e.g. polling from a plugin?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Michael Wood-8
Hi Michael,

As Jesse has already pointed out, the FM API includes all the code you  
need to do this,  it's just a bit of a hard read until you get your  
head around it.

I have published an example of calling the FM Do_Script,  which is a  
slightly modified version of what is in the FM example.

http://fmplugins.idma.co.nz/index.php/Other_Tips


For the idle stuff, just look in the main file.  Near the bottom,  you  
will find the function

static void Do_PluginIdle(FMX_IdleLevel idleLevel)

You will only want to use the  case kFMXT_UserIdle: case.  And if you  
are doing something intensive (like file tasks) I suggest you only use  
every 60 calls  (approx 1 second) or even less frequent.  ie. given  
the task could take several seconds,  I'm sure it won't matter if you  
only poll every 5 seconds.


Checking that the file is 'complete' will be the challenge.   You may  
need to poll for several seconds,  and only assume complete if the  
file size hasn't changed for several seconds ???

cheers,

Kent.



On Nov 6, 2008, at 4:34 AM, Michael Wood wrote:

> Hi Jesse
>
> On Wed, Nov 5, 2008 at 5:18 PM, jbarnum <[hidden email]> wrote:
>> Probably the best way to handle this is by calling a script on the  
>> idle
>> handler. FileMaker will
>> call your plugin frequently (about 60 times a second in my  
>> testing), and
>> once your plugin
>> detects that the scan has finished, it can trigger a script the  
>> next time it
>> gets called by the
>> idle handler.
>
> Thanks!  That sounds like it should work very well.  I haven't played
> around with FM plugins much, but I do vaguely remember something about
> the idle handler.  Do you just basically specify in the resources that
> one of your functions is your idle handler?
>
>> If your plugin polls for the scanned document every second, be
>> sure to make
>> sure that the document has been closed by the app that created it,  
>> so that
>> you're not
>> working with a partial document.
>
> Yes, I'll have to make sure of that :)
>
>> The script you call in FileMaker can obviously do whatever you  
>> want; it can
>> insert a
>> referenced container field or it can upload the doc to  
>> SuperContainer user
>> the SC plugin. It
>> is also possible to use the evaluate() function directly from your  
>> plugin to
>> call other plugin
>> functions, like the SC upload, without needing to call a script in
>> FileMaker.
>
> Excellent!  Another newbie question:  How does one call a FileMaker
> script from the FileMaker plugin?
>
>> It's safe to call
>> plugin functions this way, but be careful about trying to access  
>> field data
>> in the idle
>> hander, it doesn't work reliably.
>
> OK, thanks for the warning.
>
> --
> Michael Wood <[hidden email]>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

Michael Wood-8

Re: Re: Waiting for something in FileMaker, e.g. polling from a plugin?

Reply Threaded More More options
Print post
Permalink
Hi Kent

On Wed, Nov 5, 2008 at 9:39 PM, Kent Lendrum <[hidden email]> wrote:
> Hi Michael,
>
> As Jesse has already pointed out, the FM API includes all the code you need
> to do this,  it's just a bit of a hard read until you get your head around
> it.
> I have published an example of calling the FM Do_Script,  which is a
> slightly modified version of what is in the FM example.
> http://fmplugins.idma.co.nz/index.php/Other_Tips

Ah thank you.  Just what I was looking for :)

> For the idle stuff, just look in the main file.  Near the bottom,  you will
> find the function
> static void Do_PluginIdle(FMX_IdleLevel idleLevel)
> You will only want to use the  case kFMXT_UserIdle: case.  And if you are

Thanks.

> doing something intensive (like file tasks) I suggest you only use every 60
> calls  (approx 1 second) or even less frequent.  ie. given the task could
> take several seconds,  I'm sure it won't matter if you only poll every 5
> seconds.
>
> Checking that the file is 'complete' will be the challenge.   You may need
> to poll for several seconds,  and only assume complete if the file size
> hasn't changed for several seconds ???
> cheers,

Yes, what I plan to do is write the file in one directory and then, as
the last step, move it into the directory that is being polled by the
plugin.

> Kent.

Thanks again for all the answers :)

--
Michael Wood <[hidden email]>
Michael Wood-8

Re: Re: Waiting for something in FileMaker, e.g. polling from a plugin?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Jesse Barnum-3
Hi Jesse

On Wed, Nov 5, 2008 at 5:39 PM, jbarnum <[hidden email]> wrote:
> Hi Michael - these types of questions get into specific C++ code issues that are best
> answered by looking at the plugin API itself and the examples that come with it. If you have
> FileMaker Advanced, I believe that those files are included as an extra on the install CD.

Thanks again.

--
Michael Wood <[hidden email]>