有人能指出我如何以编程方式在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);
正如您所看到的,非常类似于下面答案中的摘录。
< / edit>
答案 0 :(得分:1)
这是我使用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);