Dynamically generate Visio from .Net

G

Guest

I would like to dynamically create a Visio diagram from .Net. I tried
looking at the Visio SDK, but the samples are extremely convoluted for me to
understand.

Does someone have an example of creating a basic drawing with two shapes
connected? I can then expand that example to include other elements.

Also, my plan is for this project to be an ASP.Net website. Is Visio
required to be on the web server in order to generate the Visio documents?
If so, a full install, or just the .Net option in the Visio install options.
 
P

Peter Huang [MSFT]

Hi Mike,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to dynamically generate
Visio document at ASP.NET Server side.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Firstly to utilize the Visio function, we do need the Visio application
installed and automation the Visio application to do the job we do
manually. This is called Automation.
But Server side Automation of Office products is not support which have
many underlying problem.
257757 Considerations for server-side Automation of Office
http://support.microsoft.com/default.aspx?scid=kb;EN-US;257757

If we want to generate Visio document programming,, we should use client
side automation, e.g. a Winform application.
Here is a link for your reference.
305199 How to automate Visio with Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;EN-US;305199

Actually we can use the Macro recording function to track the code used to
do some manually job programming.
e.g.
1. Open a Visio application and new a Drawing
2. Press Tools/Macro/Record New Macro
3. And then we can do our job manually
e.g. drop two shape and a connector onto the drawing and connect them
4. Stop Macro recording
5. Press Atl+F11 to view the macro recorded.
Here is what I got.
Sub Macro1()
Application.Windows.ItemEx("Drawing1").Activate
Application.ActiveWindow.Page.Drop
Application.Documents.Item("BASFLO_M.VSS").Masters.ItemU("Process"),
3.838583, 9.84252
Application.Windows.ItemEx("Drawing1").Activate
Application.ActiveWindow.Page.Drop
Application.Documents.Item("BASFLO_M.VSS").Masters.ItemU("Process"),
3.838583, 7.775591
Application.Windows.ItemEx("Drawing1").Activate
Application.ActiveWindow.Page.Drop
Application.Documents.Item("BASFLO_M.VSS").Masters.ItemU("Dynamic
connector"), 2.165354, 8.858268
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Size Object")
Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 =
Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsU("EndX")
Set vsoCell2 =
Application.ActiveWindow.Page.Shapes.ItemFromID(2).CellsSRC(7, 3, 0)
vsoCell1.GlueTo vsoCell2
Application.EndUndoScope UndoScopeID1, True

Dim UndoScopeID2 As Long
UndoScopeID2 = Application.BeginUndoScope("Size Object")
Dim vsoCell3 As Visio.Cell
Dim vsoCell4 As Visio.Cell
Set vsoCell3 =
Application.ActiveWindow.Page.Shapes.ItemFromID(3).CellsU("BeginX")
Set vsoCell4 =
Application.ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(7, 2, 0)
vsoCell3.GlueTo vsoCell4
Application.EndUndoScope UndoScopeID2, True

End Sub

We can easy convert the code to VB.NET, because in nature we are
programming against the Visio Object Modal.
In the SDK, it also involved the Save As Web Page API, which is also the
automation behavior which is to do the Save As Web Page menu command
programming.

In a summary, this solution is not proper to run at ASP.NET server side due
to the KB above.

Also ASP.NET can use .NET buildin funtion to create bitmap on the fly and
show to the client. So if your scenario is not complex, maybe this is an
alternative.
Create Snazzy Web Charts and Graphics On the Fly with the .NET Framework
http://msdn.microsoft.com/msdnmag/issues/02/02/ASPDraw/

If you have any concern, please feel free to let me know.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thank you Peter for the detailed response. I notice than you can create XML
Visio documents (.VDX) files. Do you suppose a better solution that would
not include server side automation of is to generate the XML file. I have
downloaded the Office Reference XML schemas.

Thanks again for the reply.
 
P

Peter Huang [MSFT]

Hi Mike,

Yes the Create the XML file vdx may be an alternative.
We have open XML format schema for Office 2003.
But if we save a simple visio drawing with two connected shape as vdx, we
will find that it is not trivial.
Because so far in the Visio SDK, we did not have an API to programming
Visio related XML document(e.g. an AddShape method will add a shape to an
existing Visio XML Document, there is no such one), it is difficult to
program a practical solution.

If we go through the solution, we have to leverate the .NET XML library to
create a XML file confined to the Visio XML file schema.
If we create a simple Visio drawing and save as vdx file and then open it
in notepad, we will find that it is hard to create such a file with XML
format even if it is a very simple drawing.

If you have any other concern, please feel free to let me know.


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Mike,

I am posting to check how the thing is going on.

If you have any concern on this issue, please feel free to let me know

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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