1

I'm not at all sure that what I need is possible with the tools that I have, but I thought I'd ask.

I have the following Python script (technically IronPython, but I don't fully understand the difference), that I pulled from a blog and modified for my purposes:

import datetime
from System.IO import StreamWriter
from Spotfire.Dxp.Application.Visuals import TablePlot

tempFolder = "C:\\Spotfire Exports\\"
tempFilename = "Data.txt"

writer = StreamWriter(tempFolder + tempFilename)
vTable.As[TablePlot]().ExportText(writer)

print tempFolder + tempFilename

The script itself works perfectly fine, but the problem is that I need to be able to make this run automatically at a certain time of day, i.e., I need the *.txt file to be updated in the morning before I get to my desk. (The project pulls from a database that isn't accessible through MS Access.)

Although the script runs fine, I have to manually push the button to activate it. I can't seem to find any way to have the script run on file open (so that I can use Windows Task Scheduler) to make it run when the file is opened.

Does anybody know if there's a way to do this?

Bear in mind, I do not have Visual Studio available to me. I already tried Visual Studio Express, and it doesn't seem to be able to access the Spotfire SDK macros.

1 Answers1

1

You can utilize JavaScript to click a button on load and have that button be your python script. Like so:

window.onload = function callButtonClickEvent(){
          document.getElementById('YOUR_SPOTFIRE_CONTROL_ID').click();
}

By clicking "edit HTML" in the text box you're using you can see the ID spotfire has assigned your button. The above code will click that button once upon loading.

If you do not want your button to be shown to end users (if applicable) then you can put it inside a hidden div or span:

<span style='display:none'><SpotfireControl id="YOUR_SPOTFIRE_CONTROL_ID" /></span>

Then once this is setup it should run your script when opened as per your windows task scheduler as you desired.

Let me know if you have any questions regarding implementation.

clesiemo3
  • 1,099
  • 6
  • 17
  • Well, I don't have any experience with JavaScript, and I can't seem to find any straightforward explanation online for putting implementing JavaScript in a Spotfire page. So far, I was able to click the add JS button in the HTML edit page and copy-paste the javascript (replacing the control id text with the number), but I don't know where to go from there. –  May 05 '15 at 21:34
  • From there, in order to test it's working you can save and close your Spotfire analysis, open it fresh, and check that the file was created (aka the script successfully executed without you pressing a button). In my example I set up on my local machine i have it change the global property "display" to "after" with the starting value of "before". Upon opening my spotfire i see that it is set to "after" despite being set to "before" when i saved and closed. After, you can work towards automation with task scheduling: https://docs.tibco.com/products/tibco-spotfire-automation-services-7-0-0 – clesiemo3 May 06 '15 at 20:57
  • @clesiemo3- Thanks for the solution. One quick question - can I run this script without opening the dxp file? – ksp585 Aug 10 '17 at 11:45