johnvisiomvp

Life with Visio and other Microsoft Toys!

Archive for the ‘Visio’ Category

Why are #Visio H&Fs so Lame?

leave a comment »

This question came up recently and though I have insisted that Visio authors mention that background pages are the Visio way, this goes into more detail.

Word has had the ability to add special text at the top and the bottom of the page called Headers and Footers. They contained information like dates, page number, number of pages and various text like titles for sections or chapters.

In Visio, it was different, the original and the Visio way to handle this information was background pages. The background pages contained information in a title block you wanted to be placed consistently on the foreground page. Each foreground page could contain several background pages. There may be information you want on all pages or information you only want on certain pages.

In the pre computer days, engineering drawings were created on large format vellum paper, a translucent paper. The draughtsperson would create the drawing with dark ink using a T Square, 45s and 30-60s(these are triangles) and other drawing aids. The T Square allowed the draughtsperson to create perfectly horizontal lines and the 45s and 30-60s vertical lines. The 45s also allowed for the creation of consistent hatch marks and the 30-60s helped to create perspective drawings.

To create the consistent title block, the draughtsperson would place a sample title block behind the vellum and trace it. This is where the concept of foreground/background pages came.

The drawing was printed by placing the vellum on top of a light sensitive page and running it through a machine that exposed it to a bright light and then ammonia. That was one of my tasks I had as a summer job (changing diapers is not a problem for me)

Headers and Footers were added  to Visio in version 3 because of a request from a large engineering firm. Most office apps print on a single page size, Visio allows you to make a drawing large than standard page sizes and print them on the same size paper or on several physical pages  by tiling the drawing. The firm wanted to print oversized drawing on standard letter size paper and have header and footers like Word to be printed on the individual pages.

So, Visio added the bare minimum. For most Visio drawings, they are not tiled when printing, so H&Fs are redundant, but when they are tiled it does give you the ability to mark each individual page.

Enjoy…

John Marshall… Visio MVP Visio.MVPs.org

Advertisements

Written by johnvisiomvp

August 8, 2019 at 11:20 am

Posted in Uncategorized, Visio

Tagged with

Cruise runs aground

with one comment

While I was creating the cruise demo, I ran into a problem removing the data source from the connected data. I had created the drawing and tried it as a data connected diagram and went back and tweaked the drawing. Since I wanted to start the demo with a clean diagram I tried to remove the reference to the source Excel file. I have done it several times on other drawings, You right click the External Data window and the last item in the drop down is Data Source. Select that and the drop down give you a Remove option. This will produce a warning dialog asking if you really want to do that, but in this case when I clicked, the drawing hung with a (Not Responding) tag. I went and had lunch and it was still hung.
Since a Visio drawing file is the same as other Office apps, a zipped version of a directory of XML and other files, I tried to unzip a test file to see if I could manually remove the reference. That only produced a corrupted file when I compressed and renamed the file.
It turns out the solution was easier than I thought. Just Cut and paste.
I selected the shapes I used, did a copy and then pasted into a new drawing. Visio was smart enough to know I was copying shapes that were part of linked drawing and asked.
“The pasted shapes were linked to data that is not in this document. Do you want to also paste the missing data source?”
A simple “No” solved my problem.
Now that I am off the rocks, I will continue working on the cruise demo.
I still have the problem file if the Visio team wants to figure out why it hung.

Enjoy…

John Marshall… Visio MVP Visio.MVPs.org

Written by johnvisiomvp

August 3, 2019 at 2:40 pm

Techniques for creating Visio Shapes

leave a comment »

