Hi,
I do run the script from the script editor, then you will get the errors created by the script.
I pasted your script in adefault report of Analyst, and then executed it from the Script editor, and just corrected the few errors I got.
Below is the script I got working, saving to my desktop, and adding the script parameter 'visual' pointing to one of the visualizations.
BR, Per K
import System
import clr
clr.AddReference("System.Windows.Forms")
from System import *
from System.IO import *
from System.Drawing import Bitmap, Rectangle
from System.Drawing import Graphics, Image
from Spotfire.Dxp.Framework.ApplicationModel import ApplicationThread
from System.IO import Path
from System.Windows.Forms import FolderBrowserDialog,MessageBox
#Choose Folder to save visualization
filename=""
folder=FolderBrowserDialog()
result=folder.ShowDialog()
if result==result.OK:
filename=folder.SelectedPath
else:
MessageBox.Show("Please select a folder and try again")
app = Application.GetService(ApplicationThread)
image = Bitmap(800, 600)
def f(visual, document, app, image, Graphics, Rectangle):
try:
vis = visual
gfx = Graphics.FromImage(image)
rect = Rectangle(0,0,image.Width,image.Height)
vis.Render(gfx, Rectangle(0,0,image.Width,image.Height))
imageFilename = filename + "image.png"
except:
return
# DO SOMETHING WITH THE IMAGE HERE
image.Save(imageFilename)
app.InvokeAsynchronously(f(visual, Document, app, image, Graphics, Rectangle))