ShowDialog()if result==result.

Script to export all bar charts, combination chart, maps etc to powerpoint

import clr
from System import *
from System.IO import *
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import FolderBrowserDialog,MessageBox
from Spotfire.Dxp.Application import Visual
from Spotfire.Dxp.Application.Visuals import *
from System.Drawing import Bitmap, Graphics, Rectangle, Point
from System.IO import Path
from Spotfire.Dxp.Application.Visuals import VisualContent
clr.AddReference("Microsoft.Office.Interop.PowerPoint")
import Microsoft.Office.Interop.PowerPoint as PowerPoint

filename=""
folder=FolderBrowserDialog()
result=folder.ShowDialog()
if result==result.OK:
 filename=folder.SelectedPath
else:
 MessageBox.Show("Please select a folder and try again")

w=800
h=600
bm = Bitmap(w,h)
g = Graphics.FromImage(bm)
r = Rectangle(Point(0,0), bm.Size)

for d in Document.Pages:
 Document.ActivePageReference=d
 for visual in Document.ActivePageReference.Visuals:
 if visual.TypeId==VisualTypeIdentifiers.BarChart or visual.TypeId==VisualTypeIdentifiers.CombinationChart or visual.TypeId==VisualTypeIdentifiers.PieChart or visual.TypeId==VisualTypeIdentifiers.MapChart:
 rt=visual.As[VisualContent]()
 rt.Legend.Visible=False
 charttitle= rt.Title
 charttitle=charttitle.replace("/","")
 tb=visual.As[VisualContent]().Render(g,r)
 tempFilename = filename + "\\" + charttitle + ".jpeg"
 bm.Save(tempFilename)

files=Directory.GetFiles(filename)
powerpoint = PowerPoint.ApplicationClass()
powerpoint.Visible = True
pres=powerpoint.Presentations.Add()

for f in files:
 slide=pres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
 slide.Shapes.AddPicture(f, False, True, 100, 100, 600, 400)
 title=slide.Shapes.Title
 txt=slide.Shapes.AddTextBox(1,10,500,500,100)
 txt.TextFrame.TextRange.Text="Enter Comments here.............."
 #title2.Top=.3
 title.Top=0.1
 obj=slide.Shapes.Title.TextFrame.TextRange
 f=f.split("\\")
 f=f.pop()
 f=f.replace(".jpeg","")
 obj.Text=f
 obj.Font.Size=32

for d in Document.Pages:
 Document.ActivePageReference=d
 for visual in Document.ActivePageReference.Visuals:
 if visual.TypeId==VisualTypeIdentifiers.BarChart or visual.TypeId==VisualTypeIdentifiers.CombinationChart or visual.TypeId==VisualTypeIdentifiers.PieChart or visual.TypeId==VisualTypeIdentifiers.MapChart:
 rt=visual.As[VisualContent]()
 rt.Legend.Visible=True

(3) Answers

Login