exporting images to powerpoint using ironpython

Hi! I'm working on exporting visualizations from Spotfire to a ppt file using Ironpython. I used the following script and it's actually working. Although I'm trying to export those images to an existing ppt template and in reserved image fields. I hope you can help me do the necessary modifications on my script. Thanks!
from System.Drawing import Bitmap, Graphics, Rectangle, Point
from Spotfire.Dxp.Application.Visuals import VisualContent
from System.IO import Path

import clr
clr.AddReference("Microsoft.Office.Interop.PowerPoint")
import Microsoft.Office.Interop.PowerPoint as PowerPoint

####################
# Powerpoint setup
powerpoint = PowerPoint.ApplicationClass()
powerpoint.Visible = True
pres=powerpoint.Presentations.Add()
slideCounter = 1

####################
# image properties obtained from properties entries (can be hard coded)
width = int(Document.Properties["myWidth"])
height = int(Document.Properties["myHeight"])

##################
# obtain_image() - takes in 1 parameter (visualization handle)
def obtain_image(viz):

#file = "c:\\tmp\\test.jpg" # 'tmp' directory needs to exist
file = Path.GetTempFileName()

# obtain image
vc = viz.As[VisualContent]()

bm = Bitmap(width, height)
g = Graphics.FromImage(bm)
r = Rectangle(Point(0,0), bm.Size)
vc.Render(g, r)

bm.Save(file)
addToSlide(file)

###################
# addToSlide - takes 1 parameter (filename)
def addToSlide(file):
global slideCounter
#pp setup
slide=pres.Slides.Add(slideCounter, PowerPoint.PpSlideLayout.ppLayoutBlank)
slideCounter = slideCounter+1
slide.Shapes.AddPicture((file), False, True, Left=0, Top=10, Width=-1, Height=-1)

##################
# main part of program

for page in Document.Pages:
print page.Title
for visual in page.Visuals:
if (visual.TypeId.ToString().find("Html") < 0):
print "\t",visual.Title,": ", visual.TypeId.ToString()
obtain_image(visual)

(1) Answer

Login