使用 C# 在 Visio 中创建状态图
谁能给我举一个如何在 visio 中以编程方式创建状态图的示例? 我可以创建空白页面、水滴形状、打开模板等,但当我尝试添加过渡时,它抱怨页面类型不正确。
到处都找不到样本。
或者:我可以将创建图表的用户操作保存为宏。我可以以编程方式运行它吗?
谢谢。
<编辑>
离开电脑 2 分钟,您意识到应该将代码片段放入问题中,而不是尝试将其放入注释中。森林:遇见树木...
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);
如您所见,与下面答案中的片段非常相似。
< /编辑>
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?
Thanks.
< 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 >
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我使用 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.