Using FMX_StartScript From Another Thread

12 messages Options
Embed this post
Permalink
threeflyingmonkeysuk

Using FMX_StartScript From Another Thread

Reply Threaded More More options
Print post
Permalink
Has anyone used the FMX_StartScript function?  I am trying to use it
from within a different function of my plugin other than the plugin
function.

If I call it from within the plugin function I can just use
dataVect.AtAsText(0) etc as parameters to it, but I'm having problems
declaring a fmx:text variable to store the filename/scriptname to call
at a later date from a different function.

Has anyone successfully done this or got any tips?

Thanks

Adam Dempsey

Kent Lendrum

Re: Using FMX_StartScript From Another Thread

Reply Threaded More More options
Print post
Permalink
Hi Adam,

fmx::TextAutoPtr theFile; // get the 'File Name'  passed to  
execute the script in
theFile->Assign("The File Name");
const fmx::Text&  file = *theFile;
                               
fmx::TextAutoPtr theScript; // get the 'Script Name' to perform in  
the File.
theScript->Assign("The Script Name");
const fmx::Text&  script  = *theScript;
                               
fmx::errcode err = FMX_StartScript( &file, &script,  
idleScript_Setting, NULL );



regards

Kent.




On 21/08/2008, at 2:29 AM, threeflyingmonkeysuk wrote:

> Has anyone used the FMX_StartScript function?  I am trying to use it
> from within a different function of my plugin other than the plugin
> function.
>
> If I call it from within the plugin function I can just use
> dataVect.AtAsText(0) etc as parameters to it, but I'm having problems
> declaring a fmx:text variable to store the filename/scriptname to call
> at a later date from a different function.
>
> Has anyone successfully done this or got any tips?
>
> Thanks
>
> Adam Dempsey
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

Adam Dempsey

Re: Using FMX_StartScript From Another Thread

Reply Threaded More More options
Print post
Permalink
That worked great thanks Kent!

I'm adding some new functions to MooPlug to allow Hotkeys to start
scripts!

Cheers

Adam Dempsey


--- In [hidden email], kent <kent@...> wrote:

>
> Hi Adam,
>
> fmx::TextAutoPtr theFile; // get the 'File Name'  passed to  
> execute the script in
> theFile->Assign("The File Name");
> const fmx::Text&  file = *theFile;
>
> fmx::TextAutoPtr theScript; // get the 'Script Name' to perform in  
> the File.
> theScript->Assign("The Script Name");
> const fmx::Text&  script  = *theScript;
>
> fmx::errcode err = FMX_StartScript( &file, &script,  
> idleScript_Setting, NULL );
>
>
>
> regards
>
> Kent.
>
>
>
>
> On 21/08/2008, at 2:29 AM, threeflyingmonkeysuk wrote:
>
> > Has anyone used the FMX_StartScript function?  I am trying to use it
> > from within a different function of my plugin other than the plugin
> > function.
> >
> > If I call it from within the plugin function I can just use
> > dataVect.AtAsText(0) etc as parameters to it, but I'm having problems
> > declaring a fmx:text variable to store the filename/scriptname to call
> > at a later date from a different function.
> >
> > Has anyone successfully done this or got any tips?
> >
> > Thanks
> >
> > Adam Dempsey
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
>


Jake Traynham

Re: Using FMX_StartScript From Another Thread

Reply Threaded More More options
Print post
Permalink
In reply to this post by threeflyingmonkeysuk
Hello Adam,

Here's some code:

fmx::TextAutoPtr theDB, theScript, theParam;
fmx::DataAutoPtr theData;
fmx::LocalAutoPtr theLocale; // defaults to fmx::Locale::kType_System
fmx::errcode err;

theDB->Assign("my db");
theScript->Assign("my script");
theParam->Assign("my script parameter");
theData->SetAsText(*theParam, *theLocale);

err = FMX_StartScript(&(*theDB), &(*theScript), kFMXT_Pause, &(*theParam));

