使用 C# 在 Visio 中创建状态图

发布于 2024-12-06 20:01:26 字数 655 浏览 0 评论 0原文

谁能给我举一个如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舞袖。长 2024-12-13 20:01:26

这是我使用 Visual Studio 2010 针对 Visio 2007 和 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文