in OmniGraffle Inhaltsverzeichnis per Script generieren lassen?!?

unique23

Aktives Mitglied
Thread Starter
Dabei seit
03.03.2004
Beiträge
759
Reaktionspunkte
2
Hallo zusammen,

ich suche ein Möglichkeit um in OmniGraffle ein Inhaltsverzeichnis automatisch zu erstellen. Ideal wäre es, wenn das Script den Namen der Arbeitsfläche und die dazugehörige Seitenzahl auf einer Seite ausgibt, eine nach der anderen...

Gibt es dazu eine Möglichkeit diese Automatisierung durchzuführen?
Ich bin schon ordentlich am Suchen im Web, aber habe noch nichts dafür gefunden. Weiß jemand eine Möglichkeit, wie man so ein Skript erstellt?

Unendlicher Ruhm sei gewährt, da bin ich mir sicher...

Besten Dank,
unique
 
nächstes Canvas in OmniGraffle auswählem

Hallo zusammen,

ich bin immer noch dabei, ein Imhaltsverzeichnis in OmniGraffle per Skript zu generieren. Ich schaffe es die aktuell ausgewählte Arbeitsfläche mit Namen und Seitenzahl in einem Dialogfenster anzeigne zu lassen.


Mein bisheriger Code sieht wie folgt aus:
Code:
tell application "OmniGraffle Professional 5"
	tell (canvas of front window) 
		set pageTitle to name
		set pageNumber to id
		display dialog pageTitle & " " & pageNumber buttons {"OK"}
	end tell
end tell

Mir ist allerdings nicht klar, wie ich die aktuelle Seitenzahl erhöhen könnte. Ich finde keine Methode dazu... :confused:
So dass ich eine Schleife durchlaufen lassen könnte, die den Seitentitel und Seitennummer in einem Array abspeichert. Und diese Daten aus den Arrays werden dann wieder in einem Text ausgegen auf einer bestimmten Seite.

Aber die Sache steht und fällt mit der Möglichkeit die Seiten alle von der ersten bis zur letzten "durch-zuloopen"

Kann mir jemand einen Tipp geben?
Besten Dank im voraus… und ein schönes Osterfest!
 
Ich hab dir mal auf die Schnelle was gebastelt:

Code:
-- Date:   April 1st, 2010
-- author: Micha Grandel, talk@michagrandel.de

set graffleCanvases to {}
tell application "OmniGraffle Professional 5"
	set docCanvases to canvases of document of first window
	repeat with currentCanvas in docCanvases
		set currentCanvas to {name of currentCanvas, id of currentCanvas}
		copy currentCanvas to the end of graffleCanvases
	end repeat
end tell

-- now 'graffleCanvases' includes all canvases 
-- of the Omnigraffle Document of the first window,
-- e.g.
--		{ {"Canvas 1", 1}, {"Canvas 2", 2}, ... }
--
-- have fun!
 
@Kümmelkorn

Vielen Dank für dein Skript!!! :)

Wenn ich das Skript jetzt ausführe werden nach und nach alle Seitennamen und Seitenzahlen in currentCanvas gespeichert und das dann an die letzte Stelle von graffleCanvases gespeichert. Damit dürfte graffleCanvases ein multi-/zwei-dimensionales Array sein. Soweit habe ich das verstanden…

Zwei Fragen bleiben mir aber noch für das Inhaltsverzeichnis offen:
1. Wie bekomme ich die Seitennamen und Zahlen von dem Array in ein Textfeld auf eine bestimmte Seite, z.b. Seite 2?

2. Woher hast du die Begriffe wie "currentCanvas"? In der Funktinsübersicht konnte ich das nicht finden:confused:


Besten Dank für dein bisheriges Skript und schöne Grüße
 
zu 2. Das sind Namen von Variablen. Du könntest die auch "hans" und "franz" nennen.

Besser ist es aber, Namen zu verwenden, die etwas über den Inhalt der Variablen aussagen.
 
okay, alles klar.
Ich dachte nur, dass das ein bestehendes Element ist, da zuerst die Repeat Schleife definiert wird mit currentCanvas udn später darauf zugegriffen wird...

Ich hab ein Shape automatisch generiert, aber leider kann ich in diesem Shape nicht die Elemente aus dem graffleCanvases Array auslesen und anzeigne lassen :confused:

Mittlerweile sieht mein Skript wie folgt aus:
Code:
set graffleCanvases to {}
tell application "OmniGraffle Professional 5"
	set docCanvases to canvases of document of first window
	repeat with currentCanvas in docCanvases
		set currentCanvas to {name of currentCanvas, id of currentCanvas}
		copy currentCanvas to the end of graffleCanvases
	end repeat
	get graffleCanvases
	
	tell canvas of front window
		make new shape at end of graphics with properties {size:{200, 200}, origin:{100, 50}, text:{text:"graffleCanvases", font:"Helvetica", size:18, alignment:left}}
	end tell
	
end tell

