是否有任何方法可以读取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