placing figures in the powerpoint slides from a given folder

Hi,

We are trying to place the picture in to the powerpoint slides.

What I want is we have an image folder in the desktop folder, say for example, PICTURES. This folder contains many images. I need a script to get the pictures from PICTURE folder one by one and place in the power point slide layout.

The power point slide layout used for this placement should be “Text & Picrture”. So the pictures should be inserted in the picture frame of this slide.

Could any one help me on this?

And also please suggest how to copy a table that is present in the word document into a power point slide.

Thanks,
Gopal

Hey y’all;

I have been trying to write an Applescript to do basically the same thing, and I’ve come up with the following (not a functional script, it’s my subroutine for interacting with PowerPoint):


on DoSlide(TheTitle)
	set TheTemplate to "[i]Drive[/i]:[i]Folder[/i]:[i]PPPresentation.pptx[/i]" as alias
	tell application "Microsoft PowerPoint"
		launch
		activate
		open TheTemplate
		set TheNewSlide to make new slide at the end of active presentation with properties {layout:slide layout custom}
		set content of text range of text frame of place holder 1 of TheNewSlide to TheTitle
		paste object view of document window 1
                set top of shape 2 of TheNewSlide to 100
	end tell
end DoSlide

This routine gets passed the title I want to use for the slide, and I have another section of the script that tells Photoshop to open images, resize them, select all, and copy the image to the clipboard. The presentation specified in the variable TheTemplate already exists, and the variable is set to an alias of the text of the path to the existing presentation. This presentation simply has one placeholder, a title placeholder, and this is where the title is inserted.

On a couple of occasions, I have gotten this script to run successfully. HOWEVER, after inserting the last line (set top of shape 2 . . .), and even if I delete it and recompile, the paste object command SIMPLY WILL NOT WORK. The script runs, there is no error, but PowerPoint won’t paste my picture from the clipboard to the slide. This script (sans the set top of shape 2 . . . line, and once even with a similar line in place when I was testing how to refer to the pasted in picture) runs just fine, it inserts text into the title box . . . but it WILL NOT paste in my picture. It is driving me absolutely crazy, there is no problem per se with the code, it’s accepted by PP and Applescript as valid and it runs without error, but it doesn’t result in a paste event.

I’ve tried rebooting, reframbulating by dingus, even transferring the files to a second Mac and trying it on that one. Nothing helps.

So, my conclusion is: Dump PowerPoint 2008 and use a presentation program which has a functional paste command.

Richard

Model: 2.66 GHz Dual-Core Xeon, recent iMac
AppleScript: 2.2
Browser: Firefox 2.0.0.12
Operating System: Mac OS X (10.5)

Hi,

Are you able to do it manually, if yes then you can do it. If no then you have first look for the best manual way then only you can do it through script.

There are several ways to put a picture into a PP slide, but I have not been able to find a way to put one into a place holder. I think that’s the command that is being asked for in the first post. So far all my tries have failed in syntax.

I myself am trying to avoid having to refer to files (which saves me having to save my files after Photoshop resizes them), and it looks like the only way to access the clipboard is via the paste object command, which, as I’ve said, is not dependable in PP 2008. It’s absolutely infuriating to know that you have the right syntax, to be able to manually paste the picture in after the script has run (so it’s not like PP can’t paste that particular type of image into that particular view/document). My script is complete and functional save for the failure of the paste object command.

Sigh. I think I’ll now have to try the file-based commands, as my institution is stubbornly refusing to allow me to use an alternative to PP. I hate the extra time that the additional save step will require, as I have thousands of images I need to process. Once more Microsoft contributes to my productivity!

Cheers,

R

Hi,

You all guy is doing greate job, this something interesting, but I am not with my Mac. Otherwise the requirement is really interesting.

I am putting my view, just ask user to browse the art folder and get a count of all the arts, start a repeat command to copy & paste in a separate slide. Please make a not that you have to increase the slide number also.

If you want any code enhancement, you can post your code here, then only I can modify it.

Regards.

