使用C#在Visio创建状态图 [英] Creating statecharts in Visio using c#
问题描述
任何人都可以点我如何编程在Visio中创建一个状态图的例子吗?
我可以创建空白页,滴形状,打开模板等,但是当我尝试添加转场就抱怨说,该页面是不正确的类型。
Can anyone point me to an example of how to programatically create a statechart in visio? I can create blank pages, drop shapes, open template etc, but when I try to add transitions it complains that the page is not the right type.
。不能在任何地方找到一个样本
Can't find a sample anywhere.
另外:我可以保存用户的操作以创建图表为宏。我可以运行编程
Alternatively: I can save the user actions to create the chart as a macro. Can I run that programatically?
感谢
<?。编辑>结果
步骤从PC 2分钟的路程,你意识到你应该把代码片段中的问题,而不是试图把它的意见。林:符合树...
< edit >
Step away from the PC for 2 minutes and you realise you should have put the code snippet in the question and not try to put it in comments. Forest: meet trees...
Visio.Document umlStencil = visioApp.Documents.OpenEx(@"UMLSTA_M.vss", (short)VisOpenSaveArgs.visOpenDocked);
Visio.Page page = visioDoc.Pages.Add();
Visio.Shape s1 = page.Drop(umlStencil[@"State"], 5.0, 5.0);
Visio.Shape s2 = page.Drop(umlStencil[@"State"], 5.0, 5.0);
Visio.Shape transition = page.Drop(umlStencil[@"Transition"], 1.0, 1.0);
正如你所看到的,非常类似于下面的答案片段。结果
< /编辑>
As you can see, pretty similar to the snippet in the answer below.
< / edit >
推荐答案
这是我与Visual Studio 2010中跑了反对的Visio 2007和Visio 2010中两个代码
This is the code that I ran with Visual Studio 2010 against both Visio 2007 and Visio 2010.
var visioApp = new Visio.Application();
// Load the UML Statechart stencil (docked)
var stencil_open_flags = Visio.VisOpenSaveArgs.visOpenDocked;
var umlStencil = visioApp.Documents.OpenEx(@"UMLSTA_M.vss", (short)stencil_open_flags);
// create a new empty doc based on the UML Model Template
var doc = visioApp.Documents.AddEx("UMLMOD_U.VST", Visio.VisMeasurementSystem.visMSUS, 0, 0);
var page = doc.Pages.Add();
// Find and manually change the diagram's title
var watermark = page.Shapes["Watermark Title"];
var LockTextEdit_cell = watermark.CellsU["LockTextEdit"];
LockTextEdit_cell.FormulaForceU = "GUARD(0)";
watermark.Text = "MyTitle";
LockTextEdit_cell.FormulaForceU = "GUARD(1)";
// Find the masters we need
var state_master = umlStencil.Masters["State"];
var transition_master = umlStencil.Masters["Transition"];
// Drop the masters into the page
var s1 = page.Drop(state_master, 5.0, 5.0);
var s2 = page.Drop(state_master, 1.0, 1.0);
var transition = page.Drop(transition_master, 3.0, 3.0);
这篇关于使用C#在Visio创建状态图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!