Hat jemand eine Idee?
 
Ich hab es soweit fertig.

Die Funktion für die Seitenzahlen musste ich nochmal ändern, da die Seitenzahl nicht mit der ID der Arbeitsfläche übereinstimmt. Ich hab jetzt vor Ostern keine Zeit mehr, die neue Funktion zu testen, sie sollte aber funktionieren.

Frohe Ostern,
Micha

Code:
-- 	Date:		April 2nd, 2010, version 0.2
-- 	author:		Micha Grandel, talk@michagrandel.de
-- 	Licence:		Creative Commons 3.0 by-sa
--			
--	LICENCE / LIZENZ
--
-- ENGLISH COPYRIGHT NOTE: (FOR THE GERMAN VERSION, SEE BELOW) -----------------------------------------------
--
--	This source code is distributed under Creative Commons Licence 3.0 Attribution-Share Alike.
--	This means, you are free to:
--
--		... Share — to copy, distribute and transmit the work
--		... Remix — to adapt the work
--
--	Under the following conditions:
--	
--		1)	Attribution
--			You must attribute the work in the following manner (but not in any way that suggests that 
--			they endorse you or your use of the work):
--
--			For printed media:			author: Micha Grandel, www.michagrandel.de
--
--			For online media:			author: <a href="http://www.michagrandel.de">Micha Grandel</a>
--
--			For internet boards:		author: [URL=http://www.michagrandel.de]Micha Grandel[/URL]
--
--			For Twitter:				by @michagrandel, [url]http://is.gd/bb62j[/url]
--
--		2)	Share Alike
--			If you alter, transform, or build upon this work, you may distribute the resulting work 
--			only under the same, similar or a compatible license.
--			The author may give you a written permission to publish your adapted work under a licence
--			of the Free Software Foundation (like GNU Plublic Licence or BSD Licence). However, this 
--			happens only on request and you need to ask the author!
--
--		More information about this licence you will get on [url]http://creativecommons.org/licenses/by-sa/3.0/[/url] 
--
-- END OF ENGLISH COPYRIGHT NOTE ------------------------------------------------------------------------------------------
--
--
--
--
-- GERMAN COPYRIGHT NOTE: ----------------------------------------------------------------------------------------------------
--
--	Dieser Quellcode unterliegt der Creative Commons Licence 3.0 Attribution-Share Alike.
--	Das bedeutet, Sie dürfen:
--
--		... das Werk bzw. den Inhalt vervielfältigen, verbreiten und öffentlich zugänglich machen
--		... Abwandlungen und Bearbeitungen des Werkes bzw. Inhaltes anfertigen
--
--	unter den folgenden Bedingungen:
--	
--		1)	Namensnennung:
--			Sie müssen den Namen des Autors/Rechteinhabers in der folgenden Weise nennen:
--			
--			Für gedruckte Publikation:		Autor: Micha Grandel, [url]www.michagrandel.de[/url]
--			
--			Für Online Publikation:			Autor: <a href="http://www.michagrandel.de">Micha Grandel</a>
--			
--			Für Publikation in Foren:		Autor: [URL=http://www.michagrandel.de]Micha Grandel[/URL]
--			
--			Für Publikation in Twitter:		von @michagrandel, [url]http://is.gd/bb62j[/url]
--		
--		2) 	Weitergabe unter gleichen Bedingungen
--			Wenn Sie das lizenzierte Werk bzw. den lizenzierten Inhalt bearbeiten oder in anderer Weise
--			erkennbar als Grundlage für eigenes Schaffen verwenden, dürfen Sie die daraufhin neu 
--			entstandenen Werke bzw. Inhalte nur unter Verwendung von Lizenzbedingungen weitergeben,
--			die mit denen dieses Lizenzvertrages identisch oder vergleichbar sind.
--			Bei Bedarf kann dazu - nach Absprache und ausdrücklicher Erlaubnis des Autors/Rechteinhabers -
--			auch eine Lizenz der Free Software Foundation gehören, z.B. die GNU Public Licence oder
--			die BSD Lizenz.
--
--		Mehr Informationen zur Lizenz bekommen Sie auf [url]http://creativecommons.org/licenses/by-sa/3.0/de/[/url]
--
-- END OF GERMAN COPYRIGHT NOTE ----------------------------------------------------------------------------------------------
--
-- 	Changelog
--
-- 	version		change
-- 	0.2			Adds a canvas to the document and creates a table of contents on it. 
--				The canvas can be choosen by using the tableOfContents property in the beginning
--				of the script and is set to page 2 by default.
-- 	0.1			Saves all canvases of the document in a two-dimensional list
--
-- and now... have fun!

