Best way to generate a diagram programatically

S

sh856531

Hi Guys,

We have a need to programmatically create Visio diagrams using either Visio
2003 or 2007 (not sure which yet).

The idea will be to process a directory with a number of XML files and
create a diagram based on the contents of each file.

Can anyone tell me the best way to achieve this at a high level. If at all
possible I'd like to use C#.

I've looked at the XML format for visio with a view to just generating an
appropriate XML document on the fly. Problem was the XML format scared the
cack out of me. In fact, I think it scared the cack of Visual Studio as well
as it refused to even autoformat it so now the entire documents appears on 3
really long lines. And thats just with one rectangle!

I'm wondering if it is possible to use an API to create and connect shapes
but I don't know if thats possible on a server. Would that approach actually
open up lots of Visio instances as I process the files?

Huge thanks to anyone who could offer some suggestions on how to approach
this!

Best Regards

Simon
 
A

AlEdlund

Let's take this in order.
a.) I'd start with v2007, no sense at all in going back and v2007
professional has a lot of data features
b.) the visio sdk has numerous examples using C# of creating drawings
c.) Chris Roth did some presentations/videos on Visio XML at the
DevConference and they are on his site (www.visguy.com)
d.) unlike Visio's Office cousins, Visio only opens one instance of the
application at a time.

al
 
N

Nikolay Belyh

d.) unlike Visio's Office cousins, Visio only opens one instance of the
application at a time.

Al, are you sure about that...? Probably I miss something here...
Means, I can easily start two (or more) Visio processses (instances),
e.g. with CreateObject()... Thus I think I can have more than one
Visio instance at a time. I thought that the "single-instance" is the
"feature" of the Outlook only...

Probably, you mean that several Visio drawing controls share the same
Visio application?

Kind regards, Nikolay.
 
A

AlEdlund

Nikolay,
You are correct. I use the drawing control so much, some times I forget.
Happy holidays and thanks,
al
 
A

AlEdlund

Nikolay,
I am aware of that one. The good news is that with the release of office
sharepoint the excel restriction has been removed (excel services). Another
example of how office is moving towards server based solutions is the
project server implementation. It's because of this trend that my own
development has been moving away from addins to activex solutions (hopefully
the code will work both on a workstation and any future solutions that may
come down the line).
al
 
S

sh856531

Hi Guys,

I really appreciate you taking the time to answer - thank you both.

I was wondering, what is the general perception of using Visio on the server
these days. My gut reaction is that I shouldn't do it, but if its the only
way and is reasonably well documented, if not encouraged, then I'm tempted to
give it a go.

Have you guys used the XML format to actually try and manipulate shapes? I
think its great that MS are doing it but the XML that I saw was
indescriminately *nuts*. I've never had an xml document that Visual Studio
and Oxygen would refuse to format. The best I managed to get was wordwrap!
And that was with just one square on a standard document!

:-|

Thanks again!

Simon
 
A

AlEdlund

For XML I really prefer the Altova XMLSPY product when investigating how
something is put together. Visio actually uses some XML under the covers
(checkout solutionXML). SVG of course is very similar and some of the guys
have been working with WPF/Silverlight.

On the server side, I use sharepoint so all of the drawings are handled
locally. As Nikolay pointed out Server side execution of workstation
products is strongly discouraged.

al
 
S

sh856531

Hi Al,

It kinda seems to me like Microsoft have been missing a trick for a long
long time.

Switching to XML is all well and good but the Visio XML looks far to
complicated to be (easily) used. If MS were to create an API over the top of
the XML so you just had to create object hierarchies it would be so much
better.

I really don't know why MS hasnt fixed the server side issue. They've made
such a huge investment is creating the office applications and underlying
APIs that I can't for the life of me created version of each product that can
generate documents server side. They have a lot of the APIs there already -
they just need to be extracted and then they could make a packet selling
middleware licenses so that people can create office documents
programmatically on the fly.

I never did understand why they haven't done that yet. They could make an
awful lot of money if they did so I would think

Best Regards

Simon
 
N

Nikolay Belyh

