AW: Export via Scripting Bridge / Modifying the selection of OmniGraffeDocument programatically

<[email protected]>
Newsgroups gmane.comp.graphics.omnigraffle.user
Message-ID <[email protected]>
Hi all,

This little Applescript works in OG4. Should be also work in OG5.

set sf to POSIX path of (choose folder)
tell application "OmniGraffle Professional 4"
	set fd to front document
	-- Save Document first. Otherwise we get unexpected Results
	if not (exists fd's path) then return display dialog "Please save document before running this script..."
	set current export settings's area type to selected graphics
	set current export settings's draws background to false
	set current export settings's export scale to 1
	set current export settings's include border to false
	set current export settings's resolution to 1.0
	set xx to selection of front window
	repeat with i from 1 to xx's length
		set selection of front window to {xx's item i}
		save front document as "png" in POSIX file (sf & i & ".png")
	end repeat
	set selection of front window to xx
end tell
Best Regards
Christian Sodl

-----Ursprüngliche Nachricht-----
Von: [email protected] im Auftrag von Tobias Wigger
Gesendet: Mi 08.10.2008 16:09
An: [email protected]
Betreff: Export via Scripting Bridge / Modifying the selection of OmniGraffeDocument programatically
 
Hi all,

Using the Scripting Bridge in 10.5 and OmniGraffle 5 Pro I'd like to do the
following:
I'd like to export the individual parts of a user-selected Illustration
within a Document. The Illustration should not be exported as one entity (I
got this working already), but as individual images. The reason for this is
that I plan to use the individual parts for animation purposes in PowerPoint
2008 / Keynote 08. The Problem now is the following:
The export using the Document works:

self.selectedItems = self.selectedOmniGraffleWindow.selection;
NSString *tempDirectory = [openPanel directory];
NSLog(@"Chosen directory: %@",tempDirectory);
for (int i=0; i< [self.selectedItems count]; i++)
{
    OmniGraffleGraphic *item = [self.selectedItems objectAtIndex:i];
    NSString *fileName = [NSString stringWithFormat:@"/%d",i];
    NSString *finalDirectory = [tempDirectory
                   
stringByAppendingString:fileName];
    NSURL *exportDirectory = [NSURL URLWithString:finalDirectory];
    [currentDocument saveAs:@"png" in:exportDirectory];
          // This does work - It just exports the whole selection!
}


However, If I replace the call to currentDocument with item, as it was
originally intended to iterate over the different graphics in the selection,

[item saveAs:@"png" in:exportDirectory];

it fails with an exception.

My questions:

1. Is it mandatory to use the OmniGraffleDocument class to export items?

The AppleScripts regarding export I've seen so far seem to indicate that.
However, in the generated header file used by the Scripting Bridge
(generated using the sdef command in Terminal), both OmniGraffleDocument and
OmniGraffleGraphic inherit  from OmniGraffleItem, which supplies the saveAs:
in: method. 

2. If it is mandatory to use OmniGraffleDocument, is it somehow possible to
modify the selection of the Document?
With that, I also would get the desired effect of iterating over the Array
of selections and exporting the items one by one.

I appreciate any comments!

Thx in advance!

Toby


_______________________________________________
OmniGraffle-Users mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/omnigraffle-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.