Creating a Custom Org Chart Template with Extra Properties

A Visio user recently asked how to add a salary amount for an Org Chart person automatically, based on their selected Level. I thought it was a bit long to answer in the forum, so I have written my answer below. It demonstrates how you can have your own custom template that works with the Organization Chart add-on in Visio.

My approach to creating a custom template that still uses the Organization Chart Add-On is to create a new drawing from the built-in template, and then to add extra properties to it.

First, select Show Document Stencil to view all of the local copies of the built-in master shapes. If they are not there, then simply drag and drop them from the built-in stencil on to the first page, and then delete the shapes on the page. This will not delete the local copies of the masters.

image

You should check that the Match master by name on drop property is ticked for each master in the Document Stencil, otherwise the Org Chart Add-On may decide to use the original Organization Chart Shapes stencil master with the same name.

image

Open the ShapeSheet of the Document by using the Show ShapeSheet drop-down menu on the Developer tab.

image

Add two extra rows to the User-defined Cells section called LevelList and SalaryList, with the Value formulas:

=”Exec;Sr;Assoc;Jr;Vacant”

and

=”70000;50000;35000;30000;0″

Note that the salaries are entered as numbers without the currency symbol.

image

Now, each of the relevant master shapes need to be updated with the new properties.

So, open up the Executive master shape in edit mode, and add two new Shape Data rows (Level and Salary), and then one new User-defined cell (SalaryTrigger):

image

The Prop.Level Shape Data row has type formula =GUARD(1) because it is a fixed list, the Format formula is =TheDoc!User.LevelList , and the Value formula was created by selecting Vacant from the Shape Data window.

The Prop.Salary Shape Data row has type formula =GUARD(7) because it is a currency, and the Value formula will be created by selecting any Level value from the Shape Data window.

The SalaryTrigger User-defined cell Value formula is:

=SETF(GetRef(Prop.Salary),”=INDEX(LOOKUP(Prop.Level,Prop.Level.Format),TheDoc!User.SalaryList)”)

This will update the value of the Salary cell when a new Level is selected, and, moreover, the value will change if you update the User.SalaryList values in the Document ShapeSheet.

The above trigger formula will allow for local editing of the salary on individual shapes, but if you want to make the salary read-only then insert the GUARD() function as below:

=SETF(GetRef(Prop.Salary),”=GUARD(INDEX(LOOKUP(Prop.Level,Prop.Level.Format),TheDoc!User.SalaryList)))”

Now, you can save your Executive master, and it will have the updated functionality. However, there are seven almost identical masters for Position Type in the Organization Chart stencil, and each of these need to be updated identically!

image

Now, you can manually make all of the changes to the other six Position Type masters (Manager, Position, Consultant, Vacancy, Assistant, and Staff) , or you could use the VBA code below to make the changes for you (note that this has been updated from my original post):

Option Explicit

Public Sub UpdatePositionTypeMastersFromExcecutive()
Dim mstExec As Visio.Master
Dim mst As Visio.Master
Dim mstCopy As Visio.Master
Dim shpExec As Visio.Shape
Dim shpCopy As Visio.Shape
'Get the Executive master
For Each mst In ActiveDocument.Masters
    If mst.Name = "Executive" Then
        Set mstExec = mst
        Set shpExec = mstExec.Shapes(1)
        Exit For
    End If
Next mst
'Abort if not found
If mstExec Is Nothing Then Exit Sub

Dim iRow As Integer
Dim iColumn As Integer