Fixed my problem, but only at the expense of setting up a script that places files from a folder into a PP slide. It creates a new rectangular shape the same size as the images (in pixels at 72 dpi), and then uses the user picture command to fill the shape with the picture. Note that the PP 2004 Applescript Guide has it WRONG: the syntax of the user picture command is:


user picture of PicShape picture file PathToPic

NOT:


user picture fill of PicShape picture file PathToPic

I screwed around with this FOREVER before thinking, “Hey, maybe the fill needs to go,” since the syntax of the command is user picture shape/fill format. Nothing like going to the reference document and finding THE WRONG INFORMATION in it. If Apple’s Keynote program was even vaguely scriptable (and I must say my feelings about Apple’s iWork went down severely upon finding that it isn’t particularly scriptable), I’d dump Microsoft products in an instant. Finding the wrong information in the PP Applescript Guide after having the whole paste object fiasco (see above) was like a last kick in the teeth.

But here is a functional script. It is designed to do a specific task for me, namely to take folders dropped on the application script, search through them for files with “jpg” as a file extension inside a folder called “Montages”, and then pipes the pics that fit those criteria to the “DoSlide()” subroutine where they are added into new slides (which have my custom layout consisting of a blank slide with a single title place holder). This routine pastes the folder hierarchy (dumped folder – first subfolder – second subfolder – etc.) in the title, creates a rectangular shape the size of my images, and then uses user picture to fill the shape with the picture.

If you use it, you’ll want to generalize it a bit so that you don’t need to put your pics into a folder called “Montages”. Unfortunately, using the user picture command REQUIRES a shape of the exact size of the image to be pasted, or you get scaling of your pic to fit the shape. If all your images are all the same size, you can set the values of the auto shape properties to fit them. NOTE: the values of the width and height properties of auto shape are pixels at 72 dpi. Therefore, if you paste in an image that is 7 x 8.273 inches at 150 dpi (equal to 1050 x 1241 pixels), you want to set your values to those I use, namely 504 width and 596 height, which are derived from 7 x 72 = 504 and 7 x 8.273 = 596 pixels. As far as I can tell, PP ignores the resolution of your picture and only cares about the dimensions, and changes your image to be 72 dpi at those dimensions. If it’s not right, it will stretch or shrink your image to fit the dimensions of the auto shape.

Hope this helps.

Cheers,

Richard


on open FolderList
	set ListOfFolders to every item of FolderList
	repeat with i from 1 to (the number of items in ListOfFolders)
		set CurrentFolder to item i of ListOfFolders as alias
		set CurrFolInfo to info for CurrentFolder
		if folder of CurrFolInfo is true then
			set FolderName to the name of CurrFolInfo
			ProcessFolder(CurrentFolder, FolderName)
		end if
	end repeat
end open

on ProcessFolder(TheFolder, TheFolderName)
	set TheFolderItems to list folder TheFolder without invisibles
	repeat with i from 1 to the count of TheFolderItems
		set TheItem to alias ((TheFolder as text) & (item i of TheFolderItems) & ":")
		set TheItemInfo to info for TheItem
		if folder of TheItemInfo is true then
			if the name of TheItemInfo is "Montages" then
				DoPowerPoint(TheItem, TheFolderName)
			else
				set NewFolderName to (TheFolderName & " -- " & (the name of TheItemInfo)) as text
				ProcessFolder(TheItem, NewFolderName)
			end if
		end if
	end repeat
end ProcessFolder

on DoPowerPoint(MontageFolder, ThisFolderName)
	set MontageFolderItems to list folder MontageFolder without invisibles
	repeat with i from 1 to the count of MontageFolderItems
		set ThisItemName to ""
		set ThisItem to alias ((MontageFolder as text) & (item i of MontageFolderItems))
		set ThisItemInfo to info for ThisItem
		if the name extension of ThisItemInfo is "jpg" then
			set ThisItemName to the name of ThisItemInfo
			set NumChars to the number of characters in ThisItemName
			set ThisItemName to text 1 thru (NumChars - 4) of ThisItemName
			set TitleText to ThisFolderName as text
			DoSlide(ThisItem, TitleText)
		end if
	end repeat