That should help you figure out how to call a script with parameters
you've created.  However, to your (hidden/secondary) question about
calling a script from another thread, I'm betting you are going to run
into problems.  It may appear to work some of the time, but it will
randomly not work even when 'err' (in the above code) has a return value
of 0.  In my experience, to get the script to run correctly, you'll need
to run it within a FileMaker thread.  Your best bet is to build a queue
system into your plug-in that queues up scripts to be called and call
them when your plug-in receives a safe idle event.  The FileMaker
application only runs scripts on idle time anyway, so this is actually
the best time to inject your script call.

I hope this helps,
Jake

threeflyingmonkeysuk wrote:

>
>
> Has anyone used the FMX_StartScript function? I am trying to use it
> from within a different function of my plugin other than the plugin
> function.
>
> If I call it from within the plugin function I can just use
> dataVect.AtAsText(0) etc as parameters to it, but I'm having problems
> declaring a fmx:text variable to store the filename/scriptname to call
> at a later date from a different function.
>
> Has anyone successfully done this or got any tips?
>
> Thanks
>
> Adam Dempsey
>

--
Jake Traynham
Owner, CNS Plug-ins
http://www.cnsplug-ins.com/
Kent Lendrum

Re: Using FMX_StartScript From Another Thread

Reply Threaded More More options
Print post
Permalink
Hi Jake,

Thanks.  You've just saved me two lines of code.     (eg.  the  
&(*thDB)  step  )



btw : I believe the last parameter in your function call should have  
been  &(*theData)  instead of  &(*theParam)


Kent.



On 22/08/2008, at 2:45 AM, Jake Traynham wrote:

> Hello Adam,
>
> Here's some code:
>
> fmx::TextAutoPtr theDB, theScript, theParam;
> fmx::DataAutoPtr theData;
> fmx::LocalAutoPtr theLocale; // defaults to fmx::Locale::kType_System
> fmx::errcode err;
>
> theDB->Assign("my db");
> theScript->Assign("my script");
> theParam->Assign("my script parameter");
> theData->SetAsText(*theParam, *theLocale);
>
> err = FMX_StartScript(&(*theDB), &(*theScript), kFMXT_Pause,  
> &(*theParam));
>
> That should help you figure out how to call a script with parameters
> you've created.  However, to your (hidden/secondary) question about
> calling a script from another thread, I'm betting you are going to run
> into problems.  It may appear to work some of the time, but it will
> randomly not work even when 'err' (in the above code) has a return  
> value
> of 0.  In my experience, to get the script to run correctly, you'll  
> need
> to run it within a FileMaker thread.  Your best bet is to build a  
> queue
> system into your plug-in that queues up scripts to be called and call
> them when your plug-in receives a safe idle event.  The FileMaker
> application only runs scripts on idle time anyway, so this is actually
> the best time to inject your script call.
>
> I hope this helps,
> Jake
>
> threeflyingmonkeysuk wrote:
>>
>>
>> Has anyone used the FMX_StartScript function? I am trying to use it
>> from within a different function of my plugin other than the plugin
>> function.
>>
>> If I call it from within the plugin function I can just use
>> dataVect.AtAsText(0) etc as parameters to it, but I'm having problems
>> declaring a fmx:text variable to store the filename/scriptname to  
>> call
>> at a later date from a different function.
>>
>> Has anyone successfully done this or got any tips?
>>
>> Thanks
>>
>> Adam Dempsey
>>
>
> --
> Jake Traynham
> Owner, CNS Plug-ins
> http://www.cnsplug-ins.com/
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

Kent Lendrum

Displaying a Graphic Parameter in a Window

Reply Threaded More More options
Print post
Permalink
Hi All,

I'm trying to get a graphic, passed as a parameter, and display it in  
a window.  (On Mac at the moment, but will need Windows as well, so  
may be back for more)


So far, I have...  (have error checking, but removed to make easier to  
read)

I've included the results I'm getting for relevant lines at the bottom.

I'd appreciate any hints on the gaps in between getting the graphic,  
and trying to display it within a window (ideally as a control)

thanks