Most Visio users barely scratch the surface when dealing with the product. I recently watched a video where a Visio expert dropped a shape on a page and then used the Text tool to create a label for the shape. All Visio shapes have a text block and there is a Text block tool if you do not like the positioning or orientation of the text, you can change it. So, why is that a big deal? Visio is a database of information and if you want to create a report on the Visio drawing, the label will not be associated with the shape, it will be a separate shape.
A lot of Visio users are unaware of the Shapesheet and can survive without that knowledge. The techniques I an going to show do not require using the shapesheet, but a little peak under the hood with a Shapesheet will help you understand what is going on.
Developer Mode If you are going to be creating shapes, you should turn Developer Mode on.
File -> Options -> Advanced -> (scroll to the bottom) Check mark  Run In Developer mode
or
File -> Options -> Customize Ribbon -> on the Main Tab Check mark  Developer
You will have access to the Developer ribbon with Operation commands and a few other goodies.
Shapesheet The shapesheet is a way to view the internal structures within a Visio drawing. In addition to a view of a shape, there are shapesheets to see some of the internals for the Visio page and the Visio document. The shapesheet is divided into sections and each section is a table of values or lists of rows of values. Most sections are unique, but the Geometry section may have several.
Image Source So, how do you create shapes from scratch to create a Visio drawing? First find a drawing you can use as a template that has the right proportions or dimensions. Should it be a vector or raster image? Vector would be nice, but sometimes it causes more problems than it is worth. what may look like a rectangle could be a set of four disconnected lines. I did a series of flags and the stars were actually triangles. Luckily Visio allowed me to select the star field and use the Union operation to simplify the stars. The result was a group of individual stars. Then there is the time taken to remove superfluous shapes. So, unless I get quick results with vector diagrams, I go with raster.
“Template” (old school definition) Visio will allow you to drop most image files into a Visio drawing, I then put them on a locked layer and use them as a template (old school definition) to draw the shapes with basic geometry shapes. I build up a collection of rectangles, circles and other basic geometries. With the Visio operations you can create some interesting shapes, but you have to plan the operations. Should you Union first or Fragment?
Scaling Visio is an engineering drawing tool and understands dimensions. When dealing with shapes with known dimensions, you need to be able to resize your “template” so it is the proper size. I have done this by adding a rectangle that has text that displays the rectangle’s height and width and placing it over something with a known dimension. Select the template and the rectangle and stretch (keeping the aspect ratio fixed). when the dimension in the text block matches the desired value, you have the right size. I have also written VBA code that sets the templates size by using two reference rectangles. One is set to a known distance on the template and the other is set to the actual dimension. The VBA code works out the ratio of the two rectangles and applies it to the template.
Basic Geometry shapes You can use the Pencil tool to create a shape, but it will be difficult to keep the lines straight and the angles of the line correct. It is far easier to lay out a set of overlapping rectangles and circles and then use the Union command to get the desired shape.
Gaps If you put two shapes adjacent, but not quite, you may get a gap between the shapes when you do a Union. Undo the Union and put a rectangle as a patch bridging the two shapes. The patch does not have to cover the full gap. It is not worth the time trying to get the patch perfect. Reselect with the patch and redo the Union. Rather than a gap you will have two fingers that can be easily fixed with the Pencil tool. Use the Pencil tool to select the corners of the fingers and delete. The Pencil tool can delete any other unwanted points.
Rounded Corners If you want a rectangle with rounded corners, you can draw a rectangle and then chose Line -> Line Options… ->and set the Rounding size. Then Developer ->Operations -> Union. This may not seem to do anything, but if you had looked at the shapesheet before and then after, the Geometry section would contain a RelMoveto and three RelLineTos, afterwards they would be interspersed with EllipticalArcTos and the Rounding setting in the Line Format would go from non zero to zero. You can do it to only some corners by duplicating the shape, align the two shapes Center and then Middle and just select the top shape and set the rounding on that. Select both shapes and do a Fragment. Delete the unwanted corners and then select the shape and the wanted corners and Union.
You can also create inside corners by placing a circle inside a larger square, centering them and then use lines to bisect.
Parallel Lines Having stripped shapes is common, making them is easier. Draw a line, duplicate it many times. Select the lines, align on center and then Distribute. You can then Join or group the lines.
Matching Curves  Trying to make matching curves is not easy. On one project I had to make a cylindrical shape that was intersected by a smaller diameter cylindrical shape. It was a container with a spout that went off at an angle. So, I created two rectangles and resized and positioned them appropriately. The smaller diameter cylinder overlapped the large diameter cylinder. I duplicated the smaller diameter cylinder and aligned the two copies to the same place. I selected the larger cylinder and a copy of the smaller diameter cylinder and did a Union. I then used the Pencil tool to remove the ends of the smaller cylinder from the large cylinder. What I was left with was what looked like the larger cylinder, but one of the side walls had two points at the location where the two cylinders intersected. Using the Pencil tool I was able to bow that section to make the intersection visible. I duplicated the larger cylinder and aligned them to be in the same place. I then took the copy of the larger cylinder with the smaller cylinder and did a Fragment. I then had a spout with a matching curve to the large cylinder. I then deleted the remaining part from the Fragment operation.
Groupies When shapes are grouped, a new shape is created and the selected shapes become sub shapes of the group shape.  Grouping is very useful for keeping subshapes together, but you can get carried away. When your shape is ready, you should go back through the shape and remove any non essential grouping. Actually, you probably should remove all groupings and select all the component shapes and group. Then add things like Shape Data and Control handles and Connection points. You may want to keep a backup copy of the shape with the groupings if you need to rebuild.
Connection Points The normal connection points handle standard situations, but what if you are creating a piece of electrical equipment and you want the connection points to be where the wires connect? Use the Connection Point tool.
Cleanup When you have finished your shape, you should remove all the Groupings and Creating a new Group of the parts. Then add Shape Data.
Almost Black My favourite technique is still Graham Wideman’s almost black. If a line or fill colour in a custom line patter or custom fill is black, it is replaced by the chosen foreground colour. If you want something to be black, it needs to be something that is almost black(255,255,25) like (254,255,255) or (255,254,255) or (255,255,254)

