11 Replies Latest reply on Nov 14, 2015 5:47 AM by JPScott

    How to Get Chart outside of FMP and into Graphic File?




      I use FMP v14 to create static webpages for a basketball statistics website.   Note that I started doing this in the late 90's and developed the scripts etc. before FMP really had any built-in web functions. Basically what I do is run a script which exports a set of records (the text is generally formatted inside a HTML table) and then the script will append a header and a footer (to put it into HTML-readable format) and then this text file is exported, and renamed according to whatever the relevant record is at the time.  While it's pretty basic in terms of generating HTML files, it's worked well for me over the years and  I've pretty much stayed with it that way ever since (the only major change was to use Troi File plug-in instead of Applescript to rename exported text files into specific .html filenames.)


      Recently I have become interested in including some charts on the webpages, which leads me to my question.  I can create the chart in FMP but was looking for the best way to transfer that chart outside of FMP and ideally into a graphic file which I can name and refer to within the various webpages.


      So for example I might have a webpage listing statistics for a particular season:


      Statistics for 2014-15


      To that I would like the webpage to also reference and display a chart which I have created in FMP, such as the following:




      The brute force method to do this would be just to take a screen capture of the chart, save it as a graphic file and then set up the page to refer to the graphic file.


      However I'd like to be able to script this if possible because I can see that with some of the charts I'm considering,  the data will be changing periodically.


      So again, is there a way within a script to capture the contents of the chart and export it as a graphic file on my computer?  Within the script I can use the Troi plugin to rename the file to a specific filename if necessary and I can have FMP include a link in the webpage to refer to this graphic file in the webpage, but not sure the best way to get the chart out of FMP in the first place.


      From what I could see, GetLayoutObjectAttribute is a start to at least point to the chart in question, but it's not clear to me what to do at that point. Can I use that in conjunction with Troi plugin in some way?


      Any suggestions?  One caveat is that if possible I'd like to continue to just use straight scripts to export information to static webpages & files. I'm not looking at making the database itself web-accessible.


      Thanks in advance.

        • 1. Re: How to Get Chart outside of FMP and into Graphic File?

          You're on the right track with GetLayoutObjectAttribute. Use this calculation:


               GetLayoutObjectAttribute ( nameOfChartObject ; "content" )


          Put the result of that calculation into a container field. Then you can export the contents of the container field anywhere you want.

          • 2. Re: How to Get Chart outside of FMP and into Graphic File?

            OK thanks.  I'll give it a try this weekend and let you know how it goes.

            • 3. Re: How to Get Chart outside of FMP and into Graphic File?

              OK, well I tried it and got the same problem as the person in this discussion.


              Re: GetLayoutObjectAttribute for a Chart doesn't work using WebDirect


              Using the Inspector tool I have given the chart a name called "Minute Distribution".  I have also placed a container field (which I call "temp graphic container") in the same layout as the chart in question.


              In my script I have Set Field (temp graphic container) using the calculation GetLayoutObjectAttribute ("Minute Distribution"; "content").

              I then have an Export Field Contents (temp graphic container; temporary filename with path) script step.


              When I manually copy the chart into the container field, and run the Export Field Contents command in a script it works fine.


              The problem is that the earlier script step, where it's supposed to Set (the container) Field with the chart using GetLayoutObjectAttribute, this script step overwrites whatever was in the container and replaces it with nothing.  Then when the script runs and it tries to export an empty container field, it gives me an error message saying "Container Fields Cannot be Exported"


              The above discussion seems to indicate this is a bug.  Is this still true, and if so, is there a workaround ?



              • 4. Re: How to Get Chart outside of FMP and into Graphic File?

                I believe this may have to do with how you insert it by script. It should work though. FM gave me some trouble with insert image vs insert file when it came to exporting later.

                • 5. Re: How to Get Chart outside of FMP and into Graphic File?

                  It's not a bug. It won't work in WebDirect because WebDirect doesn't have scripted access to the OS, but requires user interaction. So you'll need to run this from a FileMaker client. The second issue is you have to give the chart time to refresh. (This technique won't work server-side either, because the windows don't refresh on the server.) So put a pause in the script of about 0.2 seconds after you set the container field, but before you try to export it. That seemed to work for me.

                  • 6. Re: How to Get Chart outside of FMP and into Graphic File?

                    Well I tried just a script with the Set Field command to transfer the named chart to the container field, and it still doesn't work.  This is with a Pause/Resume Script step of a few seconds and I even threw in a Refresh Window step as well.


                    When I run the script, it seems to do 'something' but then ends up with a blank container field.  I can manually copy or drag and drop the chart onto the container field successfully, but then when I try the script it will overwrite what was there and leave nothing.


                    Note that this is with FMP14.0.3 on a Mac running OS 10.11.1


                    I tried it earlier today on a Windows Machine with FMP13 and was successfully able to get the script to transfer a named chart to a container field, so what you suggest does work in some configurations, just not the configuration I need it on.


                    Any other suggestions or workarounds?


                    As of now I can just run the script and then at the point I want to transfer the chart to the container field, put in a Pause/Resume Script step and manually drag and drop it over.  A PITA but workable for now. But I'd still like to get this fully automated at some point.


                    • 7. Re: How to Get Chart outside of FMP and into Graphic File?

                      Is the chart on the active layout when the Set Field executes?

                      • 9. Re: How to Get Chart outside of FMP and into Graphic File?

                        Yes, both the chart and the container field are on the same layout, and it is the same layout I am on when I execute the script. 


                        Just to be sure I added a script step to go to that particular layout before executing the Set Field command.  Same result.

                        • 10. Re: How to Get Chart outside of FMP and into Graphic File?

                          Well, something else is going on. See the sample file I posted.

                          • 11. Re: How to Get Chart outside of FMP and into Graphic File?

                            OK, I tried your sample file and it works fine, so it doesn't seem to be anything with my system or the FMP version.  BTW, the main difference between your chart and mine is that I am using related records from another file, but I wouldn't think that should affect the ability to transfer the chart contents to a container.


                            To test my system some more, I went ahead and created a brand new data file with just the year, the container and the chart. I set up a relationship between the Year and another data file which already has the minute distribution data and also set up the chart to container script.  The script runs fine on this new data file, so the problem is not the chart itself.

                            It seems to be something peculiar to the data file that I am using.  I should note that that this file that I was running my script on has literally been used, modified and updated since the mid-90's so it is huge and I'm sure has a lot of crud built up on it. 

                            So currently it seems that for whatever reason it doesn't work on the original data file, but I can use a workaround to use this alternative new data file instead in order to generate the charts and run the scripts from there.

                            Thanks a lot for your help.