![]() |
![]() ![]() |
Pearls from the auld Scotsman
|
Custom Properties in Visio: Brilliant!Part IAdding custom properties to your shapes in Visio is the ultimate in intelligent technical drawings. Dave shows how to use this powerful facility in Visio in Part I and how to exchange data between custom properties and Excel in Part II. Ceuid Mile Failte! One hundred thousand welcomes. Ive had an opportunity to chat with many of you since I "pointed ye a doon the lane" to making better use of Visios Dynamic Connectors. Your comments and feedback were grand and as always are very welcome. One of the comments that I received was that I might want to use Visio to add a wee bit o code and more examples to my article. Weel lest ye think I dinnae listen code and examples you will most certainly have! This month I want to spend a bit of time talking about Custom Properties in Visio SmartShape Symbols. Im going to take a look at how end-users can (gasp) actually open a shapes ShapeSheet and add their own custom properties to any SmartShape symbol, and then use a wee bit of VBA to pass the information in Custom Properties to a Microsoft Excel Spreadsheet. I know that you brilliant lads and lassies out there already know about the Custom Properties Editor in Visio. This is found by selecting Tools > Macro > Custom Properties Editor. However, this tool requires that the shape in question be an instance of a Master, or a Master itself. I also know that you have all used the Property Report Wizard found by selecting Tools > Property Report However, it is my fondest desire to make each of you into Visio super-users and to that end I am going to immerse you in the ShapeSheet and into a modicum of VBA code as well. Aricht then lets begin by adding a Custom Property to a shape. We will start by dragging out a rectangle onto the page of a new document. To do this, begin a new drawing in Visio based on Blank Drawing.VST. A new blank drawing with no stencils open should be on your screen. Next select the Rectangle tool from the Standard Toolbar. Click on the page, hold and drag out and release to create a rectangle of any indeterminate size. Now, heres the task that we are going to tackle: We are going to add three (3) custom properties to this shape, the first to set the shapes width, the second to set the shapes height and the third to determine the shapes text. By default this rectangle does not have any Custom Properties associated with it. You can prove this to yourself by selecting the shape, right-clicking on the shape to bring up its short-cut menu and selecting Shape > Custom Properties Notice the error message/dialog that appears. It is telling you "No custom properties exist." Here is where we shall begin to remedy this situation. Click the OK button to clear the Message Box. Now, with the shape selected, Select Window > Show ShapeSheet. You should now see two windows open. One (most probably the top) will still be your drawing page, the other will be the ShapeSheet for the selected shape. A word of warning here If you do not see a section title in the ShapeSheet called Geometry 1, you most probably did not have the rectangle shape selected prior to requesting the ShapeSheet. In that case you are viewing the ShapeSheet for the page. In this particular case, that is not what we had intended. If that is so, close the ShapeSheet window and select the rectangle shape and then select Window > Show ShapeSheet. As you look at the ShapeSheet, you will see several sections, however we need to add a Custom Properties section to our ShapeSheet since it currently has none. We will do this by first ensuring that the ShapeSheet window is active and then selecting Insert > Section This will bring up a dialog listing all of the available sections which can be added to a ShapeSheet. Check the box next to Custom Properties and then click the OK button. Note that a new Custom Properties section has been added to your ShapeSheet. It should appear directly above the Geometry 1 section. Additionally a first Custom Properties row has been inserted into the Custom Properties Section. The name of the first row is, by default, Prop.Row_1. Not very descriptive, I give you. However, we will remedy that shortly. Im going to "tak a wee stroll" through each of the cells in a Custom Property row and explain what each one is for and what information we will need to fill in to take care of the properties that we want to add to our shape. We will work through them from left to right. The First Cell is the Row Name Cell. This is the actual name of the Custom Property row that will be used for all ShapeSheet and programmatic references. This row name is always prefaced with "Prop Dot" as in "Prop." followed by the name you wish to assign to that row. We noted that by default, this row got called Prop.Row_1. Since the first property that we want to add deals with the width of the rectangle, we are going to change this cell name to "Prop.Width". To accomplish this, click into the Row Name cell, the cell with the words "Prop.Row_1" in it. Type in the word "Width" and press the enter key. Note that the cell is now changed and reflects the new value of "Prop.Width". The rules for the naming of a Custom Property row are: up to 31 characters, must contain only letters, numbers and underscores, and must contain no spaces. The next Cell is the Label Cell. This is the text which will appear to the left of the text edit, list or combo-box control in the Custom Properties dialogue box. Actually these controls are the Visio equivalent and are listed this way in this article for convenience purposes. Since we want to let the user of this shape know we are interested in Width information we will change the value of this cell to "Rectangle Width". To accomplish this, click into the Label Cell, Type in the words "Rectangle Width" and press the enter key. Note that the cell is now changed and reflects the new value of "Rectangle Width". This field is a Text string and can therefore include spaces. The next cell to the right is the Prompt Cell. This is the text that will appear at the lower area of the Custom Properties dialogue box when the user selects that particular property to edit. Since we want to assist the user in determining what should be entered in this particular Custom Property cell we will need to create a prompt applicable to the task at hand. Since there are generally three types of controls, text edit, list, or combo-box, we need to structure our prompt accordingly. We are going to allow the user to freely enter any value into a text edit box and therefore our prompt will be "Enter a width for the selected Rectangle.". If we had a fixed list of values we might have prompted, "Select a width for the selected Rectangle", or if we were utilizing a list of choices with the additional ability to freely enter values as in a combo-box, we might have prompted, "Enter or select a width for the selected Rectangle". To change this cells value, click into the Prompt Cell, type in the words "Enter a width for the selected Rectangle." And press the enter key. Note that the cell is now changed and reflects the new value of "Enter a width for the selected Rectangle". This field is a Text string and can therefore include spaces. The next cell in order is the Type Cell. This cell determines the data type of the information to be presented and stored in this Custom Property row. Under Visio 5.0 there exist eight (8) available values for this cell. They are:
Since we have determined that we will allow the end-user to freely enter any value into the Width Custom Property, and since we know that we are talking about a numeric distance for the width value, we will select option value two (2), Numeric. To change the cells value, click into the Type Cell, type in the number 2, and press the enter key. Note that the cell is now changed and reflects the new value of 2. This field is an integer value. Following the Type cell, the next cell is the Format Cell. This cell controls both how the value will appear when the user views a previously filled in value and the structure of lists to be primed into lists and combo-boxes. In our case we want to ensure that the value that the user enters will be held as a distance numeric value. This numeric formatting is held as a string and is very similar to Microsoft Excel format strings. We will enter the string "0.##u" which specifies that we have a placeholder for whole units, and available but truncate-able placeholders for decimals of units and that the units should be displayed. To change the cells value, click into the Format Cell, type in "0.##u" and press the enter key. Note that the cell is now changed and reflects the new value of "0.##u". This field is string value. The next cell in sequence is the Value Cell. This is the cell which holds the actual value the user enters from within the Custom Properties Dialogue box. This cell can be "primed" to hold a default value such that when the user enters the dialogue the value is already present. In our case we want to set up a default value which is reasonable so that if the user clears the dialogue without making any changes, the rectangle will be a usable size. The value that we will use will be "2 in.". To change the cells value, click into the Value Cell, type in "2 in." and press the enter key. Note that the cell is now changed and reflects the new value of 2 in. This field is a distance numeric value. The cell following the Value cell is the Sort Key Sell. This cell determines the order that each row in the Custom Properties Rows appear in the Custom Properties dialogue box. These are actually strings equating to the numbers "1" through "n", where "n" is the count of the last row number in the Custom Properties section of the ShapeSheet. If this cell is left blank, Visio will automatically order the items in the dialogue in the order that they appear in the ShapeSheet. Lust because we want to be explicit (have ye eer known a Scotsman who wasnae exactin?) we will assign this row the number "1". To change the cells value, click into the Sort Key Cell, type in "1" and press the enter key. Note that the cell is now changed and reflects the new value of "1". This field is a string value. Moving right, the next cell is the Invisible Cell. This cell determines whether the particular Custom Property row will even appear in the Custom Properties Dialogue box or not. This cell has two potential (well three actually) values: 0 which means FALSE and therefore it WILL appear in the dialogue, non-zero (usually 1) which means TRUE and therefore WILL NOT appear in the dialogue, and "no Formula" which is the same as 0. We definitively want our Custom Property to be visible in the dialogue and therefore we will explicitly set the value of this cell to 0. To change the cells value, click into the Invisible Cell, type in "0" and press the enter key. Note that the cell is now changed and reflects the new value of "0". This field is an integer value. The last cell in the row is the Ask Cell. This cell determines whether the particular Custom Property row will appear in the Custom Properties Dialogue box when the Shape is dropped from a Stencil, or instanced as a copy of an existing shape. All subsequent appearances are determined by the value in the Invisible Cell. This cell has two potential (well three actually) values: 0 which means FALSE and therefore it WILL appear in the dialogue on initial showing, non-zero (usually 1) which means TRUE and therefore WILL NOT appear in the dialogue on initial showing, and "no Formula" which is the same as 0. We definitively want our Custom Property to be visible in the dialogue when we instance the shape and therefore we will explicitly set the value of this cell to 1. To change the cells value, click into the Ask Cell, type in "1" and press the enter key. Note that the cell is now changed and reflects the new value of "1". This field is an integer value. Whew!! Seems like a wee bit of work to set that up? Well not really. Once you work your way through it the first time, it will go quite quickly for each subsequent row entry. To add another row to the Custom Properties section of the ShapeSheet, ensure that your cursor is planted in a cell within the Custom Properties section and select Insert > Row. This will add a new row to the section with a default row name. Now you can begin to edit the cells just as you did above. Ive listed a table below of each row and their values for you to complete your work for each of the three Custom Properties Rows in this ShapeSheet. Check the table in a new window. Click here Well, hopefully you are done with this wee chore and you are ready to accomplish the last bit of ShapeSheet work required to make all of this perform properly. We will next link the Prop.Width and Prop.Height cells to the actual Width and Height cells in the Shape Transform section of the ShapeSheet. To accomplish this, click into the Width Cell in the Shape Transform Section of the ShapeSheet. Press The "=" key. This erases the existing formula. Next click into the Prop.Width cell and then press the enter key. Note how the rectangles width just shifted and became 1 2 inches in width. Next move up to the Excel-like edit line above just below the toolbars and click into the edit line. Edit the line so that it contains the following complete formula: "=GUARD(Prop.Width)". This addition of a GUARD() Function around the reference to the Custom Property cell ensures that the user will not blast the custom formula away by "tugging on the green things", adjusting the shape by its sizing handles. Repeat this same process with the Height Cell in the Shape Transform Section, mapping it to the Prop.Height cell in the Custom Properties section and then completing the process by wrapping a GUARD() Function around it so that it reads "=GUARD(Prop.Height"). Almost their lads an lassies! The last thing that we need to do is link the shapes text to the Text Custom Property Row. This we will do from the Text Fields Dialogue. Close the ShapeSheet Window. With the rectangle shape selected, select Insert > Field. This will bring up the Text Field Dialogue box. In this dialogue you will see three columns. In the first column, find and select the "Custom Properties" entry. In the second column, find and select the "Rectangle Text" entry. In the third and last column, find and select the "Normal" entry. Click the OK button. Congratulations!!! You have just made a wonderful parametric shape with definable width, height and text. To try your shape out, select the shape, hold your control key down and drag out a copy and release. Note that when you release the mouse button, your shape is copied, and the Custom Properties dialogue appears prompting you to fill in values for Height, Width and the Text. When you click the OK button, the shape takes on the new size constraints set in the Custom Properties Dialogue as well as the shapes text taking on the value from the same dialogue. You can edit these values at any time. Simply select the shape, right-clicking on the shape to bring up its short-cut menu and select Shape > Custom Properties The dialogue will reappear for you to edit at will. You can add Custom Properties to ANY Visio SmartShape and store whatever information you wish in them. To show the power of accessing this information, Part II of this installment embarks on the process of creating a small VBA application to extract the Height, Width and Text information out of the Custom Property cells and pass them off to an Excel spreadsheet. As ye might o guessed, you will need Excel to be present on your wee computer for you to test all of this out. Take a spell now and absorb your new-found skills. I know ye'll not rest fer long and soon be back to get your teeth into Part II. "Haste ye back." Dave "The Auld Scotsman" Edson
|
|
|
Copyright © 1998-2007 DBM & others | Disclaimer | Privacy | Re-publication | Trademarks | Webmaster | Home |