Kent.

----------------------------------------------------------------------
// relevant variables (others used, but declared elsewhere)
ControlButtonContentInfo iconButton;
char * graphicBuffer;
long graphicSize;


// Get the index for the graphic as PICT
index = theGraphic.GetIndex(*fmx::QuadCharAutoPtr( 'P', 'I', 'C',  
'T' ));


// Get the graphic buffer size
graphicSize = theGraphic.GetSize( index );


// create an array to store the graphic
// Note : Not sure what type this should be (char works ???)
graphicBuffer = new char [graphicSize];

       
// get the graphic and store in our buffer
err = theGraphic.GetData( index, 0, size, graphicBuffer );


// Define the default picture to show (PICT, none)
iconButton.contentType = kControlPictureHandleTag;
iconButton.u.picture = NULL;


// Create our control to store the graphic.  Allow user to click it.
err = CreatePictureControl( parentWinRef(), &R, &iconButton, true,  
&objectRef );


// Set the control to display our graphic
// this is returning error -30591 : Size doesn't match
err = SetControlData( objectRef, kControlPicturePart,  
kControlPictureHandleTag, Size(graphicBuffer), graphicBuffer );


------------------------------------------------------
Results from relevant calls.

Graphic Count : 3
Graphic Index : PICT (1)
Graphic Size : 3776
Created Picture Control : 0
Set Control Data : -30591


Jake Traynham

Re: Using FMX_StartScript From Another Thread

Reply Threaded More More options
Print post
Permalink
In reply to this post by Kent Lendrum
Hi Kent,

kent wrote:
>
>
> Hi Jake,
>
> Thanks. You've just saved me two lines of code. (eg. the
> &(*thDB) step )

Glad I could be of help.  If you want it to look prettier, I think you
can also do &theDB->get().  I don't think I'll every learn/remember all
the STL stuff, but someone else showed some code like that before.  What
I typed was the first thing I figured out, so that's what I always do.

>
> btw : I believe the last parameter in your function call should have
> been &(*theData) instead of &(*theParam)
>

   You are correct.  That's the problem with typing out untested code
into emails. :)  So, the corrected code is:


>  >
>  > fmx::TextAutoPtr theDB, theScript, theParam;
>  > fmx::DataAutoPtr theData;
>  > fmx::LocalAutoPtr theLocale; // defaults to fmx::Locale::kType_System
>  > fmx::errcode err;
>  >
>  > theDB->Assign("my db");
>  > theScript->Assign("my script");
>  > theParam->Assign("my script parameter");
>  > theData->SetAsText(*theParam, *theLocale);
>  >
>  > err = FMX_StartScript(&(*theDB), &(*theScript), kFMXT_Pause,
>  > &(*theData));
>  >

Jake

--
Jake Traynham
Owner, CNS Plug-ins
http://www.cnsplug-ins.com/
Jake Traynham

Re: Displaying a Graphic Parameter in a Window

Reply Threaded More More options
Print post
Permalink
In reply to this post by Kent Lendrum
Hi Kent,

   I'm not sure what the Size() function does, but if it's like sizeof,
then it's going to return 4, which is the size of a pointer, which is
what your "graphicBuffer" variable is.  You could maybe correct that by
using Size(*graphicBuffer), but why bother?  You already know the size
of the buffer because you used that to create the buffer.  So, instead
of using Size(graphicBuffer), just use your "graphicSize" variable.

Jake

PS.  Personally, I (would) use an "unsigned char" buffer, but I don't
think it really matters.

kent wrote:

>
>
> Hi All,
>
>
> I'm trying to get a graphic, passed as a parameter, and display it in a
> window.  (On Mac at the moment, but will need Windows as well, so may be
> back for more)
>
>
> So far, I have...  (have error checking, but removed to make easier to read)
>
> I've included the results I'm getting for relevant lines at the bottom.
>
> I'd appreciate any hints on the gaps in between getting the graphic, and
> trying to display it within a window (ideally as a control)
>
> thanks
>
> Kent.
>
> ----------------------------------------------------------------------
> // relevant variables (others used, but declared elsewhere)
> ControlButtonContentInfo iconButton;
> char * graphicBuffer;
> long graphicSize;
>
>
> // Get the index for the graphic as PICT
> index = theGraphic.GetIndex(*fmx::QuadCharAutoPtr( 'P', 'I', 'C', 'T' ));
>
>
> // Get the graphic buffer size
> graphicSize = theGraphic.GetSize( index );
>
>
> // create an array to store the graphic
> // Note : Not sure what type this should be (char works ???)
> graphicBuffer = new char [graphicSize];
>
>
> // get the graphic and store in our buffer
>
> err = theGraphic.GetData( index, 0, size, graphicBuffer );
>
>
> // Define the default picture to show (PICT, none)
> iconButton.contentType = kControlPictureHandleTag;
> iconButton.u.picture = NULL;
>
> // Create our control to store the graphic. Allow user to click it.
> err = CreatePictureControl( parentWinRef(), &R, &iconButton, true,
> &objectRef );
>
>
> // Set the control to display our graphic
> // this is returning error -30591 : Size doesn't match
> err = SetControlData( objectRef, kControlPicturePart,
> kControlPictureHandleTag, Size(graphicBuffer), graphicBuffer );
>
>
> ------------------------------------------------------
> Results from relevant calls.
>
> Graphic Count : 3
> Graphic Index : PICT (1)
> Graphic Size : 3776
> Created Picture Control : 0
> Set Control Data : -30591
>
>

--
Jake Traynham
Owner, CNS Plug-ins
http://www.cnsplug-ins.com/
clay_maeckel

Re: Displaying a Graphic Parameter in a Window

Reply Threaded More More options
Print post
Permalink
On 8/25/08 7:26 AM, "Jake Traynham" <[hidden email]> wrote:
>kent wrote:
>> // Set the control to display our graphic
>> // this is returning error -30591 : Size doesn't match
>> err = SetControlData( objectRef, kControlPicturePart,
>> kControlPictureHandleTag, Size(graphicBuffer), graphicBuffer );

I just looked up this API and from my understanding it wants a Macintosh
handle to a PICT, not a pointer to the raw PICT byte stream. So you may need
to create a Mac handle and stuff the data into there and then give it to
SetControlData. Also it looks like that call may not be supported much
longer in the MacOS X operating system.

--Clay


Kent Lendrum

Re: Displaying a Graphic Parameter in a Window

Reply Threaded More More options
Print post
Permalink
Hi Clay,

Thanks for getting back to me.

That's pretty much what I've worked out too.

What I haven't worked out,  is how to do this :(

So, I have this Unsigned Char from FileMaker with the graphic.

How do I get this into a Mac Handle so that I can pass it to the  
Control ???



Also.  Re your last statement : What function should I be looking at  
using instead ?


Thanks

Kent.


Sorry, I've been reading the Apple Developer stuff, but I still have a  
couple of blanks in my knowledge and I'm hoping for some inspiration  
here (or sample code to get me going)

On this note : I find the Microsoft Developer site even more  
challenging, although there does seem to be more examples



On 26/08/2008, at 5:15 AM, [hidden email] wrote:

> On 8/25/08 7:26 AM, "Jake Traynham" <[hidden email]> wrote:
>> kent wrote:
>>> // Set the control to display our graphic
>>> // this is returning error -30591 : Size doesn't match
>>> err = SetControlData( objectRef, kControlPicturePart,
>>> kControlPictureHandleTag, Size(graphicBuffer), graphicBuffer );
>
> I just looked up this API and from my understanding it wants a  
> Macintosh
> handle to a PICT, not a pointer to the raw PICT byte stream. So you  
> may need
> to create a Mac handle and stuff the data into there and then give  
> it to
> SetControlData. Also it looks like that call may not be supported much
> longer in the MacOS X operating system.
>
> --Clay

Kent Lendrum

Re: Displaying a Graphic Parameter in a Window

