By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,375 Members | 1,284 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,375 IT Pros & Developers. It's quick & easy.

Dynamically generate Visio from .Net

P: n/a
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.
--
Mike Logan
Sep 12 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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...b;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...b;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.

Sep 13 '06 #2

P: n/a
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.
--
Mike Logan
""Peter Huang" [MSFT]" wrote:
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...b;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...b;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.

Sep 13 '06 #3

P: n/a
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.

Sep 14 '06 #4

P: n/a
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.

Sep 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.