on run
	set tableOfContents to {page:2, name:"Table of Contents"}
	
	tell application "OmniGraffle Professional 5" to set graffleDocument to document of first window
	set graffleCanvases to graffleCanvasesOf(graffleDocument)
	addGraffleCanvasAt((page of tableOfContents), graffleDocument)
	tell application "OmniGraffle Professional 5"
		set name of canvas (page of tableOfContents) of graffleDocument to name of tableOfContents
		tell canvas (page of tableOfContents) of graffleDocument
			
			set sizeOfPageTitle to {400, 40}
			set sizeOfCanvasTitle to {300, 20}
			set sizeOfPageNumber to {100, 20}
			set currentRepeat to 0
			
			set startPoint to {(x of page size) / 2 - (item 1 of sizeOfPageTitle) / 2, 30}
			
			make new shape at end of graphics with properties {size:sizeOfPageTitle, origin:startPoint, text:{text:"Table of Contents", font:"Helvetica", size:18, alignment:left}}
			
			repeat with currentCanvas in graffleCanvases
				set currentPageNumber to item 1 of currentCanvas
				make new shape at end of graphics with properties {size:sizeOfCanvasTitle, origin:{item 1 of startPoint, ((item 2 of startPoint) + 50) + currentRepeat * 30}, text:{text:item 2 of currentCanvas, font:"Helvetica", size:12, alignment:left}}
				make new shape at end of graphics with properties {size:sizeOfPageNumber, origin:{(item 1 of startPoint) + (item 1 of sizeOfCanvasTitle), ((item 2 of startPoint) + 50) + currentRepeat * 30}, text:{text:item 1 of currentCanvas as text, font:"Helvetica", size:12, alignment:right}}
				set currentRepeat to currentRepeat + 1
			end repeat
		end tell
	end tell
end run

--
-- addGraffleCanvasAt(positon, graffleDocument)
--
-- adds a canvas at <position> to the graffleDocument 
--
-- @param position			the position of the canvas to add. 
--							allowed values are numbers greater than 0, "1st", "first", "begin", "start", 
--							"beginning", "end" and "last"
-- @param graffleDocument		the canvases of THIS document will be return
-- @return graffleCanvases		a list of all canvases of this document, including id and name, 
--								syntax: {{id, name}, {id, name}, ... }
--
-- @version 	1.0 (April 2, 2010)
-- @author 	Micha Grandel, [email]talk@michagrandel.de[/email]
--

on addGraffleCanvasAt(position, graffleDocument)
	tell application "OmniGraffle Professional 5"
		if (position is "first" or position = "start" or position is "beginning" or position is "begin" or position is "1st" or position is 1) then
			tell graffleDocument to make new canvas at beginning of canvases
			
		else if (position is "last" or position is "end" or position is -1) then
			tell graffleDocument to make new canvas at end of canvases
			
		else
			tell graffleDocument
				try
					set countOfCanvases to count of canvas
					repeat with counter from position to countOfCanvases
						if (counter is position) then
							make new canvas
						end if
						set cName to name of canvas position
						copy canvas position to the end of canvases
						delete canvas position
						set name of last canvas to cName
					end repeat
				on error
					get canvases
				end try
			end tell
		end if
	end tell
end addGraffleCanvasAt


--
-- graffleCanvasesOf(graffleDocument)
--
-- returns all canvases of graffleDocuemnt
--
-- @param graffleDocument	the canvases of THIS document will be return
-- @return graffleCanvases	a list of all canvases of this document, including id and name, 
--							syntax: {{id, name}, {id, name}, ... }
--
-- @version 1.0 (April 2, 2010)
-- @author 	Micha Grandel, [email]talk@michagrandel.de[/email]
--

on graffleCanvasesOf(graffleDocument)
	set graffleCanvases to {}
	tell application "OmniGraffle Professional 5"
		set docCanvases to canvases of graffleDocument
		set currentPageNumber to 1
		repeat with currentCanvas in docCanvases
			set currentCanvas to {currentPageNumber, name of currentCanvas}
			copy currentCanvas to the end of graffleCanvases
			set currentPageNumber to currentPageNumber + 1
		end repeat
	end tell
	set return to graffleCanvases
end graffleCanvasesOf
 
Vielen Dank Micha,

ich hab dein Skript gleich mal getestet. Ist wirklich der Wahnsinn was du für ine langes Skript geschrieben hast. Vielen Dank nochmals!
Bis auf eine Kleinigkeit funktioniert das Skipt auch tadellos:
Und zwar wird die Seite, due für das Inhaltsverzeichnis eingefügt wird, nicht mit berücksichtigt. Das heißt die Zahlen der Seiten sind korrekt, wenn ich das Inhaltsverzeichnis kopiere und auf eine bereits bestehende Seite kopiere, die schon vor dem Ausführen des Skriptes existiert hat.

Ich denke nur, das bei sehr großen Dokumenten problematisch werden kann, wenn das Inhaltsverzeichnis nicht mehr auf eine Seite passt...
Kann man denn auch das gesamte Inhaltsverzeichnis in einem einzelnen Textfeld erstellen lassen?

Zum dritten mal nochmals vielen Dank und eine wunderschöne Osterzeit!
unique
 
Zurück
Oben Unten