Reply Threaded More More options
Print post
Permalink
In reply to this post by Jake Traynham
Hi Jake,

Sorry, I was copying and pasting code.    My last attempt was to use  
Size(graphicBuffer) to get around the incorrect size error,   but I  
had originally used graphicSize.


And yes, unsigned char  would be correct,  however at this time, I'm  
not even sure that I should be using char to store the output at all.

I can't find any sample code / documentation on how to do this,  so  
I've been trying different combinations and getting a few of crashes  
as a result.


thanks

Kent.




>   I'm not sure what the Size() function does, but if it's like sizeof,
> then it's going to return 4, which is the size of a pointer, which is
> what your "graphicBuffer" variable is.  You could maybe correct that  
> by
> using Size(*graphicBuffer), but why bother?  You already know the size
> of the buffer because you used that to create the buffer.  So, instead
> of using Size(graphicBuffer), just use your "graphicSize" variable.
>
> Jake
>
> PS.  Personally, I (would) use an "unsigned char" buffer, but I don't
> think it really matters.
>
> kent wrote:
>>
>>
>> Hi All,
>>
>>
>> I'm trying to get a graphic, passed as a parameter, and display it  
>> in a
>> window.  (On Mac at the moment, but will need Windows as well, so  
>> may be
>> back for more)
>>
>>
>> So far, I have...  (have error checking, but removed to make easier  
>> to read)
>>
>> I've included the results I'm getting for relevant lines at the  
>> bottom.
>>
>> I'd appreciate any hints on the gaps in between getting the  
>> graphic, and
>> trying to display it within a window (ideally as a control)
>>
>> thanks
>>
>> Kent.
>>
>> ----------------------------------------------------------------------
>> // relevant variables (others used, but declared elsewhere)
>> ControlButtonContentInfo iconButton;
>> char * graphicBuffer;
>> long graphicSize;
>>
>>
>> // Get the index for the graphic as PICT
>> index = theGraphic.GetIndex(*fmx::QuadCharAutoPtr( 'P', 'I', 'C',  
>> 'T' ));
>>
>>
>> // Get the graphic buffer size
>> graphicSize = theGraphic.GetSize( index );
>>
>>
>> // create an array to store the graphic
>> // Note : Not sure what type this should be (char works ???)
>> graphicBuffer = new char [graphicSize];
>>
>>
>> // get the graphic and store in our buffer
>>
>> err = theGraphic.GetData( index, 0, size, graphicBuffer );
>>
>>
>> // Define the default picture to show (PICT, none)
>> iconButton.contentType = kControlPictureHandleTag;
>> iconButton.u.picture = NULL;
>>
>> // Create our control to store the graphic. Allow user to click it.
>> err = CreatePictureControl( parentWinRef(), &R, &iconButton, true,
>> &objectRef );
>>
>>
>> // Set the control to display our graphic
>> // this is returning error -30591 : Size doesn't match
>> err = SetControlData( objectRef, kControlPicturePart,
>> kControlPictureHandleTag, Size(graphicBuffer), graphicBuffer );
>>
>>
>> ------------------------------------------------------
>> Results from relevant calls.
>>
>> Graphic Count : 3
>> Graphic Index : PICT (1)
>> Graphic Size : 3776
>> Created Picture Control : 0
>> Set Control Data : -30591
>>
>>
>
> --
> Jake Traynham
> Owner, CNS Plug-ins
> http://www.cnsplug-ins.com/
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>

Jake Traynham

Re: Displaying a Graphic Parameter in a Window

Reply Threaded More More options
Print post
Permalink
Kent,

   There's something else I remembered about PICT files.  A PICT file on
the hard drive is going to have a 512 byte buffer on the beginning, but
a PICT stored in a container field is not going to have that buffer.
Maybe you need to add it before trying to assign it to your control?  I
dunno, I haven't dealt with PICTs in a while ... I've converted to using
PNGs with CGImages. *shrug*

Jake

Kent Lendrum wrote:

>
>
> Hi Jake,
>
> Sorry, I was copying and pasting code. My last attempt was to use
> Size(graphicBuffer) to get around the incorrect size error, but I
> had originally used graphicSize.
>
> And yes, unsigned char would be correct, however at this time, I'm
> not even sure that I should be using char to store the output at all.
>
> I can't find any sample code / documentation on how to do this, so
> I've been trying different combinations and getting a few of crashes
> as a result.
>
> thanks
>
> Kent.
>
>  > I'm not sure what the Size() function does, but if it's like sizeof,
>  > then it's going to return 4, which is the size of a pointer, which is
>  > what your "graphicBuffer" variable is. You could maybe correct that
>  > by
>  > using Size(*graphicBuffer), but why bother? You already know the size
>  > of the buffer because you used that to create the buffer. So, instead
>  > of using Size(graphicBuffer), just use your "graphicSize" variable.
>  >
>  > Jake
>  >
>  > PS. Personally, I (would) use an "unsigned char" buffer, but I don't
>  > think it really matters.
>  >
>  > kent wrote:
>  >>
>  >>
>  >> Hi All,
>  >>
>  >>
>  >> I'm trying to get a graphic, passed as a parameter, and display it
>  >> in a
>  >> window. (On Mac at the moment, but will need Windows as well, so
>  >> may be
>  >> back for more)
>  >>
>  >>
>  >> So far, I have... (have error checking, but removed to make easier
>  >> to read)
>  >>
>  >> I've included the results I'm getting for relevant lines at the
>  >> bottom.
>  >>
>  >> I'd appreciate any hints on the gaps in between getting the
>  >> graphic, and
>  >> trying to display it within a window (ideally as a control)
>  >>
>  >> thanks
>  >>
>  >> Kent.
>  >>
>  >> ----------------------------------------------------------
>  >> // relevant variables (others used, but declared elsewhere)
>  >> ControlButtonContentInfo iconButton;
>  >> char * graphicBuffer;
>  >> long graphicSize;
>  >>
>  >>
>  >> // Get the index for the graphic as PICT
>  >> index = theGraphic.GetIndex(*fmx::QuadCharAutoPtr( 'P', 'I', 'C',
>  >> 'T' ));
>  >>
>  >>
>  >> // Get the graphic buffer size
>  >> graphicSize = theGraphic.GetSize( index );
>  >>
>  >>
>  >> // create an array to store the graphic
>  >> // Note : Not sure what type this should be (char works ???)
>  >> graphicBuffer = new char [graphicSize];
>  >>
>  >>
>  >> // get the graphic and store in our buffer
>  >>
>  >> err = theGraphic.GetData( index, 0, size, graphicBuffer );
>  >>
>  >>
>  >> // Define the default picture to show (PICT, none)
>  >> iconButton.contentType = kControlPictureHandleTag;
>  >> iconButton.u.picture = NULL;
>  >>
>  >> // Create our control to store the graphic. Allow user to click it.
>  >> err = CreatePictureControl( parentWinRef(), &R, &iconButton, true,
>  >> &objectRef );
>  >>
>  >>
>  >> // Set the control to display our graphic
>  >> // this is returning error -30591 : Size doesn't match
>  >> err = SetControlData( objectRef, kControlPicturePart,
>  >> kControlPictureHandleTag, Size(graphicBuffer), graphicBuffer );
>  >>
>  >>
>  >> ------------------------------------------------------
>  >> Results from relevant calls.
>  >>
>  >> Graphic Count : 3
>  >> Graphic Index : PICT (1)
>  >> Graphic Size : 3776
>  >> Created Picture Control : 0
>  >> Set Control Data : -30591
>  >>
>  >>
>  >
>  > --
>  > Jake Traynham
>  > Owner, CNS Plug-ins
>  > http://www.cnsplug-ins.com/ <http://www.cnsplug-ins.com/>
>  >
>  > ------------------------------------
>  >
>  > Yahoo! Groups Links
>  >
>  >
>  >
>
>

--
Jake Traynham
Owner, CNS Plug-ins
http://www.cnsplug-ins.com/