有什么方法可以读取Visio流的流程。如果我们有如下所示的Visio文档,我可以阅读从开始到流程1然后从流程1到决策1的流程吗。如果决策1是,则流程3否则是流程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对象,您可以获取已粘合的连接器的末端(“开始”或“末端”)以及粘合的对象(特定的连接点或整个形状)。
通过这种方式,您可以建立一个记录发件箱和收件箱的连接列表,从而可以了解该图的结构。
您可以通过查找没有传入连接的框来找到起点。用Visio的话来说,这意味着没有连接器的连接器末端粘在一个形状上。 (连接器具有“开始”和“结束”端)。
我确定我的样本在某个地方,但是我现在不在可以搜索它们的地方。以下是一些未经测试的粗糙代码,可以帮助您入门:
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