Where is the style sheet information stored in a shape

Started by mfPanter, October 26, 2012, 09:03:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mfPanter

Hi
I work with style sheets. With this function I can change e. g. the text size based on the style sheet defininition.
For a specific shape I like to get the information which style sheet is attached to that shape.
Do I find the information in the shapesheet or where is the information?

Thank you for your help
Grettings
mfPanter

Paul Herber

As far as I know style information is not stored within a shape, it is a document property, a shape will refer to a document style.
The style information is stored within the document but as far as I know there is no way to access it via the shapesheet. No documentation I have discusses how to access styles programatically.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

aledlund

Paul's correct it's stored in the document section (in a shapesheet format). I haven't gone looking for it using the standard API's, it of course is accessible as XML.
al


NOTE To show the ShapeSheet window for a style, open the DrawingTM Explorer window
(choose View > Windows > Drawing Explorer), navigate to a style, right-click the style,
and then choose Show ShapeSheet from the shortcut menu.



JuneTheSecond

#3
Now a days, I am interested in just the new Visio features.
But sometimes, it's good to remember an old days of Visio.
I found in the help document that Shape in Visio 2.0 had
already LineStyle, FillStyle and TextStyle properties.
By them you could set and find the custom styles to the shape.

    Debug.Print ActivePage.Shapes(i).LineStyle
    Debug.Print ActivePage.Shapes(i).FillStyle
    Debug.Print ActivePage.Shapes(i).TextStyle
Best Regards,

Junichi Yoda
http://june.minibird.jp/

aledlund

some example macros that might help. One thing to keep in mind is that when a shape has subshapes; the sub-shapes may have different styles associated with them so you have to iterate down through those as well.
al






Option Explicit

'
'
'
Public Sub getShapeBaseStyles()

    Dim visDoc As Visio.Document
    Set visDoc = Application.ActiveDocument
    Dim visPage As Visio.Page
    Set visPage = visDoc.Pages(1)
    Dim visShape As Visio.Shape
    For Each visShape In visPage.Shapes
        Debug.Print visShape.NameU
        Dim strStyle As String
        strStyle = "Line " & getStyleInfo(visShape.LineStyle)
        Debug.Print strStyle
        strStyle = "Text " & getStyleInfo(visShape.TextStyle)
        Debug.Print strStyle
        strStyle = "Fill " & getStyleInfo(visShape.FillStyle)
        Debug.Print strStyle
    Next visShape


End Sub


'
'
'
Public Sub getDocStyles()

    Dim visDoc As Visio.Document
    Dim visStyles As Visio.Styles
    Dim visStyle As Visio.Style

   
    Set visDoc = Application.ActiveDocument
    Set visStyles = visDoc.Styles
    For Each visStyle In visStyles
        Debug.Print visStyle.Index & " Style='" & visStyle.NameU & "' is BasedOn '" & visStyle.BasedOn & "'"
    Next visStyle

End Sub

'
'
'
Public Function getStyleInfo(ByVal strName) As String
    Dim strInfo As String
    strInfo = ""
    Dim visDoc As Visio.Document
    Dim visStyles As Visio.Styles
    Dim visStyle As Visio.Style
   
    On Error Resume Next
    Set visDoc = Application.ActiveDocument
    Set visStyles = visDoc.Styles
    Set visStyle = visStyles(strName)
    If Not (visStyle Is Nothing) Then
        strInfo = " Style='" & visStyle.NameU & " Index=" & CStr(visStyle.Index) & "' is BasedOn '" & visStyle.BasedOn & "'"
    End If
   
    getStyleInfo = strInfo
End Function