end DoPowerPoint

on DoSlide(SlideItem, TheTitle)
	set TheTemplate to "RESRansom:New Microscopy:MicroImages.pptx" as alias
	set PathToPic to SlideItem as text
	tell application "Microsoft PowerPoint"
		launch
		activate
		open TheTemplate
		set TheNewSlide to make new slide at the end of active presentation with properties {layout:slide layout custom}
		set content of text range of text frame of place holder 1 of TheNewSlide to TheTitle
		set PicShape to make new shape at the end of TheNewSlide with properties {auto shape type:autoshape rectangle, left position:18, top:100, width:504, height:596}
		user picture of PicShape picture file PathToPic
	end tell
end DoSlide

Ooops, I noticed that I had left in a bit of code from a previous iteration of the script. I get the name sans the extension of the files in the code:


			set ThisItemName to the name of ThisItemInfo
			set NumChars to the number of characters in ThisItemName
			set ThisItemName to text 1 thru (NumChars - 4) of ThisItemName
			set TitleText to ThisFolderName as text


but I decide later not to use it, and forgot to clip out these lines. You can keep them and use them if you want to pass the DoSlide() subroutine the name of the picture file instead of the folder hierarchy, otherwise they’re useless.

Cheers,

R

Using rransom’s script I was able to put together something useful. Although it admittedly does not address the text title issue, it may push this project forward a step further.

It takes a list of POSIX paths of images and inserts them into slides and centers them with aspect ratios intact.

I made an Automator Action to do this.
http://ul.to/7x7w26r6


set input to {"Users/USERNAME/Desktop/Pic1.jpg", "/Users/USERNAME/Pictures/IMG_0005.JPG"}
property menuSelection : 0

set slideWidth to 720
set slideHeight to 540

set inputLS to input as list
set inputList to {}
tell application "Finder"
	repeat with itemStep from 1 to (count of inputLS)
		set itemPX to quoted form of item itemStep of inputLS
		set inputItemALIAS to (POSIX file (item itemStep of inputLS) as alias)
		set end of inputList to file inputItemALIAS
		log inputItemALIAS
	end repeat
end tell


tell application "Microsoft PowerPoint"
	activate
	if (count of presentations) is 0 then
		make new presentation
	end if
	if (count of presentations) is greater than 0 then
		tell active presentation
			if (count of slides) is 0 then
				--make new slide at beginning with properties {layout:slide layout blank}
			end if
			repeat with xName in inputList
				tell application "Image Events"
					launch
					set my_image to open xName as alias
					set my_dimensions to dimensions of my_image
					close my_image
					set orig_x to item 1 of my_dimensions as integer
					log orig_x
					set orig_y to item 2 of my_dimensions as integer
					log orig_y
					quit
				end tell
				
				set widthPercentReduction to (720 / orig_x)
				set heighPercentReduction to (400 / orig_y)
				
				set new_x to orig_x * widthPercentReduction
				set new_y to orig_y * widthPercentReduction
				set topDistance to (slideHeight - (new_y)) * 0.5
				set leftDistance to (slideWidth - (new_x)) * 0.5
				
				if menuSelection is 0 then
					set the TheNewSlide to make new slide at end with properties {layout:slide layout blank}
					set PicShape to make new shape at the end of TheNewSlide with properties {auto shape type:autoshape rectangle, left position:leftDistance, top:topDistance, width:new_x, height:new_y}
					user picture of PicShape picture file (xName as text)
				end if
				if menuSelection is 1 then
					set the TheNewSlide to make new slide at beginning with properties {layout:slide layout blank}
					set PicShape to make new shape at the beginning of TheNewSlide with properties {auto shape type:autoshape rectangle, left position:0, top:topDistance, width:new_x, height:new_y}
					user picture of PicShape picture file (xName as text)
				end if
			end repeat
		end tell
	end if
end tell