'Loop through each master
'and filter to include those with the Prop.Name Shape Data row
For Each mst In ActiveDocument.Masters
    If Not mst.Name = "Executive" _
        And mst.Shapes(1).CellExists("Prop.Name", Visio.visExistsAnywhere) Then
        Debug.Print "Updating " & mst.Name
        Set mstCopy = mst.Open  'Open the master for editing
        Set shpCopy = mstCopy.Shapes(1) 'Get the group shape
        'Loop through Shape Data rows to find extra ones
        For iRow = 0 To shpExec.RowCount(visSectionProp) - 1
            If shpCopy.CellsSRCExists(visSectionProp, iRow, 0, visExistsAnywhere) = 0 Then
                'Add the row
                Debug.Print , "Adding " & shpExec.CellsSRC(visSectionProp, iRow, 0).rowName
                shpCopy.AddNamedRow visSectionProp, shpExec.CellsSRC(visSectionProp, iRow, 0).rowName, 0
                For iColumn = 0 To shpExec.RowsCellCount(visSectionProp, iRow) - 1
                    If Len(shpExec.CellsSRC(visSectionProp, iRow, iColumn).Formula) > 2 Then
                        'Add the formulas
                        Debug.Print , , iColumn, shpExec.CellsSRC(visSectionProp, iRow, iColumn).Formula
                        shpCopy.CellsSRC(visSectionProp, iRow, iColumn).FormulaU = _
                            shpExec.CellsSRC(visSectionProp, iRow, iColumn).FormulaU
                    End If
                Next iColumn
            End If
        Next

        'Loop through User-defined cells rows to find extra ones
Dim rowName As String
Dim newRow As Integer
        For iRow = 0 To shpExec.RowCount(visSectionUser) - 1
            rowName = shpExec.CellsSRC(visSectionUser, iRow, 0).rowName
            If shpCopy.CellExists("User." & rowName, visExistsAnywhere) = 0 Then
                'Add the row
                Debug.Print , "Adding " & shpExec.CellsSRC(visSectionUser, iRow, 0).rowName
                newRow = shpCopy.AddNamedRow(visSectionUser, shpExec.CellsSRC(visSectionUser, iRow, 0).rowName, 0)
                For iColumn = 0 To shpExec.RowsCellCount(visSectionUser, iRow) - 1
                    If Len(shpExec.CellsSRC(visSectionUser, iRow, iColumn).Formula) > 2 Then
                    'Add the formulas
                        Debug.Print , , iColumn, shpExec.CellsSRC(visSectionUser, iRow, iColumn).Formula
                        shpCopy.CellsSRC(visSectionUser, newRow, iColumn).FormulaU = _
                            shpExec.CellsSRC(visSectionUser, iRow, iColumn).FormulaU
                    End If
                Next iColumn
            End If
        Next
        mstCopy.Close

    End If
Next mst

End Sub

All you need to do now is save your drawing as a Visio template, and you are ready to create Organization Charts from your new template!

Addendum (how to write a report to total the Salary by Level):

If you copying the XML below into a file called TotalSalaryCost.vrd (for example) using Notepad, then run Shape Reports, and then browse for the file, andRun as a Visio Shape …. you should get an embedded Excel worksheet that sums up the salary cost for each level, and get an overall total :-) :

<?xml version="1.0" encoding="utf-8"?> 
<VisioReportDefinition xmlns="urn:schemas-microsoft-com:office:visio:reportdefinition" ReportExists="1" SelectDrawingDataMethod="1" 
Description="" Precision="0" ShowUnits="1" CaseSensitive="0" UserCells="0" HiddenProperties="0" AdvancedFilter="0" FilterExpression="" Version="3">
<Name>Total Salary Cost</Name>
<Title>TotalCost</Title>
<VisioRptDefField ID="1" Display="1" DisplayOrder="1" Type="0" SummaryTypes="1" Tag="2">
<Name>Level</Name>
<DisplayName>Level</DisplayName>
</VisioRptDefField>
<VisioRptDefField ID="2" Display="1" DisplayOrder="2" Type="7" SummaryTypes="2" Tag="2">
<Name>Salary</Name>
<DisplayName>Salary</DisplayName>
</VisioRptDefField>
<VisioRptDefGroup ID="0" GroupingField="1" ItemDisplay="1" GrandSummary="1" ExcludeDuplicates="0"/>
</VisioReportDefinition>