The next set of techniques in a followup article, will go into leveraging the shapesheet.
If you want to learn more about Visio shape developing, check out Chris’s Visio Guy website there are a lot of articles and forums to handle questions.

Enjoy…

John Marshall… Visio MVP Visio.MVPs.org

Written by johnvisiomvp

July 28, 2019 at 2:04 am

Posted in Shapes, Visio

Tagged with ,

Adding Shape Data to a series of new shapes

leave a comment »

I have been playing with Visio Visualization in Power BI and the first step is to create a Visio drawing. Basically it is a bunch of shapes, but I need to add Shape Data to the new shapes, basically the key that will link the shape to the row of data in Excel. I could select each shape and then set the shape name and create the shape data, but I am lazy, so…

Again VBA was useful.

So I used the following code to go through selected shapes, change the text on the current shape to “X” so I can see which shape I am about to change. The ShowChanges line makes the change visible.

I then prompt the user for the name they want to apply to the shape and use that to set the name of the shape. I also boost the font size so that it is more visible. I then go through and delete the shapes properties if they already exist so I can start with a clean slate. I then add the Shape Data field I will use as a key to the shape. The other fields will be added as Visio makes the data connections using the key. I then set the text for the shape to be the shape’s name.
I then deselect the shapes, so a new set of shapes can be selected.

Public Sub LoadCabins()
Dim Shpname As String
Dim vsoSelect As Visio.Selection
Dim vsoShape As Visio.Shape
Set vsoSelect = Visio.ActiveWindow.Selection
If vsoSelect.Count > 0 Then
For Each vsoShape In vsoSelect
vsoShape.Text = "X"
Application.ShowChanges = True
Shpname = InputBox("Enter the cabin number", "Cruise Line")
vsoShape.Name = Shpname
vsoShape.Cells("Char.Size").Formula = "=20 pt."
If vsoShape.CellExists("Prop.Cabin", 0) Then
vsoShape.DeleteRow visSectionProp, vsoShape.CellsU("Prop.Cabin").Row
If vsoShape.CellExists("Prop.Category", 0) Then
vsoShape.DeleteRow visSectionProp, vsoShape.CellsU("Prop.Category").Row
If vsoShape.CellExists("Prop.Type", 0) Then
vsoShape.DeleteRow visSectionProp, vsoShape.CellsU("Prop.Type").Row
If vsoShape.CellExists("Prop.Amenities", 0) Then
vsoShape.DeleteRow visSectionProp, vsoShape.CellsU("Prop.Amenities").Row
If vsoShape.CellExists("Prop.Connect", 0) Then
vsoShape.DeleteRow visSectionProp, vsoShape.CellsU("Prop.Connect").Row
iPR = vsoShape.AddRow(visSectionProp, visRowLast, visTagDefault)
vsoShape.Section(visSectionProp).Row(iPR).NameU = "Cabin"
vsoShape.CellsSRC(visSectionProp, iPR, visCustPropsLabel).FormulaU = """Cabin"""
vsoShape.CellsSRC(visSectionProp, iPR, visCustPropsType).FormulaU = "0"
vsoShape.CellsSRC(visSectionProp, iPR, visCustPropsFormat).FormulaU = ""
vsoShape.CellsSRC(vi7176sSectionProp, iPR, visCustPropsLangID).FormulaU = "4105"
vsoShape.CellsSRC(visSectionProp, iPR, visCustPropsValue).FormulaU=vsoShape.Name
Set vsoCharacters = vsoShape.Characters
vsoCharacters.Begin = 0
vsoCharacters.End = 5
vsoCharacters.AddCustomFieldU "Prop.Cabin", visFmtNumGenNoUnits
Debug.Print vsoShape.Name
Next vsoShape
ActiveWindow.DeselectAll
Else
MsgBox "You Must Have Something Selected"
End If
End Sub

