Andrew Andrew - 3 months ago 45
Python Question

Spotfire Export Automatically

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)

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.


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

window.onload = function callButtonClickEvent(){

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.