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

日志


8月3日

Displaying the Master and Stencil Name of Shape

A recent newsgroup question asked if it is possible to display the master name and the stencil that a shape originally came from.   Following on from my last post ( Re-opening Default Stencils ), I realised that this is possible  Here’s how (once you have created a reference to the Microsoft Scripting Runtime):

Public Sub DisplayOriginalMaster()

    If Visio.ActiveWindow.Selection.Count = 0 Then
        Exit Sub
    End If
Dim shp As Visio.Shape
    Set shp = Visio.ActiveWindow.Selection.PrimaryItem
    If shp.Master Is Nothing Then
        MsgBox "This shape has no master", vbExclamation
        Exit Sub
    End If

Dim mst As Visio.Master
    Set mst = shp.Master
Dim stenName As String
    stenName = getStencilName(mst.UniqueID)
    If Len(stenName) = 0 Then
        MsgBox "Sorry, I can't find the stencil this master (" & mst.Name & ") is from", vbExclamation
    Else
        MsgBox "This shape is the master : " & mst.Name & vbCrLf & "is from the stencil : " & stenName, vbExclamation
    End If

End Sub

Private Function getStencilName(ByVal mstID As String) As String

Dim srcDoc As Visio.Document
    Set srcDoc = Visio.ActiveDocument
Dim tmplt As String
    tmplt = srcDoc.Template
    If Len(tmplt) = 0 Then
        Exit Function
    End If

Dim fs As FileSystemObject
    Set fs = New FileSystemObject
    If fs.FileExists(tmplt) = False Then
        Exit Function
    End If
Dim winSrc As Visio.Window
Dim stenDoc As Visio.Document
Dim aryStens() As String
Dim win As Visio.Window
Dim arySrcStens() As String
    For Each win In Visio.Windows
        If win.Document Is srcDoc Then
            Set winSrc = win
            winSrc.DockedStencils arySrcStens
            Exit For
        End If
    Next

Dim sten As String
Dim stenName As String
Dim i As Integer
    For i = 0 To UBound(arySrcStens)
        stenName = stenContains(arySrcStens(i), mstID)
        If Len(stenName) > 0 Then
            getStencilName = stenName
            Exit Function
        End If
    Next
Dim doc As Visio.Document
    Set doc = Visio.Application.Documents.OpenEx(tmplt, Visio.visOpenCopy + Visio.visOpenHidden + Visio.visOpenDontList)

    For Each win In Visio.Windows
        If win.Document Is doc Then
            win.DockedStencils aryStens
        End If
    Next
    For i = 0 To UBound(aryStens)
        stenName = stenContains(aryStens(i), mstID)
        If Len(stenName) > 0 Then
            Exit For
        End If
    Next
    'Close the template document
    doc.Close

    getStencilName = stenName
End Function

Private Function stenContains(ByVal sten As String, ByVal mstID As String) As String
Dim doc As Visio.Document
Dim mst As Visio.Master
    For Each doc In Visio.Application.Documents
        If doc.FullName = sten Then
            For Each mst In doc.Masters
                If mst.UniqueID = mstID Then
                    stenContains = doc.Title
                    Exit Function
                End If
            Next
        End If
    Next
    stenContains = ""
End Function

评论

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

引用通告

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