Though this code can handle all the shapes at once, it is designed to handle smaller groups at a time. You do not want to accidently change shapes you did not intend on changing. In the process of creating the shapes, I did rerun the code several times.
So, this will help me populate a Visio drawing with data that Visio can use to link to an Excel spreadsheet and load extra data. I am in the process of writing the three articles that will explain the Visio visualization in Power BI demo I am planning on building. The first will be the creation of the Visio drawing and the considerations involved, the second will be lighting up the drawing in Visio using data connectivity and the final article will be using that Visio drawing in a Power BI dashboard.

Enjoy…

John Marshall… Visio MVP Visio.MVPs.org

Written by johnvisiomvp

July 24, 2019 at 2:33 am

Posted in Power BI, VBA, Visio

Tagged with , ,

Removing unwanted properties from a collection of masters

leave a comment »

In addition to cleaning up how the masters looked, I also had masters that contained user and custom (AKA Shape Data) properties that were no longer needed.

Again VBA was useful.

So I used the following code to

Public Sub CleanMasters()
Dim vsoMaster As Visio.Master
Dim vsoMasterCopy As Visio.Master
Dim vsoShape As Visio.Shape
For Each vsoMaster In ActiveDocument.Masters
If vsoMaster.Type = 1 Then
Set vsoMasterCopy = vsoMaster.Open
Set vsoShape = vsoMasterCopy.Shapes(1)
If vsoShape.CellExists("User.Class", 0) Then vsoShape.DeleteRow visSectionUser, vsoShape.CellsU("User.Class").Row
If vsoShape.CellExists("Prop.Link", 0) Then vsoShape.DeleteRow visSectionProp, vsoShape.CellsU("Prop.Link").Row
vsoMasterCopy.Close
End If
Next vsoMaster
End Sub

For Custom Properties (AKA Shape Data), replace “User.” with “Prop.” and use the right name of the property and remember the section name is visSectionProp rather than visSectionUser.

Enjoy…

John Marshall… Visio MVP Visio.MVPs.org

Written by johnvisiomvp

October 19, 2018 at 9:48 pm

Posted in Shapes, Uncategorized, VBA, Visio

Tagged with , ,

Clean up Visio Masters

leave a comment »

Anyone who has created Visio masters may have noticed that the masters may require cleanup. When selecting a master to edit, you may notice that the edit window seems to be empty and you  will need to center the image to bring it back in view. Other times, the shape is bigger than the page it is sitting on in the edit window. So, a little editing on the page shapesheet is required, either the values or grabbing the sides and readjusting.

I am not sure whether the cleanup actually makes a different, but it is less of a distraction when editing the masters.

Recently I was faced with the task of doing this cleanup to more than 500 shapes, so VBA to the rescue.

With a little research, I came up with

Visio.Master.ResizeToFitContents

So I used the following code to

Public Sub CleanMasters()
Dim vsoMaster As Visio.Master
Dim vsoMasterCopy As Visio.Master
Dim vsoShape As Visio.Shape
For Each vsoMaster In ActiveDocument.Masters
If vsoMaster.Type = 1 Then
Set vsoMasterCopy = vsoMaster.Open
vsoMasterCopy.ResizeToFitContents
vsoMasterCopy.Close
End If
Next vsoMaster
End Sub

So far this seems to work. I did notice that the page has a margin rather than being the same size as the master. No big deal. The key factor is that it is consistent.

Thanks JG for being a sounding board.

Enjoy…

John Marshall… Visio MVP Visio.MVPs.org

Written by johnvisiomvp

October 19, 2018 at 9:24 pm

Posted in Shapes, Uncategorized, VBA, Visio

Tagged with , ,

Colour My World Part II

leave a comment »

Visio does not handle rows well and lists easily in the shapesheet, you can not do basic things like sorting the rows. So I use my favourite list handling app, Excel. When I need to manage large amounts of shape data, I manage it in Excel and then use VBA to remove the old shape data and populate the shape data section from Excel. I also use Excel to handle arrays within the shape data so the various lists remain in sync.

