The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Automatically Diagram XML data? (http://forums.omnigroup.com/showthread.php?t=112)

loghound 2006-04-13 08:03 AM

Automatically Diagram XML data?
 
Hi All,

A friend just showed me Omnigraffle... Brilliant application!

I have a tool that creates a XML file that describes a web site layout . Is it possible to have Omnigraffle automatically create an outline view of it?

I have control over the XML format so if the formats describes somewhere I can make my output conform, or perhaps someone has written a clever applescript?



Thanks

-John

Greg Titus 2006-04-13 11:15 AM

The Graffle file format isn't very handy for anyone but us. (It is in XML, but it is just using Apple's property list DTD and is pretty grungy to read through.) One of the big things planned for version 5 is a real, good XML file format.

However, Graffle does import OmniOutliner files, which do use a very nice XML doc type. So if producing XML is easiest for you, outputting Outliner files and having Graffle open them might work best.

Alternatively, you may also want to look at the [URL="http://www.graphviz.org/"]graphviz format[/URL], which is especially simple to create, and is another format that OmniGraffle can import.

If you wanted to go into more detail about what your existing XML looks like, it might also make sense to write an AppleScript that reads the XML and builds the Graffle shapes from it as well.

loghound 2006-04-13 11:22 AM

[QUOTE=Greg Titus]The Graffle file format isn't very handy for anyone but us. (It is in XML, but it is just using Apple's property list DTD and is pretty grungy to read through.) One of the big things planned for version 5 is a real, good XML file format.

However, Graffle does import OmniOutliner files, which do use a very nice XML doc type. So if producing XML is easiest for you, outputting Outliner files and having Graffle open them might work best.

Alternatively, you may also want to look at the [URL="http://www.graphviz.org/"]graphviz format[/URL], which is especially simple to create, and is another format that OmniGraffle can import.

If you wanted to go into more detail about what your existing XML looks like, it might also make sense to write an AppleScript that reads the XML and builds the Graffle shapes from it as well.[/QUOTE]

Hi Greg,
Right now my app outputs google sitemap.xml file format

[url]https://www.google.com/webmasters/sitemaps/docs/en/overview.html[/url]

However like I said I would be happy to modify it to output a format that Graffle can import easier. The omni-outliner route sounds really good, is that documented somewhere or should I download a demo version and just look at it's output to figure it out?

The other idea I had was the applescript route but since I've never written applescript before I'm a little shy to go that route.

