Back in January 2006, I made a presentation at the Microsoft Office Visio Conference in Home-Sweet-Home Seattle. Good company, good information, and good fun was had by all! You can download plenty of excellent content from that conference, including PowerPoint slides and recorded presentations. Get it here: Visio Conference web site.
In my presentation, Working With Visio an Xml, our friend, Dr. Xml, proudly made his PowerPoint debut and won the crowd over. The presentation summary was…
Download “Visio and Xml Conference Resources” s!Aj0wJuswNyXlhEtEN0zzuI8shr-W – Downloaded 4772 times – 103.00 BEnhance the flexibility of your Visio solutions with XML. In this session you will learn how to use the Visio XML file format, how to store custom XML data islands in SolutionXML, and how to stream Shape XML elements to your drawings using the DataObject.
Note: this article used to have a download link to the audio + slides. The technology for that was so old, it didn’t seem to work in modern browsers, so I’ve removed it.
MattJ says
You’re a/v download link seems to be broken. Just thought I’d let you know.
Visio Guy says
Thank MattJ,
No idea what went wrong, but it’s fixed now!
Chris Maloney says
Chris,
I have built (and modified … converted to c#,etc) your sample code that uses a XML drawing and adds shapes and connectors to create a drawing using XML… very cool… only example of this I have seen anywhere… Thanks! I have the same issue you left in the example… Visio does not “layout” the connectors until I move a shape or use a “layout command”. Did you find a way to get Visio to layout the connectors when it opens the drawing?
thanks,
Chris M
Martin Thiele says
Hello,
I’m trying to create a XML-drawing and everything seems to work fine, only the connectors are not displayed until you move one or more shapes. This is the same problem that Chris Maloney encounters and I was wondering if you already know of a solution. I do not use automation (XML-code is created from within a SQL Server DTS-package).
Thanks,
Martin Thiele
Visio Guy says
Hi Martin,
I actually had this problem when I gave the presentation a few years ago, and still haven’t had the time to figure it out.
I’ll ask around, see if any of the other Visio Geeks have figured it out. Kind of kills the whole “server-side document generation” thing, doesn’t it?
Visio Guy says
I found this post on Mai-Lan’s blog:
http://blogs.msdn.com/mailant/archive/2004/10/26/248369.aspx
It’s from 2004, so maybe they’ve changed something, but it recommends calling Layout on Open. Duh. Still not a solution, but maybe an answer…
Martin Thiele says
Thanks for your quick reply! For the moment we’ve solved it by opening the diagram and flipping/unflipping each shape. This way the layout doesn’t change but it’s a fairly slow. Hope that we will find another solution in the near future.
Visio Guy says
Hi Martin,
Have tried flipping/unflipping the whole drawing (page)?
This little sub might do the trick a bit faster for you.
Since those unrouted connectors are in the lower-left corner of your page, this code first draws a really long diagonal line from ( -pagewidth, -pageheight ) to ( 2 * pagewidth, 2* pageheight ) so that all objects on the page will be symmetrically encompassed by ‘select all’. That way, when we do flip-x twice, the objects on the page won’t move.
At any rate, this should work faster than flipping each individual shape…
Sub FlipXmlPage()
‘// Get the page and the size of the page:
Dim pg As Visio.Page
Dim pw As Double, ph As Double
Set pg = Visio.ActivePage
pw = pg.PageSheet.Cells(“Width”).ResultIU
ph = pg.PageSheet.Cells(“Height”).ResultIU
‘// Draw a big diagonal line to make all objects
‘// on the page symmetrical:
Dim shpLine As Visio.Shape
Set shpLine = pg.DrawLine(-pw, -ph, 2 * pw, 2 * ph)
‘// Flip everything on the page
Dim sel As Visio.Selection
Set sel = Visio.ActivePage.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll)
sel.Flip (Visio.VisFlipDirection.visFlipHorizontal)
sel.Flip (Visio.VisFlipDirection.visFlipHorizontal)
‘// Get rid of the line:
shpLine.Delete
End Sub
Lucas says
Hey there!
The links are broken again. Could you somehow fix it? Or tell me where I can download the slides?
Thanks!
Visio Guy says
Hi Lucas,
No idea what’s wrong. I’ve asked Microsoft if they know what the problem is. I don’t know if I have the audio, and I certainly don’t want to host a 144MB file on my account! 😉
I might be able to dig up the PowerPoint presentation, though…
Visio Guy says
Update: we’re still looking for it…
George Smith says
Thanks, Very useful resource!!
Muhammad Adnan says
hey Vis Guy,
I want to download the files you provided in the post .. but these are not working anymore ? whats the problem ?
please I need them .. how to create XML from code ..
Visio Guy says
Ok everyone, I’ve updated the links in the article. You should now be able to download the:
– PowerPoint presentation
– Sample code for the presentation’s demos
– Live audio + slides for the presentation
Chris
Ruby says
How to find shapes contained in a Group from Visio xml? All shapes inside a Group and outside a Group are children of a Page. So, how can one find containment relationship?
Thank you.
Visio Guy says
Hi Ruby,
If a shape has child elements, then it is a group. The top-level elements under , are, of course, shapes on the page!
Ruby says
Thank you!
When I am parsing visio xml, if I encounter a shape of type Group, how can I determine what elements are in that group? The Group has shapes, but how can I relate these shapes to the actual shapes which are always on the page?
Ruby
Visio Guy says
Hi Ruby,
You look in the element for elements. These are shapes on the page.
If a has a element (that isn’t empty) then you’ve found a group.
Ruby says
Thank you.
Maybe my question is not clear.
I realize how to find a group. But, once I find a group, how can I determine what shapes are contained in that group? OR when I find a shape, how can I determine what group it belongs to? In the example below:
admin: bunch of numbers removed from comment
I have two shapes with ids “1”(pool) and “2”(task). The task is in the pool shape. When parsing the above xml, how can I determine what group shape the task belongs to?
Ruby
Visio Guy says
Hi Ruby,
All I see is a bunch of numbers, (which I have deleted from your comment). It’s just a matter of finding parent and child elements. I don’t really understand where you are confused.
Ruby says
Hi,
Is there anyway I can attach a file here? Sorry for the garbage numbers.
I am not sure how to determine a child’s parent just by looking at the xml? If you have an xml with a child and a parent, can you please point me to the part that indicates parent and child?
I can determine based on the location pinX and pinY of a shape, say shape A and checking if this location intersects with another shape, say, shape B and then deduce that shape A is a child of shape B. But, I do not that this is the right way.
Ruby says
Hi,
I realize what the confusion is.
If a user has selected some elements and ‘Group’ed using the context menu ‘Group’, then there is a Shape of type Group under the page and this Groups has shapes which are it’s children.
But, when a user does not group them explicitly, all these shapes are under the page and I am not sure how I can find the parent child relationship. The example I gave above makes a shape look as if it belong to a parent which is a group. But in the xml, how can I find that?
Thank you.
Visio Guy says
Hi Ruby,
I had assumed that since you were looking for groups, then there were groups on the page. I think you are talking about people placing shapes near each other, perhaps with borders around them so that there is a visual grouping, but no real Visio group.
If that’s the case, then you’d have to analyze size and positions of shapes to see if they are contained within one another.
Visio’s object model has methods for this, but in xml you are “on your own”. The problem with doing too much in xml (without Visio) is that you eventually start to re-create everything that the Visio application does for you.
Ruby says
Hi,
How can I find all shapes of a certain type in a page using visio xml?
Thank you.
Ruby
Gabriel says
Hi,
I realize I am 9 years late to the party, but this is still relevant for me.
Unfortunately, the links seem broken, could you point me to another download direction?
thanks,
Visio Guy says
Ok, I updated the links (again!) hopefully they will work for awhile!
Chris
Gabriel says
Thanks!