Adding the Sixth Legend Icon in Visio 2010

In my previous two articles, I described how to have 6 icons in a Data Graphic Icon Set, and provided some VBA code to make your own icons sets from existing Visio shapes or images. One thing that I overlooked was the Insert Legend command in Visio 2010, because it does not add the sixth icon automatically, so this blog describes how to add it. As a side effect, the code also enables the legend labels of icon and CBV (Color By Value) items to be edited.

image

When you use the Insert Legend command, it examines the Data Graphics used on the active page, to create legends for each Icon Set or Color By Value settings that it finds. Closer examination of the legend shapes, shows that an instance of the Icon Set master shape is added for each of the icons found.

image

So, my method for having a sixth icon as the default if a match is not found present a problem, because it is not displayed automatically.

However, it is quite simple to add the sixth one. Select the icon above the one that is missing, then enter CTL+D to duplicate the shape, and notice that it will be added below it.

image image

So, now there are two icons that look the same, and are both labelled the same.

So, I decided to write a small macro to provide a simple way to display the default icon, and to change the text.

Firstly, the macro needs to recognise if the selected shape is actually a legend shape item for an icon set. This can be tested by checking that the cell User.msvDGLegendShapeType = “IconItem”

The label text is stored in the User.msvDGLegendText cell.

image

If the legend item is for an icon set, then the sub-shape has the cell User.msvCalloutType with the value “Icon Set” :

image

The displayed icon is controlled by the value in the User.msvCalloutIconNumber cell.

So, I wrote a macro, ChangeLegendTextOrIcon , that makes these changes simple:

Public Sub ChangeLegendTextOrIcon()
Dim shpLegendItem As Visio.Shape
Dim shpIconSet As Visio.Shape
Dim txt As String
Dim sNumber As String
Dim iNumber As Integer

    'Abort if no shape or too many shapes selected
    If Not ActiveWindow.Selection.Count = 1 Then
        Exit Sub
    End If
    
    'Abort if selected shape is not a legend item
    If ActiveWindow.Selection.PrimaryItem.CellExists("User.msvDGLegendShapeType", Visio.visExistsAnywhere) = 0 Then
        Exit Sub
    Else
        Set shpLegendItem = ActiveWindow.Selection.PrimaryItem
    End If
    
    'Prompt to change the label text
    txt = InputBox("Enter the desired label text", "Change Legend Text", _
        shpLegendItem.Cells("User.msvDGLegendText").ResultStr(""))
    shpLegendItem.Cells("User.msvDGLegendText").FormulaU = "=""" & txt & """"
    
    'Prompt to change the icon number (not for CBVItem)
    If shpLegendItem.Cells("User.msvDGLegendShapeType").ResultStr("") = "IconItem" Then
        Set shpIconSet = shpLegendItem.shapes(1)
        sNumber = InputBox("Enter the icon number ( 0 to 4 normally, or anything else for the default) ", _
            "Change Legend Icon", Int(shpIconSet.Cells("User.msvCalloutIconNumber").ResultIU))
        If IsNumeric(sNumber) Then
            iNumber = Int(sNumber)
            shpIconSet.Cells("User.msvCalloutIconNumber").FormulaU = "=" & iNumber
        Else
            MsgBox "You must enter a number", vbInformation
        End If
    End If
    
End Sub

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Simply select legend item that you wish to change, and run the macro.

First, enter the new text to display:

image

Then enter the desired icon number. For example, enter 5 to display the default icon:

image

The legend will now be changed as desired:

image

 

Similarly, you can use the macro to change the label of a CBV legend item. In this example, the header is not displayed on one line because the width of the column is controlled by the widest item. So, I selected one item and ran the macro:

image

I then added some spaces after the text:

image

This forced the whole column to be widened, thus providing enough width for the header text:

image

I have added the code to to the stencil from the previous blog – bVisualIconSetMaker.vss :

https://skydrive.live.com/redir.aspx?cid=3350d61bc93733a9&resid=3350D61BC93733A9!2548&parid=3350D61BC93733A9!197&authkey=!AJaBnvdIOg8NVe4

Make Your Own Visio Data Graphic Icons Sets … automatically

In my last post, I showed how you can actually have up to six icons in a Visio Data Graphics Icon Set ( see http://davidjpp.wordpress.com/2012/04/11/how-to-have-six-icons-in-a-visio-data-graphic-icon-set/ ), and I finished by saying that I would now show how to create new icon sets from existing shapes … automatically. In fact, I will show you how to do it with existing SmartShapes or with images.

I was asked to make KPI icons from six weather images:

image

I wasn’t too keen with the graphics, so I explored the built-in Visio stencils, and found a similar series of shapes on the Symbols stencil:

image

They are okay, but I thought that I would also explore the images available from Clip Art:

image

So, now I have 3 alternative sets of cloud icons, and I wanted to see how they look as Data Graphic Icon Sets. It can be a bit tedious to manually make icons sets from code, so I thought that some VBA code would be best.

I am not going to go through all of the code in this article, because I have included it as a download at the end of this post.

The code is provided in a stencil, called bVisualIconSetMaker.vss, with no master shapes in it, so the easiest way to use it is to drop into your My Shapes folder, because you can then easily open it for any Visio document. There is just one public function, MakeIconSetFromShapes(), that expects you to have 1 to 6 shapes selected in the document that you want to add an icon set to. Read the previous article to see why 6 shapes can be selected, but also realise that the order that you select your 6 shapes dictates the order that they will appear in the icon set, with the sixth selected shape becoming the default icon. Of course, you don’t have to select six.

When you have selected your shapes in the order that you want them to appear (I selected the fourth one last in my example), then run the macro in the bVisualIconSetMaker stencil:

image

You will then be prompted to enter the desired name for your new icon set:

image

If the icon set name already exists, then you will be prompted to confirm that you want to delete the existing one first:

image

No that I had a new icon set, I could use it to change the icon set used in my test shapes:

image

Then I applied the new icon set to my strip of test shapes:

image

Faithfully reproduced, but too obviously an applied image for my taste…

I then repeated the task with the master shapes that I found in the Symbols stencil:

image

I then applied them to my test shapes:

image

Not bad … better than the rough weather icons I had been given.

Finally, I tried it with the arty images that I found using Clip Art:

image

When I applied them to my test shapes, I think I found my favourite:

image

Of course, the IconSet Maker can be applied to almost any shape. For example, I dragged and dropped 5 shapes from the Workflow Objects Shapes stencil.

image

I also added an extra Shape Data row, labelled Backup Method, to the Laptop Computer master shape, and made it a Fixed List type with the following Format formula:

=”;Floppy;USB Drive;CD/DVD;Tape;Remote”

This provides 6 options in the drop-down list because the first one is an empty string:

image

Then I applied the new Backup Icons icon set to some test shapes:

image

 

Then it is so simple to see which laptop is using which backup method:

image

Note : There is a Private Const iconSize statement at the top of the code file in the bVisualIconSetMaker.vss document. The normal values are 6 mm for Metric documents, and 0.25 in for US Unit documents. I changed it to 9 mm for the above Backup example.

This file contains all the code – bVisualIconSetMaker.vss :

https://skydrive.live.com/redir.aspx?cid=3350d61bc93733a9&resid=3350D61BC93733A9!2548&parid=3350D61BC93733A9!197&authkey=!AJaBnvdIOg8NVe4

This file contains the samples displayed in this article – MakeIconSets.vsd : https://skydrive.live.com/redir.aspx?cid=3350d61bc93733a9&resid=3350D61BC93733A9!2549&parid=3350D61BC93733A9!197&authkey=!ALpMsVLV6RXeIQs

Follow

Get every new post delivered to your Inbox.

Join 45 other followers