Here is the earlier experience Colour My World

On one of my project I also had to have the shape data in sync with an xml file. With Excel, that was easy. Just add a new column for XML and populate it with a formula that combined the column headers as part of an XML tag with the correct data. It did require a bit of finesse getting an XML column into a single string, but even there I was assisted by a Word VBA macro to remove the extraneous tabs.

In the first blog I talked about handling a handful of colours. I unfortunately got carried away and started to search the net for more colours that had names. The result was that I had more than 4,700 colours. There were a number of RGB values that had several names and several names that had multiple RGB values. There was also a few lists that could stand on their own, Lego colours, HTML colours, Crayola colours, Wikipedia colours, ColorHexa and Pantone Colours. Most of the Pantone colours did not have common names and Crayola has changed the names of some the crayons over the years. I even found some VBA code that would generate a worksheet of the colour spectrum showing the RGB values at various frequencies. Some of the lists also included hyperlinks to more information. The Colours spreadsheet contains a list of all the colours, but not their hyperlinks.

In the search for lists of colours and names, sometimes I got names and RGB values, sometimes they were names and RGH hex values and even times with there was a name and sample but no values. Luckily the colour samples, when copied into a worksheet. The colour samples became the cell fill colour. So I needed a toolbox of VBA code and cell formulas to manage the list.

The aim was to get a worksheet with a column for the colour name, columns for the R,G&B values and a column for the hex of the RG&B value. I also wanted to colour the cells with the hex value as a sample of what the colour looks like.

So I used the following code to extract the RGB values from the cells fill colour.

Function getRGB(rCell As Range, Optional opt As Integer) As Long
' =getRGB(D14,1)=getRGB(D14,2) =getRGB(D14,3)
Dim C As Long
Dim R As Long
Dim G As Long
Dim B As Long
C = rCell.Interior.Color
R = C Mod 256
G = C \ 256 Mod 256
B = C \ 65536 Mod 256

If opt = 1 Then
getRGB = R
ElseIf opt = 2 Then
getRGB = G
ElseIf opt = 3 Then
getRGB = B
Else
getRGB = C
End If
End Function

If you want to recreate the hex value of the RGB code, use
="#"&RIGHT("00"&DEC2HEX(B2),2)&RIGHT("00"&DEC2HEX(C2),2)&RIGHT("00"&DEC2HEX(D2),2)

The following code will set the fill colour of a column based on the R, G and B values in other columns.

Public Sub ColourCells()
Dim LRow As Long
Dim rCell As Range
Dim rng As Range
Dim SH As Worksheet
Dim Threshold As Integer

Set SH = ActiveSheet
With SH
LRow = .Cells(Rows.Count, "B").End(xlUp).Row
Set rng = .Range("B2:B" & LRow)
End With
For Each rCell In rng.Cells
With rCell
.Offset(0, 3).Interior.Color = RGB(.Value, .Offset(0, 1).Value, .Offset(0, 2).Value)
End With
Next rCell
End Sub

What I noticed was that the text in the colour sample did not show up when the colour was dark. So I added another column called Obverse to indicate that with that colour, the text colour must be black or white. I did change the code in the ColourCells macro to set the value for Obverse and also apply it to the text. The results were okay. The first attempt set the value if the R,G&B values were all less than a certain threshold. Since this was done in code, I will take more time tuning the values.

One of the things I was trying to do with the list was to get the colours sorted in a pleasing manner. Initially I tried to sort by RGB, but there was a banding effect as the values of RG&B changed, especially when a value jumped from 255 to 0. I also tried to match the spectrum as can be seen in the Spectrum worksheet. It is a pleasing result, but it does not map to the named colours. I also tried mapping to the Hue with some results, but again there were banding issues. I even tried a fudge by grouping values together. Again,  there was only slight improvements. So for now I am leaving sorting alone.

I could leave the lists as a mixture of values and formulas, but I was concerned with performance from all the recalculations. So all the columns were copied to new columns  and pasted as values. 

I have asked one of the Excel MVPs to host the workbook. I will update this post when it is live.

Enjoy.
John Marshall… Visio MVP Visio.MVPs.org

Written by johnvisiomvp

November 14, 2017 at 11:05 am

Posted in Excel, Shapes, Uncategorized, VBA, Visio

Tagged with , ,