David 的个人资料bVisual照片日志列表更多 工具 帮助

日志


9月8日

Visio 2010 : Containment and Cross-Functional Flowcharts

One of the templates to get a revision in Visio 2010 is the Cross Functional Flowchart template because of the new list and containment functionality that has been added into the core application.  I had to write a small bit of code in earlier versions of Visio for each flowchart shape to automatically understand which swimlane and phase it belongs to, but now there are ShapeSheet functions available, so a slight modification of a flowchart master enables it to inherit values from the swimlane that it is in.  This article demonstrates who you can do this to, for example, synchronize the fill color of each flowchart shape to that of the swimlane that it belongs to.

image

The Cross Functional Flowchart template now includes its own add-in ribbon:

image

Each Swimlane shape is now a container shape, as is the CFF Container and Phase shapes.   Notice that the Process shape has a Shape Data row, named Function, which automatically updates itself with the text entered into the header text of the Swimlane that it is within.  Unfortunately, it is not the same for the Phase that it is within … perhaps Microsoft will correct this for the official release of Visio 2010, but in the meantime I will propose a workaround later in this post.  Additionally, the Function shape data row is displayed, regardless of whether it is within a Swimlane or not, therefore I will show how the visibility can be controlled to automatically hide if it is not within a Swimlane.

Container Categories

The new container masters have lots of new User-defined cells to define how they are to be handled, amongst which are the following two:

  • User.msvStructureType = ”Container”
  • User.msvShapeCategories = “Phase”

The second value will be CFF Container, CFF List, Swimlane or Phase, depending on which Master it is.

In the above example, the My Process shape is actually within three containers, a CFF Container, Swimlane and Phase (note that the new Phase shape actually extends from the Swimlane headers to the right hand line that has the Phase X label).

Listing the Containers that a Shape is Within

There are times when you will need to determine what containers a shape is within, and to be able to recognise what type of container it is.  The ListSelectedShapeContainers macro listed below will produce output in the Immediate Window like httis (if the My Process shape is selected first):

Process       My Process
              ID            CFF Container CFF List      Swimlane      Phase         Name
               20           False         False         False         True          Phase (vertical).20
               4            False         True          False         False         Swimlane List
               11           False         False         True          False         Swimlane.11

Public Sub ListSelectedShapeContainers()
Dim shp As Visio.Shape
    If Visio.ActiveWindow.Selection.PrimaryItem Is Nothing Then
        Exit Sub
    Else
        Set shp = Visio.ActiveWindow.Selection.PrimaryItem
    End If

Dim aryContainerIDs() As Long
Dim containerID As Long
Dim iContainer As Integer
Dim containerShp As Visio.Shape

    Debug.Print shp.Name, shp.Text
    aryContainerIDs = shp.MemberOfContainers()
    Debug.Print , "ID", "CFF Container", "CFF List", "Swimlane", "Phase", "Name"
    For iContainer = 0 To UBound(aryContainerIDs)
        Set containerShp = Visio.ActivePage.Shapes.ItemFromID(aryContainerIDs(iContainer))
        Debug.Print , aryContainerIDs(iContainer), _
            containerShp.HasCategory("CFF Container"), _
            containerShp.HasCategory("CFF List"), _
            containerShp.HasCategory("Swimlane"), _
            containerShp.HasCategory("Phase"), _
            containerShp.Name
    Next iContainer
End Sub

Notice the new shape method MemberOfContainers() which returns an array of container shape IDs, which are then used to get the actual container shapes in order to discover what type of container they are using the new HasCategory() method.

Opening the ShapeSheet of the My Process shape reveals how the containing swimlane shape text is displayed in the Prop.Function row:

image

The new ShapeSheet function, CONTAINERSHEET() requires the index position in the list of container shapes, and the second argument enables the list of returned containers to be filtered by the category.  The Scratch.A1 cell formula is =User.visHeadingText, which has the formula =SHAPETEXT(Sheet.13!TheText)

There is also a new function, CONTAINERCOUNT(), which returns the number of containers that the shapes is within.

Listing the Containers and Members on a Page

It is also possible to list containers on a page, and to list the shapes contained within them.  The following Immediate Window output was produced by the ListPageContainers() macro:

ID            CFF Container CFF List      Swimlane      Phase         Name
1            True          False         False         False         CFF Container
               4            Swimlane List
               6            Phase List
4            False         True          False         False         Swimlane List
               8            Swimlane
               11           Swimlane.11
               17           Process
               18           Process.18
