有什么方法可以读取 Visio 流程的流程。如果我们有像下面这样的 Visio 文档,我可以阅读像 From Begin to Process 1 Then From Process 1 to Decision 1 这样的过程。如果 Decision 1 是 Yes 然后 Process 3 else Process 2 。从过程 3 到 END。从流程 2 到决策 2 等。
使用 Visio 中的宏或使用 Visual Studio 中的 C# 是否可以像上面那样阅读。
Visio 有一个自动化模型,允许您编写代码来完成您想做的事情。Visio 具有内置的 VBA(Visual Basic for Applications),因此您可以快速开始使用代码。而在 C# 或 VB.NET 中创建 VSTO 加载项需要更多的努力才能开始。
只要连接器正确地粘在形状上,您就可以追踪图表的结构。如何做到这一点并不是很明显,但我可以在脑海中提供一些提示。如果不出意外,我在下面提到的术语将有助于搜索代码示例和 API 参考。
这些框在 Visio 中称为“2D”形状,连接器称为“1D”。您可以通过查询 shape.OneD 属性来检测“一维”形状。
2D 形状具有“FromConnects”对象,1D 形状具有“Connects”对象。Connects 对象本质上封装了连接器的粘合端。使用 Connects 对象,您可以获得粘合的连接器的末端(Begin 或 End),以及它粘合到的位置(特定的连接点或整个形状)。
通过这种方式,您可以构建一个连接列表,其中记录了 from-box 和 to-box,从而您可以了解图表的结构。
您可以通过查找没有传入连接的框来找到起点。在 Visio 用语中,这意味着没有连接器将其连接器 End 粘合到形状上。(连接器有 Begin 和 End 端)。
我确定我在某个地方有样品,但我目前不在一个可以搜索它们的地方。以下是一些粗略的、未经测试的代码,可能会帮助您入门:
Public Sub AnalyzePage
Dim pg As Visio.Page
Set pg = Visio.ActivePage
Dim shp As Visio.Shape
For Each shp in pg.Shapes
If (shp.OneD) Then
'// This is a connector:
'// We could examine shp.Connects to find out which
'// boxes it is glued to.
Else
'// This is not a connector...a box:
If (shp.FromConnects.Count > 0) Then
'// FromConnects are the other side of Connects. We can look
'// at each FromConnect object for this shape and determine if
'// the connector is incoming or outgoing from this shape, and
'// (with a bit of work) figure out the box on the other end
'// of the connector.
End If
End If
Next shp
End Sub