By the way, my app is a plugin for RapidWeaver that creates sitemaps ([url]http://loghound.com/Sitemap/index.php[/url]) and when my friend showed me the nifty auto-diagramming from outline freature in Graffle I thought 'Bingo' it would be really nice to throw your site into graffle for documentation purposes.

-John

Greg Titus 2006-04-13 11:28 AM

So what sort of layout are you looking for in Graffle? Hierarchical with the tree structure of the URLs?

Greg Titus 2006-04-13 11:51 AM

The sitemap.xml format is particularly simple. Here is a quick AppleScript that will create a box in Graffle for each URL in a <loc> tag. They aren't connected to each other or anything - that would be a bit more complicated - but I'd be happy to extend the script once you left me know what sort of structure you are interested in. (Just change the first property line to the Mac-style path of the sitemap file.)

[CODE]
property file_to_read : "Tiger:Users:toon:Documents:sitemap.xml"

tell application "OmniGraffle"
set fileID to open for access file file_to_read
set isDone to false
set startingY to 20.0
repeat until isDone
try
-- read up to a tag, and see what the tag is
read fileID before "<"
set theTag to read fileID before ">"

-- if it is a <loc> tag, then read the contents
if theTag is "loc" then
set theURL to read fileID before "<"

-- and make a box in Graffle with the URL as its title and also its link
tell canvas of front window
make new shape at end of graphics with properties {text:{alignment:left, text:theURL}, url:theURL, vertical padding:5, autosizing:full, side padding:10, origin:{100.0, startingY}}
end tell
set startingY to startingY + 30.0
end if
on error
set isDone to true
end try
end repeat

close access fileID
end tell
[/CODE]

JKT 2006-04-13 12:04 PM

Just to let you know, you can get free day long trial licences for all of Omni's apps that allow you to use the app without limits for that length of time (this allows you to try out the app to its fullest without hitting the limits of the demo versions, or to do that one off thing - such as use OmniOutliner as a bridge between your file formats).

When in the OmniStore, look for Trial licences.

Greg Titus 2006-04-14 12:56 PM

1 Attachment(s)
So here is the source to an AppleScript droplet that will parse these sitemap files, make a shape for each web page with the file name as its title and with the full URL as an action, and lay them out hierarchically left-to-right.

Just paste this into Script Editor, save it as an application, and then drop any number of sitemap XML files on it to make a new OmniGraffle document out of each.

phillipadsmith 2006-12-03 02:41 PM

Any reason that I can't download the attachment? Some kind of permissions thing?

mgriffith 2007-03-08 05:36 PM

Unable to download script
 
Like phillipadsmith, I can't download the script attached by Greg Titus - problem with the forum?

jeremybrown 2007-03-22 06:59 AM

Applescript
 
Since no one seems to be answeringI found the sitemap2graffle applescript at Loghound:[URL="http://loghound.com/Sitemap/index.php"]http://loghound.com/Sitemap/index.php[/URL]

However, their version barfs when it encounters a URL with a trailing slash (/). I added a statement to strip any trailing / off, and it seems to work fine. I've pasted the code below. (Copy and paste it into Script Editor.app, compile it, and save as an application.)

[CODE]on makeShape(aTitle, aURL)
tell application "OmniGraffle"
tell canvas of front window
return make new shape with properties {text:aTitle, url:aURL, vertical padding:5, autosizing:full, side padding:10, magnets:{{1, 0}, {-1, 0}, {-1, 1}, {-1, -1}}, origin:{(x of canvasSize) / 2.0, (y of canvasSize) / 2.0}}
end tell
end tell
end makeShape

on makeConnection(aSource, aDestination)
tell application "OmniGraffle"
tell aSource
set aLine to connect to aDestination with properties {line type:straight}
end tell
set tail magnet of aLine to 1
end tell
end makeConnection

on siteDiagram(aFile)
tell application "OmniGraffle"
make new document
tell layout info of canvas of front window
set type to left to right
set children to back to front ordering
end tell

set fileID to open for access aFile
set isDone to false
set siteLength to 0
set urlsRead to 0
repeat until isDone
try
-- read up to a tag, and see what the tag is
read fileID before "<"
set theTag to read fileID before ">"

-- if it is a <loc> tag, then read the contents
if theTag is "loc" then
set theURL to read fileID before "<"

-- added to handle URL with trailing /
if last character of theURL is "/" then
set theURL to (texts 1 thru ((length of theURL) - 1) of theURL)
end if

-- figure out the site and make a shape for it
if siteLength is 0 then
-- "http://" is 7 characters, which is why we start looking at 8 - we want the next slash
set siteLength to (offset of "/" in (texts 8 thru -1 of theURL)) + 7
set rootURL to texts 1 thru siteLength of theURL
set rootShape to my makeShape(rootURL, rootURL)
end if

-- now walk along the URL looking for more slashes and creating a folder shape for each one it finds, and connecting each to the previous folder

set remainingURL to texts (siteLength + 1) thru -1 of theURL


set doneLength to siteLength
set lastShape to rootShape
set moreToDo to true
repeat while moreToDo
set nextOffset to (offset of "/" in remainingURL)
if nextOffset is 0 then
set moreToDo to false
else
set doneLength to doneLength + nextOffset
set folderName to texts 1 thru (nextOffset - 1) of remainingURL
set folderURL to texts 1 thru doneLength of theURL
set matchingShapes to shapes of canvas of front window whose url is folderURL
if (count of matchingShapes) is 0 then
set folderShape to my makeShape(folderName, folderURL)
else
set folderShape to item 1 of matchingShapes
end if
my makeConnection(lastShape, folderShape)
set lastShape to folderShape
set remainingURL to texts (nextOffset + 1) thru -1 of remainingURL
end if
end repeat

-- finally, it this URL wasn't a folder (or site root) itself, create another shape for it and connect it to the last folder
if length of remainingURL is greater than 0 then
set urlShape to my makeShape(remainingURL, theURL)
my makeConnection(lastShape, urlShape)
end if

-- layout again for every 10 URLs we read
set urlsRead to urlsRead + 1
if (urlsRead mod 10) is 0 then
tell canvas of front window
layout
page adjust
end tell
end if
end if
on error errStr number errorNumber
-- you'll want the next line if you want to see error messages
-- display dialog errStr
set isDone to true
end try
end repeat

close access fileID

tell canvas of front window
layout
page adjust
end tell
end tell
end siteDiagram

on open of target_files
repeat with aFile in target_files
siteDiagram(aFile)
end repeat
end open[/CODE]


All times are GMT -8. The time now is 03:24 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.