johnvisiomvp

Life with Visio and other Microsoft Toys!

I need con text.

leave a comment »

I was looking through blogs and documentation on the Visio shapesheet and though the author did a good job, sometimes the point was lost because they used screen grabs of the shapesheet. The Visio shapesheet is a busy place and highlighting the key points is not easy. So, I created a set of Shapesheet section shapes that were based on an Excel spreadsheet. The text in the cells is fully editable, so it can be coloured to highlight a cell or increased transparency to deemphasise. Each section is a spate shape, so irrelevant sections can be excluded.
The next step is to populate the shapes with real data. I did copy real dat ato make the shapes, but it would be nice to point the code at a real shapesheet, Doc, page or shape.
One thing I came across was that Visio is heavy on enumeration, so you need to fill in the labels with real words, a list of numbers just will not cut it. Using arrays of text is one way, but the enumerations are not sequential, there are large gaps. So, I went with a Dictionary. The key is a tag followed by the enumeration number. In this case, these are some of the Geometry row names.


Dim MsgDict As Scripting.Dictionary
Sub example()
Dim ky As Variant
Set MsgDict = CreateObject("Scripting.Dictionary")

Call LoadDictionary

For Each ky In MsgDict.Keys
Debug.Print ky, MsgDict(ky)
Next ky
End Sub

Sub LoadDictionary()
Set MsgDict = Nothing

Set MsgDict = CreateObject(“Scripting.Dictionary”)

MsgDict.Add Key:=”Geo139″, Item:=”LineTo”
MsgDict.Add Key:=”Geo140″, Item:=”ArcTo”
MsgDict.Add Key:=”Geo141″, Item:=”InfiniteLine”
MsgDict.Add Key:=”Geo143″, Item:=”Ellipse”
MsgDict.Add Key:=”Geo144″, Item:=”EllipticalArcTo”
End Sub

Enjoy…

John… Visio MVP in xaisle
Visio.MVPs.org

Written by johnvisiomvp

January 28, 2020 at 5:23 pm

Posted in Uncategorized

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

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 , ,