Have you guys used the XML format to actually try and manipulate shapes? I
think its great that MS are doing it but the XML that I saw was
indescriminately *nuts*. I've never had an xml document that Visual Studio
and Oxygen would refuse to format. The best I managed to get was wordwrap!
And that was with just one square on a standard document!

:-|

Hi Simon,

"Life sucks when you live, and then you die. And life still
sucks" :)
(c) Dead Like Me. Very inspiring movie, by the way.

If you ask me, then, personally, I have only heard about Chris Roth
doing cool stuff with Visio XML generation (on that presentation, in
particular..) But unfortunately I have never seen this kind of things
(generation of visio xml) happening in the real life... So for me this
is basically like UFO story :). I suppose that mere developers (like
me) might be just lazy enough to dig into XML... Though "most
attributes are optional" when you generate an XML Visio drawing (which
is true of course), IMO there are still enough of them to drive you
nuts. And that creepy XML syntax does not add any fun as well.
But what actually drove *me* nuts was a (naive) attempt to generate an
SVG out of arbitrary Visio diagram *without* Visio. This is IMO where
the "happy hardcore" lives. BTW, more about "happy hardcore" - it is
kinda music style, actually -
:)

Back to the point, I think you will be able to work with a Visio XML
file in Visual Studio XML editor, when you:

1. Remove the preview picture and all other "unused stuff".
File -> Remove Unused Information -> Check all you see there, then
save as XML

2. Open the XML in Visual studio (still 2 lines)

3. Remove the xml:space='preserve' from the root element (this
attribute prevents Visual Studio from auto-formatting the document).
Now Visual Studio shall be able to format document properly.

And, in general, I am rather optimistic about Visio XML generation and
I think that it is totally possible. For example, here is your
"square" (minimalistic):
------
<?xml version='1.0' encoding='utf-8' ?>
<VisioDocument
xmlns='http://schemas.microsoft.com/visio/2003/core'
version='12.0' >
<Pages>
<Page ID='0' NameU='Page-1'>
<Shapes>
<Shape ID='1' Type='Shape'>
<XForm>
<PinX>5</PinX>
<PinY>5</PinY>
<Width>2</Width>
<Height>2</Height>
</XForm>
<Geom IX='0'>
<MoveTo IX='1'>
<X F='Width*0' />
<Y F='Height*0' />
</MoveTo>
<LineTo IX='2'>
<X F='Width*1' />
<Y F='Height*0' />
</LineTo>
<LineTo IX='3'>
<X F='Width*1' />
<Y F='Height*1'/>
</LineTo>
<LineTo IX='4'>
<X F='Width*0' />
<Y F='Height*1' />
</LineTo>
<LineTo IX='5'>
<X F='Geometry1.X1' />
<Y F='Geometry1.Y1'/>
</LineTo>
</Geom>
</Shape>
</Shapes>
</Page>
</Pages>
</VisioDocument>
-----

One more thing. It is well known, that the first mistake in a software
design is "solving the wrong problem" (c) :). So probably if you tell
us more about the "business" task you are solving (What are these XML
files you are going to convert into drawings? Where are they coming
from? What do they mean? What do you want to do with drawings? etc...)
then probably someone will be able to help you at the "next level of
abstraction" :)

Kind regards, Nikolay
 
G

Guy..L

I liked the simplicity of this text solution. It shows the link capability.
I'm sure <link/> is in the XML spec. Plus it wouldn't be too hard to
resurrect that text command structure for specific application much as I
intend and perhaps the original question posed.

Somehow all that XML handling code seems like overkill.

Regards also,
Guy..Lister
CSI
 
P

Paul Herber

I liked the simplicity of this text solution. It shows the link capability.
I'm sure <link/> is in the XML spec. Plus it wouldn't be too hard to
resurrect that text command structure for specific application much as I
intend and perhaps the original question posed.

Somehow all that XML handling code seems like overkill.

I might have a go at recreating a CSV input utility. I suspect it
wouldn't be difficult, I already have applications that can import
SDL-CIF and MSCgen into Visio, CSV is a cinch in comparison. But would
anyone pay for such a utility - I doubt it.

CSV format will only be ASCII compatible, no unicode so nothing other
than English language (and maybe some other western European
languages).
Maybe that was why it was dropped, non-maintainable for other
languages.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top