6            False         True          False         False         Phase List
               14           Phase (vertical)
               20           Phase (vertical).20
8            False         False         True          False         Swimlane
               18           Process.18
11           False         False         True          False         Swimlane.11
               17           Process
14           False         False         False         True          Phase (vertical)
               18           Process.18
20           False         False         False         True          Phase (vertical).20
               17           Process

Notice that I did not filter out the contained containers, but I did filter out the connectors (1D) shapes.

Public Sub ListPageContainers()
Dim aryContainerIDs() As Long
    aryContainerIDs = Visio.ActivePage.GetContainers(visContainerIncludeNested)
Dim containerID As Long
Dim iContainer As Integer
Dim containerShp As Visio.Shape

Dim aryMemberIDs() As Long
Dim memberID As Long
Dim iMember As Integer
Dim memberShp As Visio.Shape

    Debug.Print "ID", "CFF Container", "CFF List", "Swimlane", "Phase", "Name"
    For iContainer = 0 To UBound(aryContainerIDs)
        Set containerShp = Visio.ActivePage.Shapes.ItemFromID(aryContainerIDs(iContainer))
        Debug.Print aryContainerIDs(iContainer), _
            containerShp.HasCategory("CFF Container"), _
            containerShp.HasCategory("CFF List"), _
            containerShp.HasCategory("Swimlane"), _
            containerShp.HasCategory("Phase"), _
            containerShp.Name
        aryMemberIDs = containerShp.ContainerProperties.GetMemberShapes(Visio.VisContainerFlags.visContainerFlagsDefault)
        For iMember = 0 To UBound(aryMemberIDs)
            Set memberShp = Visio.ActivePage.Shapes.ItemFromID(aryMemberIDs(iMember))
            If memberShp.OneD = False Then
                Debug.Print , aryMemberIDs(iMember), memberShp.Name
            End If
        Next iMember
    Next iContainer
End Sub

Notice the new page method GetContainers() which returns an array of container shape IDs.  These container shape IDs are then used to retrieve the actual shapes, and the new shape collection ContainerProperties has a method GetMemberShapes() which will retrieve the desired member shapes.

There is also a new ShapeSheet function, =CONTAINERMEMBERCOUNT(), which returns the number of shapes contained within it.

Displaying the Header Text

As stated earlier, the Swimlane master has a user-defined cell, visHeadingText, which contains a reference to the text of a sub-shape (Sheet.7 in the Master).  However, the Phase master does not, therefore I added the visHeadingText user-defined cell to the Phase master in the local stencil, with the same formula, because the text edit target shape in that master is also Sheet.7.

User.visHeadingText = SHAPETEXT(Sheet.7!TheText)

This means that you can then edit the flowchart masters, for example the Process master, to display the enclosing Phase shape in a new Shape Data row, in the same manner as the Function Shape Data row.

imageLike before, these edits were done to the master on the local document stencil.

A useful consequence of having the Phase in each shape is that these values will now be exposed to the Visio reporting tool.

Controlling Visibility of the Shape Data Rows

To avoid the needless display of Shape Data rows when they are not relevant, I decided to add formlae to the Function and Phase Shape Data rows.

 image

Note that the values display #REF! in the master ShapeSheet, which makes it reasonable to assume that we can use the ISERROR() function to determine whether or not there is an enclosing swimlane:

Prop.Function.Invisible = ISERROR(CONTAINERSHEETREF(1,"Swimlane")!NAME())

A similar formula was added to Prop.Phase.Invisible: = ISERROR(CONTAINERSHEETREF(1,"Phase")!NAME())

Synchronizing the Flowchart Shape Fill Color with the Swimlane

Finally, I get to set the fill format ell values so that the Process master is synchronized with the enclosing swimlane.

image

The Fill Format section of the Process master has several modified formulae in order to synchronize the fill color wit the enclosing swimlane.  Fortunately, I have already setup a cell which tells me if the shape is inside a swimlane or not, so it is a simple matter to refer to that value to evaluate whether to apply the fill properties of the enclosing swimlane, or just to use the default values from a theme.

image

So, there we go, we can now enhance the Cross Functional Flowchart template with just ShapeSheet functions … the new containment features of Visio 2010 are really useful additions to the rich developer interface … enjoy!

评论

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。
ParkerDavi​d 在此页禁用了评论功能。

引用通告

此日志的引用通告 URL 是:
http://bvisual.spaces.live.com/blog/cns!3350D61BC93733A9!1811.trak
引用此项的网络日志