Skip to main content

Visio Virtual TS Blog

Go Search
Home
Swimlane Timeline
Visio Virtual TS Blog
  

Documentation Share Site > Visio Virtual TS Blog
ShapeSheet Programming - Part 14

ShapeSheet - Chapter 47: Calling Automation Routines From Within ShapeSheet Cells

As the final chapter in this text, I wanted to briefly discuss a little about calling Subroutines and Functions from an Automation Controller from within ShapeSheet Cells. In Chapter 42 above, I stepped you through the process of creating a “Notes” taking application utilizing the Data 1 Field of a SmartShape symbol and a little VBA as an automation controller. As part of that implementation, I showed you that placing a Function in the Actions Section Action Cell for an Action Row could call the running of an automation routine, in this case, a small VBA Subroutine. Let’s examine that Formula again:

“=RUNADDON( “CallCommentsDialogue”)”

The Function that we placed in the Cell was the RUNADDON() Function. This Function has one mandatory argument ant that is the name of the Subroutine as a quoted string. By definition this can be either (1) a VBA Public Subroutine in the current project, (2) a VBA Public Subroutine in another module in the current project, (3) A VSL Add-On registered with your machine’s copy of Visio, or (4) an executable written in any Automation controller such as Visual Basic 6.0, Visual Basic.NET, or C#.NET.

Alternates to RUNADDON() are available to you as well. RUNADDONWARGS() allows you to call automation that requires that arguments be passed to it as (1) a VBA Function,  (2) an entry point into a Visio VSL, or (3) an executable capable of accepting arguments when called. RUNMACRO() allows you not only the same functionality as RUNADDON(), but allows a second optional argument which is the name of a valid Project. This is useful if one Visio document contains code you want to call from another document.

The preferred new all encompassing Function to use is the CALLTHIS() Function It acts as an amalgam of the RUNADDONWARGS() and RUNMACRO() Functions. You can make any valid call to any routines in any project in the Visio session with or without arguments (subject to their particular requirements of course).

Appendix 1 : Additional References

Visio Webcasts Website

http://www.microsoft.com/events/series/visio.mspx

Microsoft Office Visio Website

http://office.microsoft.com/en-us/visio/default.aspx

Visio MSDN Website

http://msdn2.microsoft.com/en-us/office/aa905478.aspx

Visio TechNet Website

http://www.microsoft.com/technet/prodtechnol/visio/default.mspx

Visio Insights Weblog

http://blogs.msdn.com/visio/

Visio MVP Weblog

http://msmvps.com/blogs/visio/default.aspx

Visio MVP Website

http://visio.mvps.org/

Chris Roth Weblog

http://www.visguy.com/

Bill Morein (Microsoft (former) Visio Development Team Lead) Weblog

http://blogs.msdn.com/wmorein/

 

Appendix 2: Visibility.biz

Visibility.biz is an award-winning consulting group with leading experts on Microsoft® Office Visio® offering education and consulting services to help organizations best leverage their Visio investment.
 
Visibility.biz delivers Visio Best Practice Presentations and tailored multi-day Visio hands-on End-User and Developer Training.  In addition, Visibility.biz consultants can help you extend Visio beyond the box for company-specific Visio solutions and visualizations, and we will work with your in-house developers to provide them the training they need for solution maintenance and support.

Visibility.biz was founded by Daniel Rohwer and David Edson who crisscrossed paths around the world throughout their early careers evangelizing computer based visualization tools while working for Visio Corporation, Microsoft Corporation, and Autodesk 3rd Party Partners. In 2005 they joined forces and founded Visibility.biz to focus exclusively on the growing need they saw in the market for custom Visio solutions and Visio education.

Visibility.biz is affiliated with Milestone Consulting Group, Inc., a company founded in 2002 that provides best of breed Enterprise Project Management products and services based solely on Microsoft solutions. Visibility.biz helps Milestone provide clients with rich presentation and automated diagramming tools that dovetail’s with the business process improvement and enterprise-wide project management tools and techniques Milestone already deploys. Milestone Consulting Group is a Microsoft Gold Certified Partner with an Information Worker Competency.

Consulting

Visibility.biz will work together with you to quickly understand your data visualization and business diagramming issues and needs, envision possible Visio solutions, and identify the best approach for implementing and developing a solution.

Education

Visibility.biz offers 1-day and multi-day hands-on educational services to organizations wanting to maximize their investment in Visio and empower their information workers with the training they need to succeed and grow professionally.

Presentations

Get a higher return on your Visio investment with tailored fast paced 3-hour Visio core and advanced lectures that quickly illustrate best practice usage and business solutions that are at the heart of all Visio versions.

Contact

Visibility.biz
Mr. Daniel Rohwer : CEO / Director of Business Development
Mr. David A. Edson, M.Arch.: CTO / Director of Consulting Services, Microsoft Visio MVP

• 4666 Slater Road, Eagan, MN 55122
• e-mail: info@visibility.biz
• tel: (+01) 952.223.1293
• web:
http://www.visibility.biz

 

 

ShapeSheet Programming - Part 13

ShapeSheet - Chapter 46: What do Visio 2007 Pivot Diagrams do to ShapeSheets?

Earlier I discussed a new type of Visio diagram under Visio 2007. That diagram type is a Pivot Diagram.  Most of you are already fully familiar with Excel Pivot Tables. I find Excel’s Pivot Tables very powerful, yet, somehow, a real struggle to get sorted out and set up the way you want to “slice and dice” the data in normal tables with any speed and agility. Visio’s Pivot Diagrams borrow the concept of Drill Down and Roll up from Excel Pivot Tables but are light-years easier to work with.

When you create a Pivot Diagram, Visio creates a specialized SmartShape symbol as a “Top Level Node” in your diagram. Keep in mind that this is just a SmartShape symbol, like any other SmartShape symbol, and as such should not be the least intimidating to you. If you “drill in” a level, you expand the diagram by Visio placing another set of node SmartShape symbols equating to the category of expansion. For Example you might have a top level node which represents the entire company. By Right-clicking on that top level node and selecting the category Department, you create a series of node SmartShape symbols which are connected by Dynamic Connector SmartShape symbols up to the top level node. This expansion looks very much like Directors reporting up to the CEO in an organizational chart. I have illustrated this below:

These Departments may be further broken down by Managers, as partially illustrated below:

Let’s look at this a bit closer and with the Breakdown SmartShape symbols (the smaller criteria symbols) being shown as well as empty value nodes being hidden as well:

If we examine the ShapeSheet of the Breakdown SmartShape symbol with the Text reading “Department” we will see that a User-defined Cell Row is listed as “User.visDDParentShape” and has a Value of 2 in its Value Cell.

If we Right-Click on the top level node and select Format > Special from its Context Menu we can see that its Sheet.[n] ID is 2, as in Sheet.2.

If we look at the ShapeSheet of the SmartShape Node symbol with the header “Finance” showing, we will find a User-defined Cell Row listed as “User.visDDParentBDShape” and having a Value of 12 in its Value Cell.

If we Right-Click on the breakdown SmartShape symbol and select Format > Special from its Context Menu we can see that its Sheet.[n] ID is 12, as in Sheet.12.

We therefore are able to query the SmartShapes via their ShapeSheet and ascertain a SmartShape symbol which is the child or parent of any other SmartShape symbol.

However, what seems to be missing from any of the node SmartShape symbols or the breakdown SmartShape symbols is any of the data we linked to when we ran the Pivot Diagram Wizard. The wizard, by the way, is identical to the wizard we stepped through when we used the Visio “Link Data to Shapes…” Wizard. You would have assumed since you were pointing to the same data source, and that since Visio fully understands the structure of the hierarchy based upon data in the data source, that you should be able to view the data for each record attached as Shape Data to the appropriate SmartShape symbol. The current Pivot Diagram Solution does not hold the record data for each record; it simply holds an understanding of the structure. This is to ensure that you can quickly and easily “drill down” and “roll up” criteria for the Pivot. Keep in mind that you can always, subsequent to expanding your Pivot in the manner that makes the most sense to you, use the “Link Data to Shapes…” Wizard to re-link to the same data source and either manually or automatically link specific nodes to specific data records. Then changes to data in the data source can be refreshed in the Shape Data with a simple Right-Click on the External Data Table and selecting “Refresh” from the context menu.

By Right-Clicking on any Node in the Pivot Diagram you can select Apply Shape… from the Context Menu. The Dialog that appears allows you to choose a SmartShape symbol (Bitmap or Visio Vector-based) and apply that SmartShape symbol to the node. The node “box” is actually just a Data Graphic and, by default, the node itself is not shown. Applying a Shape is actually associating the Data Graphic with a SmartShape symbol that has geometry rather than not being displayed. Be aware that in addition to the two “default” collections of SmartShape symbols to apply using the Apply Shapes… utility, that you can also select a SmartShape Master from any additional open Stencil in your Diagram’s workspace.

 

ShapeSheet Programming - Part 12

ShapeSheet - Chapter 44: Visio 2007 – The New Data Connectivity

In January 2007 Microsoft released the latest version of Microsoft Office Visio. Code named Visio 12, this version of Visio brought about three new feature sets to the product: Data Linking, Data Graphics, and Data Refresh. It also debuted an entirely new diagram type based upon connectivity with external data: Pivot Diagrams.

The purpose of this chapter is not to cover every use case scenario for the new Data Linking, but rather to cover how the data linking affects the ShapeSheet and how you can leverage this connectivity in your solutions.

The process of linking with an external data source under Visio 2007 is far easier than it has been in the past. The linkage is essentially a two step process. I will step you through the sequence of actions necessary to connect a SmartShape symbol with a record in an external data source utilizing the new Data Linking within Visio 2007. You will see that this is actually FAR easier than the older Database Wizard (which, by the way, still exists under Visio 2007). Keep in mind that this linkage is uni-directional; from the data source to the SmartShape symbol. Here is how it works:

Step One – Connect External Data Source to the Visio Drawing as a whole.

From the Visio 2007 Data Menu select Data > Link Data to Shapes… This will show the following Wizard Opening Screen:

In this opening screen you select the particular class of data source that you wish to use.  Note that you can link to (a) An Excel workbook, (b) an Access database, (c) a Windows SharePoint Services list, (d) a SQL Server database, or ANY OLEDB or ODBC data source. For ease of example, I will connect to an Excel workbook. Ensure that the “Microsoft Office Excel workbook” Radio Button is selected, then Click the “Next >” Command Button to advance to the next screen.

In this screen of the Wizard you are asked to either type in the complete path and name to a data source, select a previously used data source from the Drop-Down list, or use the Browse… Command Button to browse to, and select the data source. I am going to browse to a known Excel workbook, select it in the File dialog, and Click the OK Command Button. This will return the named data source into the listing as shown below:

Click the “Next >” Command Button to advance to the next screen.

You are now asked to select the range of the data within the data source. If you are working with an Excel workbook and your data is on the first worksheet in a traditional column/row format with the first row containing the field names, you can simply Click the Next Command Button to advance to the next screen. If your data is not necessarily as properly structured, you can use the Select Custom Range… Command Button to organize your data. When you have your data structure properly set and the name of your data range is shown in the range list, Click the “Next >” Command Button to advance to the next screen.

In this screen you have the ability to filter on the Columns (fields) you wish to include or exclude by Clicking on the “Select Columns…” Command Button and Checking and un-Checking the appropriate Check Boxes.

You also have the ability to filter on the Rows (records) you wish to include or exclude by Clicking on the “Select Rows…” Command Button and Checking and un-Checking the appropriate Check Boxes.

I am going to include all Columns and Rows (the default). Click the “Next >” Command Button to advance to the next screen.

You are now asked to select a field with unique values to use as the Primary Key for the linkage. Visio 2007 will scan your data and look for this field automatically and will pre-check a field name as its suggestion. If this is acceptable you can Click the “Next >” Command Button to advance to the next screen. If not, you can switch the key field by Checking and un-Checking the appropriate field and then Click the “Next >” Command Button to advance to the next screen.

To complete the wizard, Click the Finish Command Button. A new data table will be displayed in the Visio environment as shown below:

This completes the first step. You have successfully attached the external data source to the Visio Diagram. While it is grand that you can see every attached record and field, it is less than useful if the data cannot be directly linked to individual SmartShape symbols. This, we will do in Step Two.

Step Two – Link the External Data Source Record to a specific SmartShape symbol in the Visio Diagram.

Now that we have external data attached to the Diagram as a whole, the second, and final, step is to link the data directly to individual SmartShape symbols. There are actually two methods that can be employed to set this Data Linkage: (a) Manual, and (b) Automatic.

I’m going to cover manual linkage first. While a bit more cumbersome than automatic, manual linkage requires no assumptions and no pre-defined Shape Data fields. To manually link a SmartShape symbol to an external record attached and shown in the External Data table in the External Data window, simply (a) select the SmartShape symbol you want to link to the external data, (b) select the record to be linked in the External Data table, and (c) Click, Drag, and Release the record on to the face of the selected SmartShape symbol. Note that when you drag your mouse cursor over the selected SmartShape symbol, Visio outlines the symbol with an aqua box to indicate that the linkage is taking place. This outline disappears as soon as you release your mouse cursor. When the linkage is complete, Visio automatically associates a default Data Graphic with the newly linked SmartShape symbol (more about Data Graphics in a moment).

In order to establish an automatic linkage between the external data source as shown in the external data window table, and a SmartShape symbol,  there MUST be a pre-established Shape Data field in the SmartShape symbol with the IDENTICAL name in BOTH the external data source and the Label field of the Shape Data Row in the Shape Data Section of the ShapeSheet of the SmartShape symbol. This is the matching key that the Link Data to Shapes… Wizard will use to establish a one-to-one correspondence between the record and the SmartShape symbol. To facilitate this for our demonstration purposes, I will create an “Employee” Shape Data Field in the SmartShape symbol. I will not illustrate this process, as you are, I am already certain, quite capable and proficient at this task. Once the field has been established in the SmartShape symbol we can now run the Automatically Link… Wizard. You do this by selecting “Automatically Link…” from the Data Menu in Visio in the Drawing context. When shown the opening screen of the wizard looks like that shown below:

We want to link every possible SmartShape symbol to every corresponding record, so we will select the “All shapes on this page” Radio Button and then Click the “Next >” Command Button to advance to the next screen.

Here we match the name of the Data Column with the Name as entered in the Label field of the Shape Data item. Use the Drop-Down lists to map the Data Column Name and the Shape Field Names such that they are the same. Wherever there is a match between the data in the record in the external data source for the Employee field, and the entry in the Value in the Shape Data item, Visio will automatically establish a linkage between these two objects. Click the  “Next >” Command Button to advance to the next screen.

The final screen of the Wizard lists your decisions as you have progressed through the Wizard. Here we see that we are linking to (if a match exists) all shapes on this page, we will replace any existing links is the names are exactly the same, and only link where the fields Employee and Employee contain exactly the same values. Click the “Finish” Command Button to close the Wizard.

Note, again, that the default Data Graphic has been applied. Note also that a small Chain Link symbol has appeared next to the record in the External Data Source Table in the External Data Window. This is your visual clue that the automatic data link was successful.

So… now that the two step data linkage has been completed, just what changes have been made to the ShapeSheet of the SmartShape symbol which is now linked? Several changes and additions have been made. Keeping in mind that I began with a simple rectangle SmartShape symbol and that I only added a single Shape Data Row to establish the automatic link, I will describe those Sections, Rows, and Cells added or modified as a direct result of the Wizard. I will detail these for you below.

Firstly, Visio has added both User-Defined and Controls Sections to the ShapeSheet for the Rectangle SmartShape Symbol. Had we not already established a Shape Data Section when we created our Shape Data field for automatic linkage, Visio also would have created the Shape Data Section and populated a row for each data field in the external data source.

 

User-defined Cells Section

Row 1

Name: visDGDefaultPos

Value: =PNT(6,3)

Prompt: No Formula

Row 2

Name: visDGDisplayFormat

Value: =USE({1A2FD8EF-0000-0000-8E40-00608CF305B2})

Prompt: No Formula

Controls Section

Name: msvDGPosition

X: =BOUND(1.25*Width,0,FALSE,Width*-0.25,Width*-0.25,FALSE,0,0,FALSE,Width*0.25,Width*0.25,FALSE,Width*0.5,Width*0.5,FALSE,Width*0.75,Width*0.75,FALSE,Width,Width,FALSE,Width*1.25,Width*1.25)

Y: =BOUND(0.5*Height,0,FALSE,Height*-0.25,Height*-0.25,FALSE,0,0,FALSE,Height*0.25,Height*0.25,FALSE,Height*0.5,Height*0.5,FALSE,Height*0.75,Height*0.75,FALSE,Height,Height,FALSE,Height*1.25,Height*1.25)

XDynamics: =Controls.msvDGPosition

YDynamics: =Controls.msvDGPosition.Y

XBehavior: =0

YBehavior: =0

CanGlue: =FALSE

Tip: ="Reposition Data Graphic"

Shape Data Section

If you pre-established any Shape Data rows, those rows will be preserved and they will retain the name of the row as you have defined them. If, however, you have NOT pre-established any Shape Data Rows, when the manual data linkage is complete there will be a row for each field linked from the data source. With this creation of the Shape Data Row, the Row will be named by Visio. The row name will be first prefaced by “_VisDM_”. Therefore id you had a field in the data source whose header was “Telephone”, the Shape Data row would be “Prop._VisDM_Telephone”.

Be aware that Visio 2007, by default, attached the default Data Graphic to the SmartShape symbol as soon as it is linked. As you can see from the User-defined Cells Section and the Controls Section, these Sections and Rows are generated by Visio to accommodate the attached Data Graphic. If you later change the Data Graphic to “None”, the following actions will take place in the ShapeSheet:

The User-defined Cells Section Row “User.VisDGDisplayFormat” will be deleted, though the “User.VisDGDefaultPos” row will remain. The Controls Section Row “msvDGPosition” will be emptied of ALL formulae and values although the Section itself will still remain.

Unlinking the external data from the SmartShape symbol, even removing the external Data Source all together will NOT remove the added Shape Data Rows from the ShapeSheet. It WILL, however, prevent any updating of the SmartShape symbol until a valid link is re-established.

Chapter 45: A Whole New SmartShape – Data Graphics

Now that you have established a link to external data from your SmartShape symbol, what can be done with this data that you have not already been able to do utilizing Visio 2003 or prior? The second new concept developed for Visio 2007 is the new feature called Data Graphics. What are Data Graphics? Data Graphics are either SmartShape vector path-based symbols or SmartShape bitmap-based symbols, which are attached to SmartShape symbols. These new SmartShape symbols are used to visually represent the data that has been linked to a SmartShape Symbol via the external data linkage. Keep in mind, however, that these new Data Graphics are simply a reflection of data stored (and possibly calculated upon) in Shape Data Rows. This means that Data Graphics may be used even if you have not linked to External Data with the Data Linking feature.

Essentially there are four classes of Data Graphics: (A) Text, (B) Data Bar, (C) Icon Set, and (D) Color by Value. I will describe each below:

Text

A Text Data Graphic is a Text Callout. Visio pre-defines eight Text Callout types; Text Callout, Bubble Callout, Circle Callout, Triangle Callout, Oval Callout, Heading 1, Heading 2, and Heading 3. These are shown below:

These Text items can be placed (by default) at any of 49 position combinations on the associated SmartShape symbol.

Horizontal Position

Vertical Position

Far Left

Top Edge

Left Edge

Top Edge

Left

Top

Center

Middle

Right

Bottom

Right Edge

Bottom Edge

Far Right

Below Shape

 

More than one Data Graphic may be associated with any SmartShape symbol at any time. It IS possible to relocate Data Graphics for more granular control. However there are some things to look out for. I will go through these later in this chapter.

Text items simply display a Label (optionally) and a Value from a Shape Data Value Cell in the ShapeSheet of the associated SmartShape symbol. You chose the look and feel, you choose formatting of the Label and Value, you choose the default position and you are set.

Data Bar

A Data Bar is a Graphical Representation of a Data Value. There are Eleven pre-defined Data Bars: Progress Bar, Star Rating, Speedometer, Data Bar 1, Data Bar 2, Data Bar 3, People Rating, Thermometer, Multi-bar graph, Stacked bar 1, and Stacked bar 2. Some of these are shown below:

Data bars accept a value or range of values and modify the appearance of the particular data bar to reflect the value(s) being displayed. For example if an IT Asset, say… a desktop PC has a hard disk capacity of 320GBytes and has 120 GBytes still unused in holding applications and data, a speedometer could be used to display the free space or the space used as part of the total capacity. Like Text items, multiple Data Graphics may be applied to any SmartShape symbol and any combination of all four styles of Data graphics may be used on any one SmartShape symbol. The same 49 default positions are available.

Icon Set

An Icon Set is a collection of similar Icons which show one of the set based on a value, or a range of values.  Icon Sets are strips of bitmaps with anywhere from four to five items per strip. There are Up, Down, Left, Right, and Neutral arrow strips, etc. Visio has pre-defined 12 Icon Set types, most of which are shown below:

These can be utilized in Scorecards and Heat maps to indicate trends, breaking points, and many more visual indications of status. For example you could indicate the health of a given aspect of a Project by utilizing the Stop Light Icon Set indicators to show Green for Good, Amber for Marginal, and Red for Bad. It is possible to design and define your own Icon Sets.

Color by Value

Color by Value is just that… the Fill Color of the SmartShape controlled by a defined value or range of values. Each Value or Range of Values can be associated with a color as shown below:

Here we can see for the Department Shape Data field, a Value of Marketing will color the Fill Red, Finance will result in Orange, Sales in Light Green, Operations in Medium Green, and Development in Cyan.

Each Data Graphic or multiple Data Graphics you apply to any given SmartShape symbol will add additional User-defined Cells Rows to the User-Defined Cells Section of the associated SmartShape symbol’s ShapeSheet. Changing from one Data Graphic set to another will add and remove User-defined Cells Rows. There are so many combinations of these rows that it would be impractical to document every permutation in this text, however, they are actually quite self explanatory when you open the associated SmartShape symbol’s ShapeSheet.

You will note that I keep referring to “the associated SmartShape symbol”, and that is because that is exactly what happens… Visio associates the SmartShape Data Graphic Symbol with the SmartShape symbol who’s Shape Data is being visualized. Strangely, though, there does not seem to be a reference to the Data Graphic SmartShape symbol in the ShapeSheet for the SmartShape symbol containing the Shape Data Cells. How, then, is this association created?

To understand this, you will need to open the ShapeSheet for the Data Graphic SmartShape symbol. In the ShapeSheet of the Data Graphic SmartShape symbol you will find a litany of User-defined Cells Rows. Among these Rows you will find a Row named “User.visDGDefaultPos”. This Row will contain a reference to the Sheet.[n] index of the SmartShape symbol it is associated with. Let’s imagine that the very first SmartShape symbol, say a plain Rectangle SmartShape symbol, has an index of 1, and therefore a name of “Sheet.1”. The “User.visDGDefaultPos” Value Cell of the Data Graphic SmartShape symbol (in this case “Sheet.2”) would contain the Formula :

=PNT(ROUND(Sheet.1!Controls.msvDGPosition*4/Sheet.1!Width,0),ROUND(Sheet.1!Controls.msvDGPosition.Y*4/Sheet.1!Height,0)).

Note that it refers to Sheet.1 to establish its positioning. The PinX and PinY cells contain references to this formula which position it in alignment with the Sheet.1 SmartShape symbol with no requirement to be within a group etc.

By understanding that Data Graphics SmartShape symbols are simply another SmartShape symbol associated with a SmartShape symbol containing Shape Data rows and are fed values from those Rows and modify their appearance based upon those values per their type definition, it is a relatively simple task to design your own Data Graphics.

You may ask, “but where are the Masters for these Data Graphics Stored?”. “I don’t see them on an external stencil and I don’t see them on the local document stencil, even after I have applied them to a SmartShape symbol”. In order to see the Masters for the Data Graphics SmartShape symbols complete the following:

Select View > Drawing Explorer Window from the Visio View Menu in the Drawing Context.

In the Drawing Explorer Window, expand the Masters leaf of the Drawing Explorer Tree.

Look at the listing of the Masters and locate the Master for the Data Graphic SmartShape symbol Master you are interested in. Right Click on that Master and Select Edit Master Shape from the Context Menu

A Master Editing Window, exactly like any other Master Editing Window will appear allowing you to make any change you wish to the local Master for the Data Graphic Master SmartShape symbol for this drawing.

 

ShpeSheet Programming - Part 11

ShapeSheet - Chapter 43: Visio 2003 and Prior Data Linkages – The Database Wizard

Thus far we have discussed Data as it is stored in a SmartShape symbol. This data must be entered manually by the user from the user interface. Though powerful in its usage, it is tedious to manually enter large quantities of data. Visio, for a long time, has provided a means to tie external data sources to SmartShape symbols and feed the data from these external sources into the Shape Data cells of a SmartShape symbol’s ShapeSheet.

The method that we are going to look at in this chapter is the Visio Database Wizard. This functionality came about with Visio 4.0. It provides the ability to set up a bi-directional linkage with any ODBC-compliant data source. When the data in the data source changes the user can refresh the SmartShape symbol and update the Shape Data Cells. When the user edits and makes changes to the Shape Data Value Cells, those changes can be pushed back and update the data source.

I am going to walk you through the Database Wizard screen by screen. I will then open a ShapeSheet and show you exactly what changes are made to the SmartShape symbol’s ShapeSheet subsequent to the completion of the wizard . I will then detail what actions are available as a consequence of the wizard and how these actions affect the SmartShape Symbol and the data source.

So… to begin… From the Visio Drawing Toolbar, drag out a simple rectangle 1” in Height by 2” in Width. Keep this SmartShape symbol selected. The Visio Database Wizard Add-on to Visio is found by selecting Tools > Add-Ons > Visio Extras > Database Wizard from the Visio Tools menu in the Drawing context. When launched, the opening screen of the wizard will look like the Screen Shot Below:

Typical of most wizards, the opening screen of the Database Wizard is a gratuitous plug telling you that you are running a wizard, and as such you can click the Next > Command Button to advance to the next screen of the Wizard.

The second screen asks you to select from one of three choices, depending on the task you are attempting to accomplish. You can (a) link a SmartShape symbol to a Database Record (this is exactly what we want to do), (b) create a linked drawing or modify an existing one, or (c) generate new masters from a database. Select the “Link shapes to database records” Radio Button and Click the Next > Command Button to advance to the next screen of the Wizard

You are now asked to select from three choices for the type of link you wish to establish on the Visio end of things. You can choose (a) a SmartShape symbol or symbols in the current Visio Diagram (which is what we want to do), (b) a Master SmartShape Symbol or symbols on the local Document Stencil of the current Visio Diagram, or (c) Master SmartShape symbol or symbols on ANY Visio Stencil. While I am ALWAYS an advocate of making changes to local masters on the document stencil because those changes are propagated throughout the diagram, I do not recommend making changes to Masters on Stand-Alone Visio external Stencils. The Wizard will do this just fine, and you CAN make database links to Visio Stencils, however, you just KNOW that the moment you modify a standard Visio Stencil, Microsoft will come along with a Service Pack release and wipe out your changes. So, if you wish to modify a .VST file, by all means make a copy of that Stencil and make your changes to that COPY of the Stencil. In this way, your work will not be thrashed by any updates etc. Select the “Shape(s) in a drawing” Radio Button and Click the Next > Command Button to advance to the next screen of the Wizard.

Notice that because you had a pre-selected SmartShape symbol as you began the wizard, this screen of the Wizard knows the Drawing you are currently working in, knows the Page you are currently working on, and most importantly knows the name of the SmartShape symbol(s) on that Page. Select the SmartShape symbol in the “Shape name(s) and ID(s)” list then Click the Next > Command Button to advance to the next screen of the Wizard.

The Wizard now presents you with a list of all defined Data Sources that your particular PC is aware of on your machine. If the data source you are desiring to link with is not shown, it is probably because you have not yet set up a File or System DSN for that data source. You can either Browse for a File DSN or, create your own File DSN by selecting either of the appropriate Command Buttons to execute those tasks. For our purposes, we will utilize the “Visio Database Samples” listed in the Data Sources Listing. This sample Access Database ships with Visio and should already be populated in the list. Select the “Visio Database Samples” item and then Click the Next > Command Button to advance to the next screen of the Wizard.

The moment you Clicked the OK Command Button, you should have seen a tiny Spreadsheet Icon attach itself to your mouse cursor for just a moment’s time. This is simply a visual indicator that Visio is searching for, has located, and is reading the external data source you have specified.

The Data Source you have selected is now listed in the Database Text Box and a listing of all available Tables and Views for that Data Source is provided. Note that you can Check and un-Check Tables, Views (Access calls them queries), System Tables, and Aliases as required. Note that you can also define your own Table, should this be necessary (though I do not recommend this… it is quite tedious). Select the “Office – Employee Details” Table from the Database Objects List Box and then Click the Next > Command Button to advance to the next screen of the Wizard.

In some databases, a single field is not unique enough to comprise a unique set of records to act as a key field. Visio, therefore, is capable of utilizing up to 5 fields to comprise a complex key. Quite frankly, if your data source requires five or more fields to create a unique key, it just might need a bit of organizational structure applied to it. In the case of our sample data source, the one key field contains only unique records (the Name of the employee) so we can leave the Number of fields Drop Down List set at 1. Ensure that the “Number of fields” Drop-Down List is showing the number “1” in the list and then Click the Next > Command Button to advance to the next screen of the Wizard.

In this screen of the Wizard the Data Source is listed and the Table is listed based upon the choices we have already made. The Field listing shows all of the available fields which CAN be used as the Primary Key linkage from the data source end. Note that since the “Name” field (the key field in the table in the sample data source) was already defined in the data source, the “Name” field is pre-selected in this list. It, therefore, is safe (and desirable) to leave this selected. Ensure that this Primary Key Field item, “Name” (as in employee name) is selected and then Click the Next > Command Button to advance to the next screen of the Wizard.

The Wizard now presents you with a list of all records for the “Name” field in this Data Source. If you desired a default record to be linked to in your solution, you could choose any of the record items. This is desirable id you were working with IT assets and your business usually specified, say, Dell Desktop PC’s. However in the case of our connectivity to Employee records, we want to be able to select a new record each and every time we drop a SmartShape symbol onto the Page. We, therefore, are going to Click on the “None” Command button to tell the Wizard we DO NOT want a default record. Click on the “None” Command Button and then Click the Next > Command Button to advance to the next screen of the Wizard.

In this screen of the Wizard you define the Actions you want to have available to the user when the SmartShape symbol is residing on the Page. You define what event should be triggered when the SmartShape symbol is dropped or instanced as well. In our case we want to be able to select a record each time the SmartShape symbol is dropped or instanced so we need to ensure that the “Select record on drop” Radio Button is selected. Note that there are also four choices for Actions which may be added to the Context Menu of the SmartShape symbol: (a) Select database record, (b) Refresh shape cells, (c) Update database record, and (d)  Delete shape and database record.

We want the user, at any time to be able to point the database linkage to any other record in the database table so we ensure that the “Select database record” Check Box is checked. If a change has been made to any field in the database record that this SmartShape is linked to, we want to be able to refresh the Shape Data Cells’ Value storing those Values so we ensure that the “Refresh shape cells” Check Box is checked. In some companies, it is absolutely permissible for employees to make changes to the records in a database. In others it is absolutely NOT OK and this activity is controlled by DBA’s, therefore it is a business choice whether or not to have the “Update database record” Action item included such that any changed value in the Shape Data field updates the data source or not. For our illustrative purposes we will leave this Check Box checked. The final item is the one that tends to turn IT Professional’s hair grey. It states that if we delete a linked SmartShape symbol from the Visio diagram do we want the corresponding record in the data source to be deleted as well? In MOST use cases this is NOT a valid option and so the Delete shape and database record Check Box would be changed to un-checked. For our illustrative purposes we will leave this Check Box checked.

Ensure that the “Select record on drop” Radio Button is selected, and that all four Check Boxes are checked for the available Right mouse actions, and then Click the Next > Command Button to advance to the next screen of the Wizard.

In our example, the Primary Key Field is the “Name” field, as in Employee Name. Remember that we are starting with a plain Rectangle SmartShape symbol, and that this SmartShape symbol contains NO DEFINED Shape Data rows/items. Therefore, Visio is suggesting the name of a Shape Data row (Custom Property row) called “Prop.Name” as the name of the Shape Data item to be added to the ShapeSheet to hold the other end of the linkage with the “Name” field in the record, in the table, in the data source we are linking with. 99.9999999 percent of the time this is exactly what we want to do. Therefore, ensure that the Cell List Box displays “Prop.Name” and  Click the Next > Command Button to advance to the next screen of the Wizard.

The final task needed to complete the Wizard is to map the database fields to either existing or suggested Shape Data rows in the SmartShape symbol. Since our Rectangle SmartShape symbol contained NO Shape Data rows, the items shown as Prop.[name of field] as suggested fields. To link these, select the item in the Database Fields: list with the appropriate item in the Cells: list. With both selected, Click the Add > Command button

Note that the linkage is shown in the Links list at the right of the Wizard. Repeat this for Extension, and Title.

When all three linkages have been made between “Department” and “Prop.Department”, “Extension” and “Prop.Extension”, and “Title” and “Prop.Title”, Click the Next > Command Button to advance to the next screen of the Wizard.

We are now presented with the final screen of the Wizard. This screen simply lists all of the actions that we have asked the Wizard to perform. To execute the actions, Click the “Finish” Command Button. You will be returned to the Drawing environment with your SmartShape symbol selected and almost ready to use.

Looking at your Rectangle SmartShape symbol, you might say “Grand… but it does not look any different than BEFORE I began this Wizard!” And, visually, you would be correct. However, Right-Click and Select Data > Shape Data… from the SmartShape symbol’s Context menu. You will see that the Wizard has added four new Shape Data items

The Name, Department, Extension, and Title Shape Data Fields have been added to the SmartShape symbol.

Right-Clicking on the SmartShape and looking at its Context menu shows that the four Actions have been added to the Context menu as well.

The Database Wizard has taken care of all of the background work to set up the connectivity for us.

We’ve looked at this purely from a user interface perspective. Let’s look at the SmartShape symbol’s ShapeSheet itself and see what changes the Wizard has made there.

All of the Wizard’s activity has added User-Defined Cells, Shape Data Cells, and Actions Cells to the ShapeSheet of our SmartShape symbol. The Shape Data should be self explanatory. The Actions also should be quite obvious. Notice that the Actions place a RUNADDON() Function in each Action Row’s Action Cell. Each Action Menu item corresponds to a specific Visio Add-On for working with Databases.

The “Select Database Record” item calls the “DBS” Add-On, the “Refresh Shape Properties” item calls the “DBR” Add-On, the “Update Database Record” item calls the “DBU” Add-On, and the “Delete Shape and Record” item calls the “DBD” Add-On. Notice that the menu Cells have Ampersand characters (&) in their Menu Listings. These are keyboard accelerators which cause the Menu Item to have an underlined character, which, when the user presses that letter while the Context Menu is displayed does the same as Clicking on the menu item. In other words the entry “Se&lect Database Record” actually looks like “Select Database Record” and pressing the “L” key is the same as clicking on the menu item entry.

The User-Defined Cells Section contains two Rows. The first row is the ODBC Connection string. It is entered all on one line as follows:

="ODBCDataSource=Visio Database Samples|ODBCQualifier=C:\Program Files\Microsoft Office\Office12\1033\DBSAMPLE|ODBCTable=Office - Employee Details|1|Name=Prop.Name|3|Department=Prop.Department=0|Extension=Prop.Extension=0|Title=Prop.Title=0|"

This string lists the full qualified path to the data source, the name of the linked database table, the name of the Shape Data Row linked to the Primary Key Field in the table, and the name of the remaining linked Shape Data Fields.

The second row is the ODBC Checksum that the Visio Add-Ons use to work with the database. DO NOT alter either of these User-Defined Rows if you want the linkages to continue working.

The SmartShape symbol still could use some refinement, and so, as you have learned earlier, I am going to create four Text Fields in the Text Block of the SmartShape to display the linked data. As I add each Text Field displaying the Shape Data rows, a “place holder” of “0” will be displayed on the SmartShape indicating that the Field is in place but that no data as of yet has been entered into the fields since we have not as yet pointed to a specific record.

When we Drop, Instance, or Right-Click on the SmartShape and select the “Select Database Record” Context Menu Item, the “DBS” Add-On calls and displays the Select Database Record Dialog as shown below:

Selecting the Clair Hector record from the Database then feeds the values from the data source into the Shape Data fields and, because we added Text Fields, it also displays those values as Text on the face of the SmartShape symbol.

The linkage that we have just worked through is a two-way manual linkage. In other words, we can pull data from the data source and we can push data back TO the data source. This, however, must be done manually for the action to take place. Now that you understand which Functions call which Visio Add-Ons, you can utilize these Add-On calls in other areas of the ShapeSheet as required.

 

 

ShapeSheet Programming - Part 10

Section Four : ShapeSheets Conversing with External Data

 

ShapeSheet - Chapter 42: Data Repositories in SmartShape Symbols and ShapeSheets

As we know, Visio SmartShape symbols are more than just graphical images on a page which represent data and processes. They are, in fact, repositories of, potentially, large quantities of data. Just as you would think of a ShapeSheet as being an Excel Spreadsheet behind every SmartShape symbol, Shape Data can be thought of as an Access Database Table behind every SmartShape Symbol. In fact, all of the diverse data repositories behind each SmartShape symbol are record sets in the Diagram’s Database.

Golden Oldies – Data1, Data2, and Data 3 Fields

From the earliest days of Visio there have always existed three data repositories within a SmartShape symbol which have been designed to hold absolutely any form of data; text, numbers, even binary streams. These Data Repositories are the Data 1, Data 2, and Data 3 fields. Be aware that these fields do NOT have an interface in a ShapeSheet. They ARE addressable as Text Fields as well as via automation calls.

Because these data repositories still exist, and because you can address them through ShapeSheet methodologies, I am including a “how – to”, if you will, to create a “note taking” application from within a Visio SmartShape symbol which allows you access to these fields in a FAR more robust manner than the default. From the default, you say? Just what IS this default? Below I have included a screen shot of the default interface to these three fields. They are, by default, accessed via the Format > Special selection with a Right-Click on a SmartShape symbol, accessing its Context Menu.

As you can see, the interface to enter data into, and subsequently, to read data from, the Data 1, Data 2, and Data 3 fields in simply a one line text field in the Dialog form. This is absolutely less than optimal.

I am going to walk you through an exercise in creating a far more robust interface to these data repositories. You can include access to this interface for ANY SmartShape symbol by simply adding an Actions row to your ShapeSheet for your SmartShape symbol.

Create a new Comments Dialogue for Microsoft Office Visio 2007 SmartShape Symbols.

 

Within Microsoft Office Visio 2007, there exist two distinct methods of adding comments “associated” with any given Visio SmartShape symbol. The first of these is the Microsoft Office Comments Object. This is added by selecting a SmartShape Symbol and then selecting Insert > Comment from Visio’s Insert Menu. This is somewhat less than effective since if the symbol is moved, the comment does not move along with the Symbol and hence becomes quite orphaned. The Second is to ensure that the subject SmartShape Symbol is selected and then select Insert > Insert Shape Screen Tip… from the Visio Insert Menu. After adding the comment information in the dialog, and the subsequent closing of the dialog, whenever you hover the mouse cursor over the SmartShape Symbol, the Screen Tip (Comment) pops up for a brief time as a Pop-Up Screen Tip. The advantage of this is that the Screen Tip always remains associated with the SmartShape symbol. However, the down-side is that is only temporarily visible, and it can only display a limited number of characters. Additionally, there is no method for accessing these Screen Tips with Visio Custom Reports.

I am going to show you how to implement a Powerful Comments Dialog in Visio which may be associated with ANY Visio SmartShape symbol, and can hold up to as much as 64K of text. Additionally the comments can remain on screen until the Comments Dialog is Closed. Again… This technique utilizes a field contained in every SmartShape symbol, which has been around since Visio 1.0. Every SmartShape Symbol contains three data fields accessible by end users: the Data1, Data2, and Data3 fields. To access these, Right-Click on any Visio SmartShape Symbol and select Format > Special from the SmartShape’s Context Menu. In the Format Special Dialog you will see three single-line data entry fields: Data1, Data2, and Data3. Each holds up to 64K of ANY sort of data. With the introduction of Microsoft VBA and VBA Forms with Visio 3.0, Visio has all of the tools necessary to implement an elegant User Interface to add, edit, and delete text into a data field through a VBA form.

I will detail exactly how to implement this feature. With a bit of practice you will be able to greatly enhance and embellish on this technique to create a robust comments repository associated with any SmartShape symbol.

The Steps necessary to create this interface are relatively simple:

1.       Create the User Form

2.       Add the VBA ActiveX Controls to the Form

3.       Create the Code to initialize the Form

4.       Create the Code to Save the Comment changes when the Form is Closed

5.       Create the Public Subroutine to call and initialize the Form

6.       Create the Context Menu and associated Action to Call the Public Subroutine

We will cover each of these tasks in a step-by-step, click-by-click manner.

The appendix at the end of this section of this text lists the entire code implementation for this exercise.

Create a new Microsoft Office Visio 2007 Diagram

In Visio 2007 Select File > New > General > Basic Diagram (US units) from the File Menu

Enter the Microsoft Office 2007 Visual Basic for Applications Development Environment

In Visio 2007 Select Alt+F11

Ensure that the VBA Project Explorer is Visible

In the VBA IDE Select View > Project Explorer from the VBA View Menu

Select the current Diagram Project

In the VBA IDE, in the Project Explorer, Click on the open Diagram name (i.e. Drawing 1 (Drawing1))

Create a new VBA Form

In the VBA IDE Select Insert > User Form from the VBA Insert Menu
(in the VBA Code Area a new window will be visible, initially entitled “Drawing1 – UserForm1 (UserForm)”
Within the Form Design Window a new blank form will be visible, initially entitled “UserForm1”

Ensure that the VBA Properties Window is Visible

In the VBA IDE Select View > Properties Window from the VBA View Menu

Ensure that the VBA Toolbox is Visible

In the VBA IDE Select View > Toolbox from the VBA View Window

Edit the Properties of the newly created User Form

In the VBA Properties Window modify the values for the following Property Fields (note that the field name is to the left of the table in the Properties Window, the field value is to the right of the table):

(name) = “frmCommentsDialogue”
(Note that this will change the title of the Properties Window, as well as the value in the drop-down-list immediately below the Properties Window Title, as well as the Header in the Form Design Window)

Caption = “Comments Dialogue”
(Note that this will change the Title in the User Form to “Comments Dialogue”

Add a Text Box Control to the Comments Dialog

In the VBA IDE, Click anywhere within the open area of the Form Design Window to display the toolbox and prepare the new User Form to accept the Text Box ActiveX Control

In the VBA IDE, In the Toolbox Click to select the Text Box ActiveX Control Item (it looks like a small “ab|”

Move your cursor to the User Form.

Click – Drag – and release to drag out a Text Box as shown in Figure 1

Figure 1

Edit the Properties of the newly created Text Box

In the VBA Properties Window modify the values for the following Property Fields:

(name) = “txCommentsSurface”

EnterKeyBehavior = “True”

MultiLine = “True”

ScrollBars = “3 – fmScrollBarsBoth”

WordWrap = “True”

Add a Command Button Control to the Comments Dialog

In the VBA IDE, Click anywhere within the open area of the Form Design Window to display the toolbox and prepare the new User Form to accept the Command Button ActiveX Control

In the VBA IDE, In the Toolbox Click to select the Command Button ActiveX Control Item (it looks like a small raised rectangular box i.e. button)

Move your cursor to the User Form.

Click – Drag – and release to drag out a Command Button as shown in Figure 2

Figure 2

Edit the Properties of the newly created Command Button

In the VBA Properties Window modify the values for the following Property Fields:

(name) = “btnClose”

Caption = “Close”

Initialize the configuration of the Comments Dialog when the Dialog Loads

In the VBA IDE, In the Form Design Window, in the Comments Dialog, Double-Click on any open area of the Dialog Form (i.e. any area with the grid of dots pattern)
Note a new Code Window will Open

Create the Code Stub for the Dialog Initialization Event

In the VBA IDE, In the New Code Window, ensure that the Left Drop-Down List near the top of the Code Window has shown “UserForm”.

In the VBA IDE, In the New Code Window, ensure that the Right Drop-Down List near the top of the Code Window as shown “Initialize”

In the VBA IDE, In the New Code Window, ensure that the mouse cursor is blinking at the beginning of the blank line between the line reading “Private Sub UserForm_Initialize()”, and “End Sub”

Create the VBA Code for the Form Initialize Event

In the VBA IDE, in the New Code Window, beginning at the point where the blinking Mouse Cursor exists, enter the following Visual Basic For Applications (VBA) Code:

           Dim shpSubjectShape As Visio.Shape

    Set shpSubjectShape = Visio.ActiveWindow.Selection.Item(1)

    Me.Caption = "Comments Dialog : " & shpSubjectShape.Name

    Me.txCommentsSurface.Text = shpSubjectShape.Data1

    Me.txCommentsSurface.SelStart = 0

The DIM statement means to Dimension or Declare a VBA Variable to hold an Object. In this case you declare a variable named shpSubjectShape and declare it as an object data type of Visio Shape

When you interact with an Object to Get or Set Properties, Methods, or Events you use the VBA Keyword SET. A quick way to get a reference to the selected SmartShape symbol is to go to the Visio Application Object and look at the Active Window Object and look at the Selection Object and get a reference to the first thing selected; in this case the singular SmartShape Symbol you have selected.

The VBA Keyword ME is a VBA shortcut to the VBA Form currently in use. Therefore the Caption property of the Form is being set with the string “Comments Dialog” and the actual name of the selected shape.

The next line binds whatever text is in the Data1 field of the Shape to the Text Property of the Text Box on the Current Form

Finally the last line simply locates the curser at the beginning of the body of text in the Text Box.

Create the Code Stub for the Dialog Close Event assigned to the Command Button

In the VBA IDE, Click on the Header for the Comments Dialogue User Form

In the VBA IDE, In the Form Design Window, in the Comments Dialog, Double-Click on the Command Button on the Comments Dialog Form
Note the Code Window will rise to the top of the Code Windows Stack

In the VBA IDE, In the New Code Window, ensure that the mouse cursor is blinking at the beginning of the blank line between the line reading “Private Sub btnClose_Click()”, and “End Sub”

Create the VBA Code for the Form Close Event

In the VBA IDE, in the New Code Window, beginning at the point where the blinking Mouse Cursor exists, enter the following Visual Basic For Applications (VBA) Code:

    Dim shpSubjectShape As Visio.Shape

    Set shpSubjectShape = Visio.ActiveWindow.Selection.Item(1)

    shpSubjectShape.Data1 = Me.txCommentsSurface.Text

    Unload frmCommentsDialogue

This subroutine is very similar to the module described above. However as you can see in the last two lines, you simply reverse the binding and push the text from the Text Box control back to the Data1 field of the Shape. You then close and unload the User Form.

Create a new Public VBA Subroutine to Call for the Initialization and Loading of the Comments Dialogue Form

In the VBA IDE Select Insert > User Module from the VBA Insert Menu
Note that the Code Window’s Header will have a title reading “Drawing1 – Module1 (Code)”

In the VBA IDE, In the Module1 Code Window, enter the following VBA Code:

Public Sub CallCommentsDialogue()

    frmCommentsDialogue.Show

End Sub

This tiny module simply exists as a Public Subroutine which calls for the initialization and showing of the VBA Form.

This completes the VBA Form and VBA Code Creation for the Comment s Dialogue. You may now close the VBA IDE

From the VBA IDE, Select File > Close and Return to Visio from the VBA File Menu.

Assign the Code to call the Comments Dialog to any desired Visio SmartShape Symbol.

In the Visio User Interface, drag any desired Visio Master from a Visio Stencil onto the Visio Diagramming Surface.

Open the ShapeSheet for the SmartShape Symbol

Ensure that the desired Visio SmartShape Symbol is currently the only selected SmartShape Symbol on the current Visio Page.

From the Visio User Interface, Select Window > Show ShapeSheet from the Visio Window Menu.

Add the Function Call to trigger the Comments Dialog

With the Visio ShapeSheet Window Open and active, Select Insert > Section… From the Visio Insert Menu.

In the Insert Section Dialog, check the Check Box Control labeled “Actions”, then Click the OK Command Button to close the Insert Section Dialog.

Scroll down through the various ShapeSheet Sections until you find the Actions Section of the ShapeSheet. Notice that there are numerous cells in the available row. The first cell at the far left of the row will have the Column Header labeled “Actions” and will have a value reading “Actions.Row_1”. Click into the cell and type the following text “CallCommentsDialogue”. Press the Enter key to accept this edit.  The cell will now read as “Actions.CallCommentsDialogue”.

The next cell to the Right has a Column Header entitled “Action”. In the cell immediately below the header , enter the following formula “=RUNADDON( “CallCommentsDialogue”)”. Press the Enter to accept this edit.

RUNADDON() is a ShapeSheet Function which calls for and runs a VBA Subroutine or Function. Note that the name of the Subroutine or Function must be entered as a Quoted String. In this case RUNADDON is calling the Public Subroutine “CallCommentsDialogue”.

The next cell to the Right will have a Column Header reading “Menu”. In the cell immediately below the header , enter the following formula “Add or Edit Comments for this SmartShape Symbol”. Press the Enter to accept this edit. The Quoted Text is the text that will physically appear on the Context (Right-Click) Menu.

Close the ShapeSheet Environment

Test the Comments Dialogue

Right-Click on the Selected SmartShape Symbol and select “Add or Edit Comments for this SmartShape Symbol” from the SmartShape Symbol’s Context (Right-Click) Menu.

When the Dialogue Opens, begin typing comments into the Dialog in the Multi-Line Text Box. When your additions and edits are complete, Click the “Close” Command Button to accept the additions and edits and close the Dialog.

Note that the Dialog displays the header inclusive of the selected SmartShape Symbol’s Name to aid in easy identification of the SmartShape to which the comments are being attached.

Each SmartShape Symbol is capable of holding up to 64K of text.

Listing 1 – VBA Code

Module 1

Public Sub CallCommentsDialogue()

    frmCommentsDialogue.Show

End Sub

User Form 1

Private Sub btnClose_Click()

    Dim shpSubjectShape As Visio.Shape

    Set shpSubjectShape = Visio.ActiveWindow.Selection.Item(1)

    shpSubjectShape.Data1 = Me.txCommentsSurface.Text

    Unload frmCommentsDialogue

End Sub

 

Private Sub UserForm_Initialize()

    Dim shpSubjectShape As Visio.Shape

    Set shpSubjectShape = Visio.ActiveWindow.Selection.Item(1)

    Me.Caption = "Comments Dialog : " & shpSubjectShape.Name

    Me.txCommentsSurface.Text = shpSubjectShape.Data1

    Me.txCommentsSurface.SelStart = 0

End Sub

FORM Code

VERSION 5.00

Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmCommentsDialogue

   Caption         =   "Comments Dialogue"

   ClientHeight    =   3225

   ClientLeft      =   45

   ClientTop       =   330

   ClientWidth     =   4710

   OleObjectBlob   =   "frmCommentsDialogue.frx":0000

   StartUpPosition =   1  'CenterOwner

End

Attribute VB_Name = "frmCommentsDialogue"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

I realize that this exercise strayed a bit from pure ShapeSheet development, however, I feel that the effort was neither too daunting nor too divergent from adding a formidable new tool to your toolkit in enhancing the power of SmartShape symbols in your applications.

Shape Data – Used to be Custom Properties

As stated before, Data 1, Data 2, and Data 3 have been available as Data Storage Repositories since the early days of Visio. It became obvious that these three storage areas were not enough to hold the important data which needed to be associates with SmartShape symbols, and so Custom Properties were created. Custom Properties go a long way back in the history of Visio as well. You can think of Custom Properties as being simple Access Databases associated with SmartShape symbols and their ShapeSheets. Unlike Data 1 through Data 3, these Custom Properties are directly accessible via the ShapeSheet.

Beginning with Visio 2007, these Custom Properties have been renamed. They are now called Shape Data. Internal to the ShapeSheet they still, for backward compatibility reasons, carry the Cell designator of “Prop.[row name]/[row index]”

By default a simple SmartShape symbol carries no Shape Data. To add Shape Data to a ShapeSheet (and hence, the SmartShape symbol itself) select Insert > Section from the Visio Insert menu in the ShapeSheet Context, then add additional Rows as necessary by Clicking into an existing Shape Data Row and selecting Insert > Row from the Visio Insert menu in the ShapeSheet Context.

Shape Data can also be added through the user interface by Right-Clicking on a SmartShape symbol and selecting Data > Shape Data… from the SmartShape symbol’s Context menu, then clicking the Define… Command Button. When you have completed this action, the following Dialog will be opened:

There are 11 Fields in the dialog. These directly correspond to the Cells in a Shape Data Row in a ShapeSheet. The ShapeSheet row is shown directly below:

Using the Dialog as a basis, here is the mapping between the Dialog and the ShapeSheet

Label = Label
Name = Prop.[user provided name] in the leftmost Cell of the Row
Type = Type
Language = LangID
Format = Format
Calendar = Calendar
Value = Value
Prompt = Prompt
Sort key = SortKey
Ask on drop = Ask
Hidden = Invisible

The Shape Data Dialog, as seen by the user is shown below:

Label is the Text String which is shown as a label to the Left of the Text Box where the Value is entered.

Name is the actual Shape Data Row name in the ShapeSheet. NOTE: Whereas the Label is a simple Text String and can contain spaces, the Name must comply with ShapeSheet standards for Row naming, i.e. no spaces, letters, numbers, underscore characters, and no special characters.

Type is the Data Type as selected in the Shape Data Definition Dialog. These can be String, Number, Fixed List, Variable List, Boolean, Currency, Date, or Duration. When entered directly in a ShapeSheet Shape Data Row, the Data Type Choice must be entered as an integer where String = 0, Fixed List = 1, Number = 2, Boolean = 3, Variable List = 4, Date = 5, Duration = 6, and Currency = 7

Language ID is the Language Definition for the target use. 1033 is the code for US English

Format has multiple use. When applied to String, Number, Date, Duration, or Currency, it is the Formatting Picture String. When applied to Fixed List or Variable List it is a semi-colon-deliminated list as a text string which lists the possible entries for the user to select from, as in “able;baker;charlie;delta;easy”.

Calendar is the Calendar Type Definition as defined by Visio. 0 is the Western Calendar. There are 9 possible calendar definitions available within Visio.

Value is the actual repository where data input into a Shape Data dialog is stored. It is the default cell for a Shape Data Row.

Prompt is the Text String as a prompt to the user as shown in the lower area of the Shape Data Dialog. Please note that it is considered poor SmartShape symbol programming practice to state the obvious as a prompt. In other words, if you are asking for a text based entry which will hold data about an Employee, the prompt should be something like “Enter the Employee’s Name here” rather than “Type text here”. If the Data Type is a Fixed List (Drop Down List), the prompt would begin “Select… from the list of available …”. If the Data Type is a Variable List (Combo Box), the prompt would begin “Select, or Enter…”

Sort Key is the order in which you want the (presuming that you have more than one) Shape Data Rows to be displayed in the Dialog. Note that these ARE NOT in alphabetical or numeric order. They are in ASCII Character order. In other words, if you use a sort order sequence of 1,2,3,4,5,6,7,8,9,10,11, they will show in the dialog in the order of 1,10,11,2,3,4,5,6,7,8, and 9. To have them ordered properly, use the sequence 01,02,03,04,05,06,07,08,09,10, and 11.

Ask on Drop determines whether the particular Shape Data item will be displayed in the Shape Data dialog when the SmartShape symbol is dropped and instanced from a Master on a Stencil, or when the SmartShape symbol is copied. If True it will be initially displayed (in the older style Shape Data dialog), if False it will not be displayed. Any subsequent display of the Shape Data dialog will show ALL entries (based upon their Hidden [Invisible] Property).

Hidden is whether or not you wish the user to see this Shape Data item in the Shape Data Dialog or not. A value of True hides the Row Item, a value of False shows the Row Item.

There is no practical limitation to the number of Shape Data items which can be associated with a SmartShape symbol. However, note that there are two differing styles of the Shape Data Dialog. The default Shape Data dialog (selected by Right-Clicking on a SmartShape symbol and selecting Data > Shape Data… from the SmartShape symbol’s Context menu) is screen resolution dependent. It can display between 19 and 24 items. If there are more defined Shape Data items, they will not display in the dialog, and a warning will appear in the dialog informing the user that “additional items are not shown…”. The new Shape Data Window (selected by selecting View > Shape Data Window from the Visio View menu) is a scrollable dialog which will show ALL defined Shape Data items.

Why is it valuable to add Data to the SmartShape symbol? Because data rich SmartShapes can be included in Custom Reports and other output mechanisms. Data Rich SmartShape symbols are able to display their data when accessed in an Internet Explorer browser subsequent to a Save As Web Page operation in Visio. Data Rich diagrams are what set Visio apart from other simple graphic tools like PowerPoint. The ability to store, report on,  and display data is the value add that sets  your solution apart from “pretty pictures”.

 

ShapeSheet Programming - Part 9

ShapeSheet - Chapter 36 : A Specialized SmartShape Symbol – A Multi-Shape

A Multi-Shape is a Visio SmartShape symbol which can alter its features based upon user-selectable context menus. A classic example of a Multi-Shape can be found on the Basic Flowchart Stencil in Visio versions dating back as far as Visio 3.0. The “Flowchart Shapes” Master is configurable by the user from the user interface simply by the user selecting “Process”, “Decision”, “Document”, or “Data” from the SmartShape symbol’s context menu.

Underlying this functionality is actually a very simple concept… create a SmartShape symbol with multiple geometry sections and only display one of these Geometry Sections at a time, based upon a click of the SmartShape symbol’s Context (Right-Click) menu.

I will walk you through the process of creating a Multi-Shape below.

There are actually two different approaches to the initial creation of a Multi-Shape: either create multiple single SmartShape symbols and utilizing the Combine Shape Operation (which, remember, creates a new SmartShape with multiple Geometry Sections from the individual SmartShape symbols), or, Create a single simple SmartShape symbol and then modify and enhance it by adding additional Geometry Sections via the ShapeSheet. I am going to utilize the former method; let Visio do the Combine Operation to create the symbol for me.

To begin, I will drag out the four Flowchart symbols, Process, Decision, Document, and Data, and then place them exactly on top of each other such that they are perfectly aligned and directly on top of each other as illustrated below:

Let’s look at the Geometry Sections of the ShapeSheet for the resultant SmartShape symbol subsequent to the Combine Shape Operation.

A quick look at Geometry1 reveals that it is the Geometry Path for the rectangle which is the Process item. Geometry3 is the Decision item, Geometry4 is the Document item, and therefore Geometry2 is the Data item. As stated earlier the reason that there seems to be a strange fill/no fill pattern is because these four Geometry Sections are on top of each other and in attempting to show all of them it creates this rather cubist/impressionist/modernist artistic effect. If we change the value of any three of these Geometry section’s NoShow Cells to True then we will only see the remaining Geometry section with its Fill intact.

So how do we accomplish this, you might ask? The answer is that we will add an Actions Section with Four Selectable items, and have these actions set a value in a User Defined Cell. This User Defined Cell will be referenced in a Formula in each Geometry Section’s NoShow Cell. Below are the added Actions Section and four Actions Rows:

Below is the User-Defined Section being referenced by the Actions Section Rows:

Below are the NoShow Cells for each Geometry Section:

The NoShow Formulae are simply logical expressions that evaluate to True or False, and show or do not show the given Geometry Section.

So as you can see, Right-Clicking on the “Process” Context Menu Item for the Multi-Shape SmartShape symbol, sets the value in the User-Defined Cell User.SetShapeType to a value of 3, which triggers the evaluation of the four Geometry Sections’ NoShow Cells and sets three of the four to True and one to False thereby showing only the Process item.

Quite simple actually… but absolutely BRILLIANT!!!!!!

ShapeSheet - Chapter 37 : Text is a Sub-Shape (if you will) of a SmartShape Symbol

You already know that the Text on any SmartShape symbol can be relocated independently of the geometry of the SmartShape symbol itself by using the TextBlock tool found under the Text tool on the Visio Standard Toolbar. Every SmartShape symbol has a Text Block. By default, every ShapeSheet contains numerous ShapeSheet Sections, as you have seen above. However, unless the user has in some way modified the size, angle, or position of the Text Block, the Text Transform Section is not displayed in a SmartShape symbol’s ShapeSheet. If the Text Transform is not visible, selecting Insert > Sections from the Visio Insert Menu while in the ShapeSheet context and selecting Text Transform from within the Insert Section dialog will add the Text Transform Section to the active ShapeSheet.

If you look at the Cells of the Text Transform Section, you will note that the default Formulae refer to cells in the Shape Transform Section. This would lead you to believe that the Text Block is a SubShape of the overall SmartShape symbol. In fact this assumption is, in a loosely defined manner, is quite true. A SmartShape Symbol contains a Text Block. It is not an actual SubShape, however it is controlled by the SmartShape symbol’s Bounding Box. Custom Formulae can alter this default behavior. The Text Block is, by default, the same Width, Height, and Angle as the SmartShape symbol itself.

ShapeSheet - Chapter 38 : Controlling Interactions between Text, the Bounding Box  and Geometry in SmartShape Symbols

The default behavior for Text associated with a Visio SmartShape symbol is to:

(A)   Be exactly the same Height and Width as the SmartShape symbol’s Bounding Box

(B)   Rotate with the SmartShape symbol as if it were locked to the face of the SmartShape symbol

(C)   The Text word-wraps at the Bounding Box Boundary (less the default margins)

(D)   Excessive amounts of Text “spill out” of the SmartShape symbol

(E)    Text is Vertically and Horizontally Centered in alignment

While this default behavior might be satisfactory for some limited use, designing a SmartShape symbol with far more intelligent Text Behavior will result in a SmartShape symbol with a vastly more usable functionality.

Font Grows and Shrinks as the SmartShape is Resized

While text spilling out is the default behavior, you might wish to design a SmartShape symbol whereby an increased amount of text will simply remain constrained within the Bounding Box and cause the Font Size to Grow or Shrink based on the volume of text as it is confined within the Bounding Box. The process for designing such text behavior is actually deceivingly simple.

I’ll illustrate this by beginning with a simple Rectangle SmartShape symbol that is 2 inches wide by 1 inch high. I’ll also begin with a Font size of 10 points.

In order to make the Font grow or shrink based upon the volume of text we will simply need to design in a custom Formula in the Font Size Cell of the ShapeSheet.  Open the ShapeSheet for the Rectangle SmartShape symbol. Locate the Character Section. Click into the Size Cell (referring to the Font Size). Fairly obviously we need to change the default Value of 12 pt with a Formula which will alter the Font Size as the Height of the SmartShape Symbol changes.

Consider the following equation:

10 pt / [required font size] = 1 in / [current Height]

We know that the current Height is simply Height. If we remember our Algebra course from years back, we know that we need to isolate [required font size]. To do this we multiply both sides of the equation by [required font size] which yields the equation:

10 pt = (1 in / Height) * [required font size]

Dividing both sides by (1 in / Height) yields the equation:

(10 pt*Height) / 1 in = [required font size]

Or properly stated as a Visio ShapeSheet Formula:

=(10pt*Height)/1in

 Therefore we will enter the Formula “=(10pt*Height)/1in” into the Size Cell

In essence what we have done is take the ratio of Designed Height versus Actual Height and compared that to Designed Font Size versus Required Font Size. This means that as we resize the Height of the SmartShape Symbol, the Font Size resizes as well.

The SmartShape Resizes with the Volume of Text it Contains

An even more powerful and diametrically opposed behavior is to have the height of the SmartShape symbol grow or shrink based upon the volume of text that the SmartShape symbol contains.  In order to make this work, we need to make use of a Visio ShapeSheet Function called TextHeight and a ShapeSheet Function called TheText.

The custom Formula is placed in the ShapeSheet’s Height Cell. The Custom Formula is as follows:

=GUARD(TextHeight(TheText, Width))

The TextHeight() function takes two arguments. The First Argument is the Function “TheText”, which simply is the volume of text entered onto the SmartShape symbol. The Second Argument is the Cell Reference “Width”, which, of course, is the Width of the SmartShape symbol. You already know the GUARD() formula.

In essence the Custom Formula states that we need to look at the Text entered onto the SmartShape Symbol and, utilizing the Width of the SmartShape symbol, set the Value of the SmartShape symbol’s Height to be the contained volume of text constrained by the width of the SmartShape symbol.

A corollary to this is a Formula that would be placed into the SmartShape symbol’s Width Cell as follows:

=GUARD(TextWidth(TheText))

This causes the SmartShape symbol’s Width to change based upon the volume of text on the surface of the SmartShape symbol.

While both of these custom Formulae work perfectly fine, it is not a wise idea to attempt to use BOTH of them in the SAME ShapeSheet. These two work at crossed purposes and fight each other for supremacy.


 

ShapeSheet - Chapter 39 : Controlling Text Positional and Rotational Behavior in SmartShape Symbols

As we have seen thus far, a few simple Formulae can go a long way to providing a much better user experience when working with text in SmartShape symbols. We have seen that the physical size of a SmartShape symbol can be controlled by the quantity of text and that the Font size can be controlled by the size of a SmartShape symbol. Next we are going to look at how the text can exhibit far more intelligence in terms of its angle and position.

Keeping Text Horizontal, Yes… Even When the SmartShape Has Been Flipped

Previously we talked about how, by default, the Text on a SmartShape symbol tracked angularly with the SmartShape symbol itself, that is when you rotated the SmartShape symbol 15 degrees the text was also rotated 15 degrees. This is not necessarily the type of behavior most desirable.

Once you have added a Text Transform section to a ShapeSheet you will notice that the Text Transform Section contains a TxtAngle Cell, and that by default, the Formula in that Cell is referencing the Angle Cell in the Shape Transform Section. Logically, you would derive that if the SmartShape symbol itself is rotated 15 degrees then to keep the Text at an absolute horizontal you would only need to counter rotate the Text Block by -15 degrees and you have the behavior you need. The formula in the TxtAngle Cell could be:

=GUARD(-Angle)

If, subsequent to placing this custom Formula into the TxtAngle Cell, you push and pull on the SmartShape Symbol’s Rotation Handle, you will see that, seemingly, the Formula works absolutely effectively. However, if you flip the symbol across its X or its Y angle, the text seems to behave even WORSE than when you started. Strangely, if you flip the SmartShape symbol in BOTH X and Y, the SmartShape seems to behave properly once again.

This sort of aberrant behavior can be controlled by utilizing a Visio Function called BITXOR(). BITXOR evaluates BOTH of its arguments and if one or the other evaluates to True then BITXOR() evaluates to True, however if BOTH or NONE of the arguments evaluates to True, then BITXOR() evaluates to False. You can take advantage of this by placing the BITXOR() Function inside of a Conditional IF() Statement to create a function like the following:

=GUARD(IF(BITXOR(FlipX, FlipY),Angle,-Angle))

The IF() statement says that IF the BITXOR() Function Evaluates to True (i.e. EITHER FlipX OR FlipY evaluate to True, then the value in the TxtAngle needs to be set to True, otherwise, set it to False.

This Formula will ensure that no matter how the SmartShape symbol is rotated or flipped, the Text will ALWAYS remain at 0 degrees to the Page; i.e. horizontal.

Keeping Text Readable – Gravity Text

In many Visio Solutions, especially Engineering Solutions, the standard accepted way that text is to be presented is such that it is always readable from the bottom of the diagram or from the right side of the diagram. As we have noted, the default behavior for Visio text is to rotate with the SmartShape symbol itself. This means that there are many possible rotations of SmartShape symbols which would render the text upside down and hence not readable from bottom or right.

To solve this issue without the requirement of massively convoluted Formulae, Visio created a Function called Gravity(). The Gravity function works as follows:

Gravity() calculates a text block's correct angle of rotation for the indicated shape rotation to prevent the text from turning upside down.

GRAVITY(angle,limit1,limit2)

Where : angle The shape's angle. limit1 Optional. Default limit is 90 degrees. limit2 Optional. Default limit is 270 degrees.

The GRAVITY function is usually used in the TxtAngle cell.

The value returned is 180 degrees if angle is between the angles specified by limit1 and limit2; otherwise the value returned is 0 degrees. All of the arguments are automatically normalized between 0 and 360 degrees by the function. If an argument does not specify units, radians are assumed.

Example 1

GRAVITY(Angle)

Returns 180 degrees if Angle is between 90 and 270 degrees; otherwise, returns 0 degrees.

Example 2

GRAVITY(2)

Returns 180 degrees, because 2 radians is between 90 and 270 degrees.

Example 3

GRAVITY(100 deg, 110 deg, 290 deg)

Returns 0 degrees.

Example 4

GRAVITY(100 deg, 290 deg, 110 deg)

Returns 0 degrees

This simple, easy to implement Formula, when placed in the TxtAngle Cell will ensure text readability no matter how a SmartShape symbol is rotated.

ShapeSheet - Chapter 40 : SmartShape Symbols with Multiple Text Blocks

Remembering the rules I gave you above… Every SmartShape symbol has one, and ONLY one, Text Block. No more, no less. However there may be many times when you have a need to design a SmartShape symbol which contains several items of Text which need to be accessed independently and which need to have their own unique Text Formatting. This formatting could include, but is not limited to Vertical and Horizontal Alignment, Bullet Styles, Font, Font Size, Tab Spacing, etc.

There really is only one way that this functionality can be implemented, and that is by creating a Group Shape. A SmartShape symbol which is a Group Shape has zero or more Sub-Shapes “wrapped” in a Group “Shell”. Again… each Sub-Shape will have one Text Block. The Group itself will have a Text Block as well. You are free to use any viable method for the placement of these Sub-Shapes and their Text Blocks within the Group. When you select a Group SmartShape symbol and begin typing, by default, the text is fed into the Text Block of the Group, not to any Sub Shape. You can prevent the Group from accepting the text via the Protection Section of the Group’s ShapeSheet. If a user selects the Group and then sub-selects a SubShape, that SubShape will accept the text being typed.

ShapeSheet - Chapter 41 : Text Fields – Views into Lots of Data

I am going to take a small leap of faith here and assume that you are already at least minimally acquainted with Shape Data (formerly known as Custom Properties). I will cover Shape Data in far greater detail in a little while. For now accept that if a SmartShape symbol, like a Process SmartShape symbol from the Flowcharting Solution in Visio, has its Shape Data fields, Cost, Duration, and Resources filled with data, that data is accessible to the Text Block of the SmartShape Symbol.

Not only are the Shape Data items accessible, but NUMEROUS other properties of the SmartShape Symbol, the Page it resides on, and the Document it lives in are accessible as well. The Illustration below is of the Insert > Field Dialog from the Insert Menu while in the Diagram context:

Note that there are eight categories of Fields that can be added to a Text Block of a SmartShape symbol. The listing below details the available fields:

Shape Data

                [an available field for each Shape Data item defined in the SmartShape Symbol]

Data/Time

Creation Date/Time

Current Date/Time

Last Edit Date/Time

Print Date/Time

Document Info

Creator

Description

Directory

Filename

Keywords

Subject

Title

Manager

Company

Category

Hyperlink Base

Page Info

Background

Name

Number of Pages

Page Number

Geometry

Width

Height

Angle

Object Info

Data 1

Data 2

Data 3

ID

Master

Name

Type

User-defined Cells

                [an available field for each User-defined Cell item defined in the SmartShape Symbol]

Custom Formula

[any valid Formula/Function usable within the ShapeSheet environment]

The data associated with any of these fields should be relatively self explanatory.

To add a Text Field to a SmartShape symbol’s Text Block simply Double-Click on the SmartShape symbol such that you see a blinking cursor and are actively in Text Editing Mode for the SmartShape symbol. While the cursor is active in the Text Block, select Insert > Field… which will bring up the Insert Field Dialog as shown above. Select the Category and the Item within the Category and Click the OK Command Button. The data associated with that particular Text Field will be displayed as part of the text stream in the Text Block. Note that you can have as many Text Fields in a Text Block as you desire.

 

ShapeSheet Programming - Part 8

ShapeSheet - Chapter 29 : A Brief Divergence – Shape Operations

As part of the word bubble exercise above, I had you utilize a Shape Operation to create a new SmartShape symbol based on the Union of the ellipse and triangle SmartShape symbols. Just to reiterate… using ANY Shape Operation will destroy the original SmartShape symbols and create a new SmartShape symbol based upon the outcome of that particular Shape Operation.

I will, below, detail how each of these Shape Operations work, however as a precursor to walking you through them, you need to know that the new SmartShape symbol will take all of its default formatting options from the FIRST SmartShape symbol selected. The following set of illustrations show you how each of these Shape Operations work. I will be using three very basic SmartShape symbols; a Triangle, a Circle, and a Rectangle.

 Union

A Union Shape Operation takes in to consideration all of the selected SmartShape symbols and returns a new SmartShape symbol which is the Union of all their filled areas. It draws its formatting from the first SmartShape selected. It creates a new ShapeSheet with one Geometry Section.

Combine

A Combine Shape Operation takes in to consideration all of the selected SmartShape symbols and returns a new SmartShape symbol which is the Combination of all their filled areas. It draws its formatting from the first SmartShape selected. It creates a new ShapeSheet with multiple Geometry Sections, one for each Geometry Path. Where each filled area overlaps another it creates an alternating Filled / Not Filled pattern.

Fragment

A Fragment Shape Operation takes in to consideration all of the selected SmartShape symbols and returns a SERIES of new SmartShape symbols which are the boundaries of each area where Geometry Paths cross. It draws its formatting from the first SmartShape selected. It creates a new ShapeSheets, each with one Geometry Section.

Intersect

An Intersect Shape Operation takes in to consideration all of the selected SmartShape symbols and returns a new SmartShape symbol which is the Intersection of all the filled areas the SmartShapes share in common. It draws its formatting from the first SmartShape selected. It creates a new ShapeSheet with one Geometry Section.

 

Subtract

A Subtract Shape Operation takes in to consideration all of the selected SmartShape symbols and returns a new SmartShape symbol which is the result of the Subtraction of all other selected SmartShapes from the first SmartShape selected. It draws its formatting from the first SmartShape selected. It creates a new ShapeSheet with one Geometry Section.

 

The beauty of Shape Operations is that by working with simpler pieces of a more complex path requirement and applying Shape Operations, complex paths can be created without the need for hundreds of trimming operations as would be required with a CADD program.

Remember that a single SmartShape symbol can only have one Fill, and one Line Formatting applied to it. If you need multiple colors and disparate line types in a single SmartShape symbol, then you will need to make use of Shape Groups.

One last time… because Shape Operations destroy the original SmartShape symbols, it is best to use these Operations PRIOR to any custom Formulae or Data being added to the SmartShapes being used in the Shape Operations.

 

Chapter 30 : A Second Divergence – Groups

Immediately above, we spoke of the fact that a given SmartShape symbol might well need several colors to be displayed within it, or it might need differing line weights and linetypes, or it might even need more than one Text Block to hold differing items of text at differing locations within the same SmartShape symbol. This is where Groups come in to play.

In Visio, Groups are much more than just a simple collection of objects brought together to make it easier to relocate them as a whole. In Visio, Groups are a Parent “Shell” SmartShape symbol with its own Text Block and one or more sub-Shape SmartShape symbols, each with own Geometry Section (s) and Text Block, each capable of its own unique formatting. Each item within the Group can hold custom Formulae that refer to other members of the Group and up to the Group itself. Control Handles on the Group can manipulate individual Geometry Paths of any member of the Group. Shape Data in members and the Group itself can reference each other, as well as custom calculations and formulae in User-Defined and Scratch Cells.

Parent and Child Relationships

The relationship between the Group SmartShape symbol itself and the SmartShape symbols which are part of the Group is a Parent – Child relationship. Imagine three SmartShape symbols on a Visio Drawing Page. Their Sheet ID’s are Sheet.1 , Sheet.2 , and Sheet.3. If all three SmartShape Symbols are selected and then Shape > Grouping > Group is selected from the Visio Shape Menu, the individual SmartShape symbols will retain their own Sheet.(n) ID and the Group will receive an Sheet.(n) ID of Sheet.4. Sheet.4 is the Parent of Sheet.1 through Sheet.3. Because these are at differing Scoping Levels, the members of the Group MUST refer to their Parent, the Group, as Sheet.4 and the Group must refer to each member as Sheet.1, Sheet.2, and Sheet.3, regardless of the friendly name assigned them via the Format > Special dialogue.

Unless the formatting of each member of the Group is protected or preserved (via the individual SmartShape symbol’s Protection Section or using a GUARD() Function), any Formatting of the Parent (The Group) will pass through to the individual children within that Group.

Keep in mind that members of a Group are still accessible to the end user by simply Clicking on the Group to select the Group and then Clicking again to sub-select the individual member of the Group. You can prevent this by Right-Clicking on the Group Shape and selecting Format > Behavior, and in the Selection drop-down list, ensure that the list item shows “Group only”.

Chapter 31 : A User-Defined Section of a ShapeSheet

Earlier I stated that User-Defined Cells Rows are evaluated by the ShapeSheet Recalculation Engine whenever the ShapeSheet is recalculated. This functionality lets you, as a ShapeSheet Developer, place Formulae to be evaluated in User Defined Cells and they can take appropriate action upon other Cells by referencing them in the User-Defined Cell Formulae.

Let’s again have a look at a User-Defined Section of a ShapeSheet.

The Name Cell, which, by definition, will hold Values like Row_1, Row_2, etc., can be renamed by Clicking into the Cell with the Red Text and typing in any valid name you wish to use for the particular row.

The Value Cell holds the actual Formula that you want to be evaluated by the Recalculation Engine. The Value Cell is capable of holding Formulas and Values. These may be entered as formulas or values as text, numbers, or numbers with units (number/unit pairs).

The Prompt Cell simply holds a comment to you, the ShapeSheet Developer, to assist you in knowing what in the world you had in mind when you created this User Defined Row in the first place. This text NEVER shows at the User Interface level, unless you specifically reference it in another Formula.

 

Chapter 32 : A Scratch Section of a ShapeSheet

Even before there was a User-Defined Section in a Visio ShapeSheet there was a place to hold custom Formulae and Values, the Scratch Section. When Visio 1.0 was introduced, the Scratch Section served as a workspace to create custom Formulae and hold calculations to add a greater level of intelligence to what would have otherwise been not – so – SmartShape symbols. The Scratch Section still exists under Visio 2007 and is equally as viable today as it was under Visio 1.0. It is also an equal repository to a User-Defined Cells Section, and in some ways better, though in some ways not quite as advanced.

Let’s have a look at a Scratch Section of a ShapeSheet.

The first, and immediate difference between a Scratch Row and a User-Defined Row is that a Scratch Row cannot be named. Cells in a Scratch Row will always be Scratch.X(n), Scratch.Y(n), Scratch.A(n), Scratch.B(n), Scratch.C(n), and Scratch.D(n). Like User-Defined Rows, you can add as many Scratch Rows as you care to.

The next thing we need to discuss is the type of Cells in a Scratch Row. Fairly obviously, the X and Y rows were meant to hold a coordinate pair; the X holding the ordinate, and the Y holding the abscissa. The A through D cells were meant to hold any various type of Formulae, numbers, text, etc.

Remember that ALL X and Y Cells are understood as having units. In other words, if you enter 3.1415926 into a Scratch.X1 Cell it will be understood from that time on as 3.1415926 in.

 

Chapter 33 : Unit-ed versus Unit-less Cells in a ShapeSheet

This brings us to a brief discussion of Unit – ed versus Unit – less Cells in a ShapeSheet. As we have discussed before, certain Cells like X and Y cells are meant to hold coordinate pairs, other cells such as Height and Width are also understood to hold number – unit pairs since they refer to size and position, which are, by their very nature, unit – ed values. Try entering 2.5 into a Height Cell and it will always become 2.5 inches. If you want millimeters you must explicitly enter 2.5mm. Visio’s internal units are, in fact, inches. Not because inches are better than any other unit of measurement… In fact the United States is just about the last place left on planet Earth still using the bluiddy things. However, Visio was created in the US, and therefore the Recalculation looks at any unit – less number that should be unit – ed, and automatically assumes that it must be inches. This is not as impactive in the US. However anywhere outside the US (or even in the US where metric units are used for international purposes) this can have HUGE ramifications. 13.75 in is NOT the same as 13.75 mm.

General Mathematics can also come into play when dealing with unit – ed versus unit – less values in cells. If you have a value of 9.0 inches in a Scratch X Cell and 2.0 inches in a Scratch Y Cell and you divide Scratch.X1 by Scratch .Y1 you would expect that the result would be 4.5 inches if the formula were in a Scratch.A1 cell. Take a look at the following:

Scratch Formulas with error

Scratch Values with error

Scratch Formulas Corrected

Scratch Values Corrected

When a unit – ed number is divided by a unit – ed number, per the standard rules of mathematics, the units cancel, and you are left with a unit – less number. The way to overcome this, presuming that you need a unit – ed number is to take the formula and multiply it times 1 of the units you require. This will result in the unit – ed number you are looking for in your Formula.

Chapter 34 : The Evaluation of Logical Expressions in ShapeSheets

As you work with Formulae within Cells of a ShapeSheet you will notice that many of the Cells evaluate to 1, 0 / True, False. Remember that within a ShapeSheet Cell False is ALWAYS zero (0) and True is ALWAYS simply non-zero: ANY non-zero. As a ShapeSheet Developer you can use this fact to your advantage. Consider the following:

You have designed a SmartShape symbol such that the SmartShape’s Fill should only appear when the Control Handle’s X position is within the SmartShape, not outside. Presuming that you have a Rectangle SmartShape symbol with a ShapeSheet containing both a Geometry Section and a Controls Section which looks similar to the following:

Note that in the Geometry1.NoFill Cell the formula “=Controls.Row_1<Width” evaluates to True any time the Control Handle of the SmartShape symbol is positioned at a point less than the Width of the SmartShape symbol’s Bounding Box and evaluates to False if the position is greater or equal to the Width of the SmartShape symbol. The use of the evaluation of the Formula in the NoFill is a highly convenient method of flipping the visibility of the SmartShape symbol’s fill based on an evaluation of a logical expression.

Whenever possible, utilize this methodology to design SmartShape symbols which perform at maximum efficiency based on how the ShapeSheet Recalculation Engine works.

Chapter 35 : SmartShape Symbols Respond to Events

Every Visio SmartShape symbol is capable of “signing up” for Event Monitoring. It is not the purpose of this text to detail Automation Programming to create these Event Sinks and detail the process of monitoring the firing of events. It IS the purpose of this text to discuss and teach the best usage of the Events Section of a ShapeSheet and what can normally be accomplished through the use of the Events Cells. Earlier I detailed what each Cell in the Events Section was already “signed up for” in terms of Event Monitoring. Below I will detail how the Events Section can be leveraged to create Events that can be triggered by the user from the user interface to empower the well mannered SmartShape symbol.

The Events Section of a ShapeSheet

Within the Events Section of any Given ShapeSheet you will find the EventDblClick Cell. As any of you who have ever attempted to edit the text of any SmartShape symbol knows, 99.99 times out of 100, the act of double-clicking on a SmartShape symbol, places the SmartShape symbol in Text Editing Mode. There are actually several possible reasons that this phenomenon works: (1) there is no formula at all (listed as No Formula in black text in the EventDblClick Cell), (2) the Formula in the EventDblClick Cell is listed as “=DEFAULTEVENT()”, or the Formula in the EventDblClick Cell is listed as “=OPENTEXTWIN()”.

The DEFAULT Event for a Double-Click action in the context of a SmartShape symbol is ALWAYS  Enter the Text Editing Mode.

Here is a list of the Default Events for the differing Contexts:

Object

Default event

Shape

Edit text.

Group

Do nothing.

OLE

Do primary verb.

Other

Do nothing.

 

Instead of utilizing the Default Event for the Double-Click Cell you can enter your own custom Function Call in this Cell to trigger any action you desire to take place. Perhaps you would like to call a Function which transfers you to another page in the Visio diagram whenever a specific SmartShape symbol is double-clicked. Presuming that a SmartShape Symbol named HighLevelViewSummary (Sheet.1) exists on Page 1 in a Visio Diagram and that the diagram contains both Page 1 and Page 2, you simply need to place the following formula in the EventDblClick Cell of Sheet.1’s ShapeSheet:

“=GOTOPAGE(“Page 2”)

and every time the user double-clicks anywhere on the face of the HighLevelViewSummary SmartShape symbol, the user will be immediately transferred from Page 1 (where the SmartShape symbol resides) to Page 2, which might contain a drill-down view of the processes in greater detail.   

The DEPENDSON() Function in a ShapeSheet Cell

Another function which may be placed in a ShapeSheet Cell is the DEPENDSON() Function. Here is its definition:

DEPENDSON Function

Creates a cell reference dependency.

DEPENDSON(cellref[,cellref2,...])

Remarks

This function always returns FALSE. It has no effect when used in an Event row or an Action cell.

Example

OPENTEXTWIN() + DEPENDSON(PinX,PinY)

Opens the text block for a shape whenever the shape's PinX or PinY cells change.

 

As you can see above, as the Recalculation Engine evaluates the ShapeSheet Cells, it encounters two Formulae (1) “=OPENTEXTWIN()” and (2) “=DEPENDSON(PinX,PinY)”. Note that these two Formulae are joined into one evaluated statement set by the plus sign (+). When the Recalculation Engine looks at and attempts to evaluate this set of Formulae, it sees that “if the Values in either/and/or the PinX or PinY Cells change, THEN evaluate the Function paired in the cell and, in this case, open the Text Editing Mode for text editing.

Adding Context Menus to SmartShape Symbols

There may be many times when you, as the SmartShape symbol designer, want the user to be able to trigger the implementation of a Function whenever the user Right-Clicks the SmartShape symbol and selects an item from the Context Menu. This is accomplished through the Actions Section of the ShapeSheet. The Actions Section looks like the following:

Some of the Cells in this Section are obvious, however I will concentrate on just two Cells here3: the Action Cell and the Menu Cell.

The Action Cell holds the actual Formulae you want to have Evaluated when the user selects the accompanying Menu item from the SmartShape symbol’s Context Menu. The Menu Cell hold the Text you want the user to actually see when they Right-Click to call the Context Menu.

For example, perhaps you want the end user to be able to work with and/or edit the SmartShape symbol’s Shape Data (Custom Properties) based upon a Right-Click action. In the particular Action Row in the Actions Section, you would place the item of text “Edit the SmartShape Symbol’s Shape Data” in the Menu Cell, and you would place the Function “=DOCMD(1312)” in the Action Cell (DOCMD(1312) is the Function and Command Number for Edit the Custom Properties in the old style Custom Properties Dialogue Box).

To insert a separator into the menu above an Action Cell Item shown in an Actions Row by the Menu Cell, use the BeginGroup cell. To display the command at the bottom of the menu, prefix the name with a percent character (%).

 

ShapeSheet Programming - Part 7

ShapeSheet - Chapter 24 : Control Handles

If you have ever dropped a SmartShape symbol onto a Page and noticed small yellow diamonds appearing on the SmartShape while it is selected, you have encountered Control Handles. If you let your mouse cursor rest over one of these Control Handles you will see a small Pop-Up which describes the purpose of that Control Handle. For example, many SmartShape symbols have a Control Handle, located by default, at the center of the SmartShape, which, when the SmartShape has Text entered onto the face of the SmartShape, appears. Floating the cursor over this Control Handle displays a Tip that tells you that the Control Handle is designed to assist you in relocating the position of the SmartShape symbol’s text. The Ethernet Backbone SmartShape symbol on the Network and Peripherals Stencil has, what appears to be, seven Control Handles shown on the Ethernet SmartShape symbol. Floating your cursor over any of these Control Handles displays a Tip that tells you that the Control Handle is designed to connect to an item of Network Equipment as a SmartShape symbol.

Control Handles are designed to manipulate some portion of the SmartShape symbol’s Geometry or Text or any other relocatable aspect of the SmartShape. They can be of great benefit to the Visio User, making it easy and visual to modify the SmartShape to meet the needs of the SmartShape symbol’s usage.

Let’s look at how these Control Handles are implemented. To add a Control Handle to a SmartShape symbol, you will need to open the ShapeSheet and add a Controls Section to the ShapeSheet for that SmartShape symbol. I will presume that you already have learned how to do this. When you have completed this task you will notice a new Controls Section in your ShapeSheet that looks similar to the Controls Section Shown below:

By default a Controls Section Row will be given a sequential Row number as its Name, as in, Controls.Row_1. You can edit and rename this Row to any valid name desired, such as “TextRelocate”, which will appear as Controls.TextRelocate. Also, by default, the Control Handle will appear on the face of the SmartShape symbol in the initial location determined by the X and the Y cells (note that these are in the Local Coordinate System for the SmartShape symbol). Visio will always provide an initial placement position of X = “Width * 0” and Y = “Height * 0”, such that the initial placement point for the Control Handle will be the lower left hand corner of the SmartShape symbol. You, of course can modify these Cells to place the initial placement position wherever you need the placement point to be. The XDynamics and the YDynamics Cells provide a base point from which a “rubber banding line” appears to be rooted when you drag the Control Handle. The root end of the line is at the XDynamics, YDynamics Point and the end point is at the yellow diamond location as dragged about by the user. By default Visio enters formulas of Controls.Row_1, Controls.Row_1.Y for these coordinates. This causes the root end to be originated at the point where the Control Handle was last located. I find that this can be a bit confusing to end users and as such I modify these two Cell’s Formulae to reflect a fixed, and logical, location with respect to the visual aspects of the SmartShape Symbol. The XBehavior and YBehavior Cells determine how the Control Handle should behave. The Values are shown listed below.

XBehavior Values:

Value

Behavior

Definition

0

Proportional

The control handle can be moved, and it also moves in proportion with the shape when it is stretched.

1

Proportional locked

The control handle moves in proportion with the shape but the control handle itself cannot be moved.

2

Offset from left edge

The control handle is offset a constant distance from the left side of the shape.

3

Offset from center

The control handle is offset a constant distance from the center of the shape.

4

Offset from right edge

The control handle is offset a constant distance from the right side of the shape.

5

Proportional, hidden

Same as 0, but the control handle is not visible.

6

Proportional locked, hidden

Same as 1, but the control handle is not visible.

7

Offset from left edge, hidden

Same as 2, but the control handle is not visible.

8

Offset from center, hidden

Same as 3, but the control handle is not visible.

9

Offset from right edge, hidden

Same as 4, but the control handle is not visible.

 

YBehavior Values:

Value

Behavior

Definition

0

Proportional

The control handle can be moved, and it also moves in proportion with the shape when it is stretched.

1

Proportional locked

The control handle moves in proportion with the shape, but the control handle itself cannot be moved.

2

Offset from bottom edge

The control handle is offset a constant distance from the bottom of the shape.

3

Offset from center

The control handle is offset a constant distance from the center of the shape.

4

Offset from top edge

The control handle is offset a constant distance from the top of the shape.

5

Proportional, hidden

Same as 0, but the control handle is not visible.

6

Proportional locked, hidden

Same as 1, but the control handle is not visible.

7

Offset from left edge, hidden

Same as 2, but the control handle is not visible.

8

Offset from center, hidden

Same as 3, but the control handle is not visible.

9

Offset from right edge, hidden

Same as 4, but the control handle is not visible.

 

The CanGlue Cell is a True / False Value which determines whether the “yellow diamond” end of the Control Handle can glue to any other point of geometry, vertices, etc. of another SmartShape symbol.

The Tip Cell takes a String as its Formula and displays a Tool Tip when the mouse Cursor is floated over the yellow diamond when the SmartShape symbol is selected (all Control Handle Tool Tips and the “Yellow Diamonds” are ONLY visible when the SmartShape symbol is selected).

You can add as many Controls Rows to the Controls Section of a ShapeSheet as you wish. To add a Control Row, Click into a Cell in an existing Controls Row and select Insert > Row or Insert > Row After from the Visio Row Menu.

Now that you have the base knowledge of how to create and use a Control Handle, let’s use this knowledge to create a Talking Word Bubble (like you see in comic strips and cartoons) where the tip of the mouthpiece is relocated on the SmartShape symbol by the usage of a Control Handle with Tool Tip.

In order to create the basic SmartShape, we will create an ellipse, and a triangle and use a Shape Operation to create a Union of the SmartShape symbols into a new SmartShape. We will then locate the point in the Geometry Path that corresponds to the tip of the mouthpiece. We will then add a Controls Section and reference that mouthpiece vertex in the Formulae of the Control Handle. Finally we will add a Tool Tip to inform the user as to the procedure for relocating the mouthpiece. I will also go over a few additional embellishments that will make the SmartShape symbol even more intelligent.


 

Let’s get started.

The illustration below shows the Ellipse SmartShape and the Triangle SmartShape. You are more that qualified to use the Visio Drawing tools to create these yourself.

Next we need to position the triangle over the ellipse in a logical position and then use a Shape Operation to create a Union of the two SmartShape symbols (remember that Shape Operations ALWAYS destroy the original SmartShape symbols and create a NEW SmartShape Symbol). To perform the Union Operation, ensure that BOTH SmartShape symbols are selected and then select Shape > Operations > Union from Visio’s Shape Menu. The newly created word bubble SmartShape Symbol is shown beside the two original SmartShapes in the illustration below:

 

Now let’s look at the Geometry Section of the ShapeSheet for the new word bubble SmartShape symbol. Notice the corresponding row in the Geometry Section and the “Pappa Smurf” Black Box Indicator showing us the vertex corresponding to the particular Row. This will be the Row that we will need to reference in the Controls Section when we add the Section to the ShapeSheet.

We’ll go ahead and add the Controls Section to the ShapeSheet by ensuring that the ShapeSheet Window is the Active Window and selecting Insert > Section… > Controls from the Visio Insert Menu. Then we will reference the Control Section’s X and Y cells in the Geometry1.X3 and Geometry1.Y3 cells. I have illustrated this below

REMEMBER TO TEST YOUR WORK ONLY ON A COPY OF THE SMARTSHAPE SYMBOL! When you select the SmartShape, the Control Handle (Yellow Diamond) will appear. Dragging the Control Handle around will move the vertex of the tip of the Mouthpiece.

In a production, real, development environment, I would slightly alter the steps above. Here is why… My personal preference is that the Bounding Box should remain around JUST the word bubble and that the mouthpiece should fall OUTSIDE the Bounding Box. Furthermore, the user should NEVER be allowed to drag the mouthpiece into the word bubble itself. The Tool Tip should inform the User what they need to do with this control handle. The user resizing the word bubble should leave the mouthpiece intact. And, finally, the root of the rubber banding line should always be at the center-top of the mouthpiece, where it joins the word bubble. The illustration below shows the steps and completed word bubble and the illustration below that shows the ShapeSheet to implement this.

Cells in the ShapeSheet to notice:

Protection Section : LockCalcWH

Geometry Section : Geometry1.X3 and Geometry1.Y3

Controls Section : X, Y, XDynamics, YDynamics, CanGlue, and Tip

Chapter 25 : Controlling the Bounding Box

As mentioned in the previous example, a refinement, if you will, is to ensure that the Bounding Box with its inherent Sizing Handles (in highly technical terms, the Green Things) always bounds only the area of primary interest. The ability for this to happen is held in the Protection Section with the LockCalcWH Cell.

Here is an example. You have created a rectangle and the value of the LockCalcWH Cell is set to 0 (False). You now add an additional vertex at the bottom center and place its Geometry2.Y value at “Height * -1”. When the Recalculation Engine evaluates the Bounding Box, it resizes it to encompass ALL of the new existing Geometry. What you had intended was for the Bounding Box to remain around the Rectangle and the line pass outside the Bounding Box. In order to implement this functionality, make certain that the LockCalcWH Cell value is set to 1 (True) BEFORE adding the additional Geometry. The illustration below shows this clearly.

                      

As you can see, it is definitely a more user-friendly experience for the end user to have the Bounding Box around the main SmartShape symbol and let manipulable items fall outside the Bounding Box.

Chapter 26 : Prohibiting Geometry Changes in a SmartShape by Users from the User Interface

While I am certain that there are a large number of both Visio Users and Visio SmartShape symbol Developers who vehemently dislike any SmartShape symbol being locked down such that they cannot change any aspect of the SmartShape symbol at will, there ARE reasons why this functionality SHOULD be implemented.

Going back to the example of the Grand Piano, if absolute control was released to the end user in being able to resize at will, the piano would distort and you would be left with things like an 88 key keyboard with 6” wide keys, or a key depth of 28”, or a piano length of 16 feet. You see my point, right? Part of properly planning and executing on the design of a well mannered SmartShape symbol is to design in constraints such that the SmartShape symbol behaves as it should as a digital counterpart to its real world intent.

To facilitate this constraint management, Visio, from within the ShapeSheet has provided two methodologies. These are (1) the Protection Section of the ShapeSheet, and (2) the Guard() Function.

The Protection Section of the ShapeSheet

As we saw above, the Protection Section provides numerous (20 to be exact) Cells, all of which hold Values of 0 or 1 (False or True) to disable or enable their Protection. In the discussion of a really simple rectangle above, I went into detail as to the functionality of each of these and therefore I will not repeat myself here, however, do not hesitate to implement these where necessary.

Those Protection Section Cells that directly affect user interface abilities, i.e. LockHeight, LockWidth, and Lock Rotate, grey-out the particular Sizing Handles affected. For example, when you set the LockWidth Cell to 1 (True), the Sizing Handles at Center-Left and Center-Right of the Bounding Box become grayed-out and the user interaction is blocked for these two handles.

Remember at all times that setting these values ONLY affects interaction from the User Interface. It is very easy for a Visio User to open a ShapeSheet and change any of these values at any time. 

The GUARD() Function

If you not only want the interaction to be blocked from the User Interface, but also want to prohibit any change to a ShapeSheet’s Cell Formula or Value, you can wrap any Formula or Value in the ShapeSheet Cell with a GUARD() Function. For example. Let’s presume that you do not want anyone to alter the Width of a SmartShape symbol. In the Shape Transform Section of the ShapeSheet you can take the Value listed as “3 in” and wrap it with a Guard Function thusly:

Width = “=GUARD(3 in)”

And as you can determine by testing on your own, no matter how the user tugs at the sizing handles or attempts to change the width with the Size and Position Dockable Window, the SmartShape symbol will remain at a constant 3” in width. Only by the user removing the GUARD() function from around the Formula or Value will the SmartShape symbol’s Width change.

Before, however, you get too carried away wrapping everything in sight in a GUARD() Function, remember that the only Cells that need to be guarded are those which have an interaction with manipulation at the user interface level. For example, it may make sense to guard the FillForegnd Cell in the Fill Format Section, but it might not make any sense to guard the LangID Cell in the Miscellaneous Section. As with all power… Use wisely!

Chapter 27 : Classes of Functions Applicable to ShapeSheet Formulae

Visio contains a wealth of Functions which, when utilized in ShapeSheet Cell Formulae, add a tremendous power in the creation of truly Intelligent SmartShape symbols. I tend to break these functions down by “class” of function. My categories include:

·         Numeric

·         Trigonometric

·         Conditional

·         Statistical


 

In the appendices at the end of this text, I have listed, and detailed, all of the available functions to Visio ShapeSheet Cells. I will, however, list some of the more commonly used Functions here

Numeric Functions

Numeric Functions include

ü  ABS() – Absolute Value of a number

ü  CEILING() – Rounds a number away from zero

ü  FLOOR() – Rounds a number toward zero

ü  INT() – Integer, Rounds a number down to the next integer

ü  INTUP() – Integer, Rounds a number up to the next integer

ü  LN() – Natural Logarithm of a number

ü  LOG10() – The Base 10 Logarithm of a number

ü  MODULUS() – Returns the remainder (modulus) resulting when a number is divided by a divisor.

ü  PI() – Returns the mathematical constant pi, which is 3.1415926535898

ü  POW() – Returns a number raised to the power of an exponent.

ü  RAND() – Returns a random floating point number from 0.0 to 1.0

ü  ROUND() – Rounds a number to the precision represented by numberofdigits

ü  SIGN() – Returns a value that represents the sign of a number

ü  SQRT() – Returns the square root of a number

ü  SUM() – Returns the sum of a list of numbers

ü  TRUNC() – Returns a number truncated to numberofdigits

Trigonometric Functions

Trigonometric Functions include

ü  ACOS() – Returns the arccosine of number, for example, the angle whose cosine is number

ü  ANG360() – Normalizes an angle's range to be 0 <= result < 2PI radians (0 <= result < 360 deg)

ü  ANGTOLOC() – Returns a transformed angle in the destination shape's local coordinate system

ü  ANGTOPAR() – Returns a transformed angle in the destination shape's parent coordinate system

ü  ASIN() – Returns the arcsine of a number, for example, the angle whose sine is number

ü  ATAN() – Returns the arctangent of a number, for example, the angle whose tangent is number

ü  ATAN2() – Returns the angle between the vector represented by x,y and the direction of the x-axis

ü  COS() – Returns the cosine of an angle

ü  COSH() – Returns the hyperbolic cosine of an angle

ü  DEG() – Converts the value of an angle from radians to degrees

ü  MAGNITUDE() – Returns the magnitude of the vector whose rise is A and whose run is B, multiplied by the respective constants constantA and constantB

ü  RAD() – Converts the value of an angle from degrees to radians

ü  SIN() – Returns the sine of an angle

ü  SINH() – Returns the hyperbolic sine of an angle

ü  TAN() – Returns the tangent of an angle

ü  TANH() – Returns the hyperbolic tangent of an angle

Conditional Functions

Conditional Functions Include

ü  AND() – Returns TRUE (1) if all of the logical expressions supplied are TRUE

ü  BITAND() – Returns a 16-bit binary number in which each bit is set to 1 only if the corresponding bit in both binarynumber1 and binarynumber2 is 1

ü  BITNOT() – Returns a 16-bit binary number in which each bit is set to 1 only if the corresponding bit in binary number is 0

ü  BITOR() – Returns a 16-bit binary number in which each bit is set to 1 if the corresponding bit in either binary number1 or binary number2 is 1

ü  BITXOR() – Returns a 16-bit binary number in which each bit is set to 1 if the corresponding bit in either but not both binary number1 and binary number2 is 1

ü  IF() – Returns valueiftrue if logicalexpression is TRUE

ü  NOT() – Returns TRUE (1) if logicalexpression is FALSE

ü  OR() – Returns TRUE (1) if any of the logical expressions are TRUE

Statistical Functions

Statistical Functions Include

ü  MAX() – Returns the largest number from a list

ü  MIN() – Returns the smallest number from a list

Additionally there are a litany of other SmartShape, Page, Document, Date and Time Functions available to you, as a ShapeSheet Developer. We will be using some of these in our work in this text, but many are left for you to peruse in the listing of all Functions at the end of this text.

 

Chapter 28 : How the Insert Function Command in Visio Assists in Working with ShapeSheet Formulas

When working with Functions and Formulae in ShapeSheet cells it is helpful to have a “syntax guide”, if you will, to assist in adding these Functions into Formulae in ShapeSheet Cells. Visio provides a tool to assist you, the ShapeSheet Developer, in adding these Functions.  This is the Insert Function Command.

When you have a ShapeSheet window open and are actively entering information into the Formula Editing Bar (above the ShapeSheet), with your mouse cursor in the editing line. Select Insert > Function from the Visio Insert Menu. This action will cause the Insert Function Dialog to appear. The Insert Function Dialog is shown below

The main List Box in the Dialog contains a list of each available Function within Visio’s ShapeSheet environment. Immediately below the List Box is a Check Box labeled “Insert arguments into formula bar”. It is my STRONG recommendation that this check box remain checked. It will decidedly assist you in working with the Function that you choose. To work with a Function, scroll through the list until you locate the Function you wish to use, Click on the Function Name in the list, ensure that the Insert arguments… check box is checked, and Click the OK Command Button.

When you have completed this task you will note that the desired Function is entered into the Formula editing bar along with the templitized arguments. This is shown below

As is true of all Visio Functions, the Function Name is followed by an open parenthesis then each argument, comma separated, then a closing parenthesis. The arguments are entered in what I refer to as their “templatized” form, i.e. the argument name. You will need to substitute the actual Value, Function,  or Formula for each named, required, argument to the Function. At any time, if you need help in understanding the syntax of the argument or the Function as a whole, you can press the F1 key and obtain on-line help for that Function.

With the introduction of Visio 2007, Help has become an on-line feature. This presumes that you are connected at every moment you are developing your SmartShape symbols. I, personally, find this a bit frustrating. A brilliant alternate to this is to download the free Visio 2007 SDK from the Microsoft MSDN Visio Download Site. As part of that SDK you will have a .CHM file which is the entire Visio Automation and ShapeSheet reference (the same reference as was found in the older “Developing Visio Solutions [DVS]” text). All entries are cross-referenced and hyperlinked.

 

ShapeSheet Programming - Part 6

ShapeSheet - Chapter 23 : What Makes Truly Intelligent Behavior in SmartShape Symbols as it Applies to Geometry?

As I stated before (and most probably will state many times yet again…) the hallmark of a well designed SmartShape symbol is that it (1) behaves as it would in the real world, and (2) that it is fully optimized to be the singularly most efficient SmartShape symbol possible via proper references, and the most efficient Formulae possible. Let’s look at an example of how a SmartShape symbol SHOULD behave and look at how to design in this functionality utilizing the ShapeSheet.

The First Visio Example – The Intelligent Arrow

Below you will see an arrow “lifted” from a general Bitmap-based Graphics drawing tool.

 

Here is the same arrow when stretched in width utilizing its sizing handles

Notice that when the arrow is stretched in width, the arrow, especially the arrowhead dramatically distorts. The arrowhead angle is no longer at a 45-degree angle.

In the real world, when an arrow symbol is stretched in width, the growth should take place entirely in the shaft of the arrow and the arrowhead should remain at a constant 45-degree angle, and remain the same size. If the arrow is stretched or shrunk in height, the arrowhead should resize appropriately with no distortion to the arrowhead. Finally if the arrow is shrunk in width such that the arrow’s width is less than the width of the arrowhead itself, the symbol should be intelligent enough to never let the arrow and arrowhead “implode” when the resizing is complete.

It is exactly this arrow that was used as a proof of concept in the beginning of Visio Corporation to illustrate the power of the ShapeSheet and how simple Formulae can provide the Intelligence to make the arrow behave in a manner optimal in the real world.

I am going to assist you in walking through the process of creating the Smart Arrow step by step.

(1)    Launch Visio 2007

(2)    When Visio begins and you are at the Getting Started Screen, select File > New > New Drawing (US units) from the Visio File Menu

(3)    Your default drawing page should be an 8-1/2”X11” Portrait Mode Page. If necessary, press Ctrl+W to Zoom out to see the entire Page

(4)    Ensure that your Grid and Your Rulers are being shown. If they are not, select View > Grid , and View > Rulers from the Visio View Menu

(5)    Ensure that the Drawing Toolbar is open and active in the Visio Drawing Workspace. To validate this, Right-Click on any open area of the Toolbar Area above the Drawing Surface, look and validate that the Drawing Toolbar is Checked

(6)    Select the Line Tool from the Drawing Toolbar by Clicking on the Line Tool Icon on the Drawing Toolbar

(7)    Move your mouse cursor over the Visio Drawing Surface until it is located at a point where it is 5” to the right of the left edge of the Page and 4” above the lower edge of the Page. You will see a small coordinate pair display at the bottom of the drawing area, just below the Shapes Pane (Stencil Area). This coordinate display will provide real-time feedback as to where your cursor is located.

(8)    With your cursor located at X=5”, Y=4” , Click, Hold, Drag, and Release at a point Exactly 1” above and 1” to the right of where you began. The Coordinates are X=6” , Y=5” . Use the Grid to assist you. Also use the Virtual Snap Guides to assist you.

(9)    Without moving the cursor, Click(right on top of the exact point where you ended the first line segment), Hold, Drag, and Release at a point Exactly 1” above and 1” to the left of where you ended the last line segment. The Coordinates are X=5” , Y=6” . Notice how the SmartShape symbol that you are creating has just changed from a 1-D SmartShape to a 2-D SmartShape.

(10) Without moving the cursor, Click, Hold, Drag, and Release at a point Exactly 0.5” below where you ended the last line segment. The Coordinates are X=5” , Y=5.5” .

(11) Without moving the cursor, Click, Hold, Drag, and Release at a point Exactly 2” to the left of where you ended the last line segment. The Coordinates are X=3” , Y=5.5” .

(12) Without moving the cursor, Click, Hold, Drag, and Release at a point Exactly 1” below where you ended the last line segment. The Coordinates are X=3” , Y=4.5” .

(13) Without moving the cursor, Click, Hold, Drag, and Release at a point Exactly 2” to the right of where you ended the last line segment. The Coordinates are X=5” , Y=4.5” .

(14) Without moving the cursor, Click, Hold, Drag, and Release at a point Exactly 0.5” below where you ended the last line segment. The Coordinates are X=5” , Y=4” . This is the same point where you began. You should notice that the SmartShape symbol just became filled. You now have a relatively dumb SmartShape symbol that looks like a right-pointing arrow.

(15) Select the Pointer Tool from the Visio Toolbars.

Here is a tip that you should take on as a RULE when designing SmartShape symbols : NEVER work on your original SmartShape symbol while under development. ALWAYS work on a copy of the SmartShape. To make a clone of a SmartShape symbol, Select the SmartShape, hold down the Ctrl Key, Click, Hold, Drag and Release to drag out an exact clone of the original SmartShape symbol.

(16) Drag out a copy of the arrow SmartShape you just created. Pull on its width to make it wider. Notice how the arrowhead distorts. Let’s look at why this happens.

Open the ShapeSheet for the original arrow that you have just created. The Shape Transform and Geometry Sections should look like the Illustration below:

Notice that the Width of the SmartShape is 3”, and the Height is 2”. Notice that the place where we began drawing our arrow is in Row 1 of the Geometry Section and has an X Cell Formula of “Width * 0.6667” and a Y Cell Formula of “Height * 0”. This says that the back edge of the arrowhead is positioned at exactly 2/3 of the way along the Width of the SmartShape symbol’s Bounding Box and at the bottom edge of the Bounding Box. This is why when the arrow is stretched in width, the arrowhead distorts. It is doing EXACTLY as it is programmed to do: remain at a point 2/3 of the width, so when the width increases, the distance between the back edge of the arrowhead and the tip of the arrowhead increases proportionally with the entire arrow. This is NOT the behavior we need. In order to correct this behavior we need to alter the formulae in some of the Geometry cells such that the arrowhead remains a fixed distance from the tip of the arrow.

Before continuing, we need a very quick refresher course in Trigonometry and Geometry. Look at the illustration below:

Remembering back to your Trig and Geometry classes… In order for the arrowhead’s angle to remain at a constant 45 degrees, what must the relationship between Side A and Side B be? Correct! Side A and Side B must be EQUAL in order for the angle to remain at a constant 45 degrees.

By default the position of the arrowhead’s X ordinate is expressed as a function of the SmartShape symbol’s Width. There is the problem. We need to express the point as a function of the SmartShape symbol’s Height. If we change the default formula in the Geometry1.X1 Cell from:

Geometry1.X1 = Width * 0.6667

To:

Geometry1.X1 = Width – (Height/2)

The result will be that the X ordinate of that point will be at the SmartShape symbol’s Width minus the quantity Height/2 (the same as the distance from the side of the arrowhead to the tip of the arrowhead in Y)

You will also notice that the formulas expressed in the Geometry Section are very inefficient. We need to clean these up to be more efficient by removing unnecessary references to things like Width * 0 and Height * 0 and Width * 1 and Height * 1. Remember…? We discussed this earlier. Now I am also (a) a lousy typist (b) and a lazy typist. If I can get away without having to key in loads of references and text I will! Visio provides a very nice way of obtaining a reference to another cell without keying in the reference. The technique is as follows:

Click into the Cell you need to set a reference in. Press the equal sign key (=). Click into the Cell you wish to reference. Press the Enter Key. Notice that this fills in the reference without the worry of typo’s or other mistakes.

Notice also that we can make use of these references to dramatically streamline the work that the Recalculation Engine must do. Notice that we DO NOT chain references, but rather we point all references back to the same Cell for efficiency.

The following two Geometry Sections show the changed Formulae in the Geometry Section for “Before” and “After” the Changes:

Before Changes

After Changes

Here is what the Arrow looks like when stretched in Width AFTER the new ShapeSheet Formulas have been applied. (I’ve colored the arrow with a Fill color, just to make it more readable.

Notice how the entire growth has taken place in the Shaft of the Arrow and no distortion of the arrowhead takes place.

We still need to take care of the issue of the arrowhead “imploding” when the width of the arrow is too small. Here is what such an implosion looks like:

At what point does this aberration take place? Right! When the Width of the SmartShape symbol is less than half the Height. So all we really need to do is apply a constraining rile that stipulates that the Width can never be resized to a point less than half the Height.

We have not yet spent much time on User-Defined Cells in a ShapeSheet. User-Defined Cells are evaluated whenever the Recalculation Engine needs to reevaluate the ShapeSheet for the applicable SmartShape symbol. Therefore if we created a User-Defined cell with the following Formula:

User.Row_1 = IF(Width<(Height/2),SETF(GetRef(Width),(Height/2)+(Width*0.2)),0)

If the Width of the SmartShape symbol ever gets less than half the height of the SmartShape symbol, then set the formula in the Width Cell to be Height/2 + (Width * 0.2), otherwise do nothing at all.

Now if we try to make the arrow too narrow it will simply appear as:

To add a User-Defined Section to the ShapeSheet:

(1)    Open the ShapeSheet

(2)    Select Insert > Section from Visio’s Insert Menu

(3)    Select User-defined Cells from the Dialog

(4)    Click the OK Command Button

Then add the above formula to the first row in the User-defined Cells Section.

Working your way through this example teaches you a great number of techniques. You have learned how to:

ü  Draw with Visio’s Drawing Tools

ü  Use the Grid and Dynamic Guides to assist in accuracy

ü  Develop Formulae to add intelligence to SmartShape Symbols through their ShapeSheet Cells

ü  Test on COPIES of your work

ü  Add new Sections to a ShapeSheet

ü  Understand how the Recalculation Engine Evaluates ShapeSheet Cells

ü  Understand how IF() Functions work

ü  Understand how SETF() Functions Work

ü  Understand how GETREF() Functions work

Next we will look at more advanced techniques for manipulating parts of SmartShape symbols.

 

ShapeSheet Programming - Part 5

Section Three: An Immersion into ShapeSheet Development

 

ShapeSheet - Chapter 17: Another Look at the Interaction between SmartShape Symbols and Their ShapeSheets

Thus far I have instructed you to open a SmartShape Symbol’s ShapeSheet by selecting Window > Show ShapeSheet from the Visio Window menu in the Diagramming Window Context. There is a far easier method to go directly to a particular SmartShape’s ShapeSheet. In order to do this, however, you first (and only once) need to change a setting from the Tools > Options Dialog in Visio. Within the Tools Options Dialog, go to the Advanced Tab and ensure that the “Run in developer mode” is checked as follows:

 

Returning to fundamentals once more, when you make changes to a SmartShape symbol from the User Interface, you are actually editing the Formulae or Values in the SmartShape symbol’s ShapeSheet. When you edit the Formulae or Values in a ShapeSheet, you are changing aspects of that ShapeSheet’s SmartShape. The SmartShape and the ShapeSheet are one and the same. Additionally when you manipulate a SmartShape via any Automation Controller you are actually editing Formulae and Values in the associated ShapeSheet. Again… The SmartShape and the ShapeSheet are one and the same.

The following illustration provides an easy to understand visual of the relationship:

 

Chapter 18: Coordinate Systems and Visio SmartShape Symbols

To control a SmartShape Symbol’s Size or Position, you describe it in terms of a Coordinate System. A Coordinate is comprised of an X, Y pair. The first element in the Coordinate Pair is the Ordinate (the X or Horizontal movement increasing from Left to Right). The second element in the Coordinate Pair is the Abscissa (the Y or Vertical movement increasing from Bottom to Top).

Local Coordinates refer to the SmartShape Symbol itself. The origin is ALWAYS the lower-left corner of the SmartShape Symbol’s Bounding Box. The ShapeSheet’s Geometry Section is expressed in the coordinate system of the SmartShape symbol itself.

Page Coordinates refer to the Page. SmartShape symbols always reside on a Page. The Page can be thought of as the Parent of the SmartShape symbols it contains.

The Page Coordinate System describes the location of the SmartShape Symbol on the Drawing Page. The Page’s Origin is the lower left corner of the Page, EVEN IF THE RULER VIEW HAS BEEN CHANGED. It is the Absolute Origin.

 

Chapter 19: Local Coordinates and Parent Coordinates

The Parent Coordinate System is the local coordinate system of the SmartShape’s Parent. Think in terms of nesting order: Parent and Child.

There can be additional levels of nesting when Group SmartShape symbols are involved. The Group SmartShape symbol is the Parent of its Members. The Parent Origin is at the lower left corner of the Group SmartShape symbol’s Bounding Box.

The Page is the ultimate Parent of everything it contains. The Shape Transform Section of the ShapeSheet uses Units of Measure of the Parent Coordinate System to represent a SmartShape symbol’s Width, Height, and Position on the Page.

This understanding is vitally important when developing custom formulae which position sub members of a Group SmartShape within the Group SmartShape and when positioning the Group SmartShape symbol on the Page. The Shape Transform Section always expresses its units in its Parent’s Coordinate System while the Geometry Section, the Text Transform Section, The Controls Section, and the Connection Points Section always express their units in the coordinate system of their Parent; the SmartShape symbol itself.

Chapter 20: The Pin and the Local Pin

Fundamental to understanding how Visio SmartShape symbols are positioned within a Visio Diagram as well as fundamental to understanding how SmartShape symbols are placed, rotated, resized and flipped is the understanding of the unique qualities of PinX and PinY as well as LocPinX and LocPinY. Here is how you can think about Pins and Local Pins in Visio:

To place a SmartShape symbol on a Page you push an imaginary pushpin through the SmartShape symbol to attach it to the Page.

Two imaginary holes are formed; one in the Page and one in the SmartShape symbol

The location of the imaginary hole in the Page is denoted by the PinX and PinY in the SmartShape symbol’s ShapeSheet. The Pin Values are relative to the Page (PinX, PinY might have been called “ParPinX” and “ParPinY” since they locate the SmartShape symbol relative to its Parent – in this case the Page)

The location of the imaginary hole in the SmartShape symbol is denoted by the LocPinX and LocPinY in the SmartShape symbol’s ShapeSheet. These Pin Values are relative to the SmartShape symbol

The illustration shown below will assist in clarifying this concept

 

The Pin is the point around which a SmartShape symbol is rotated and flipped.

The Pin in Visio is equivalent to the “Insertion Point” or “Reference Point” for CAD users

Moving the entire SmartShape symbol on the Page changes the PinX and PinY Values in the ShapeSheet but does NOT alter the LocPinX and LocPinY Values in the ShapeSheet

Moving the Local Pin on the SmartShape symbol changes BOTH the PinX and PinY Values in the ShapeSheet AND the LocPinX and LocPinY Values in the ShapeSheet

To move the Local Pin on the SmartShape symbol move your mouse cursor over the Rotation Handle on the SmartShape symbol, then move your mouse cursor over the top of the Local Pin, which is now displayed as a small green and black circle in the center of the SmartShape symbol, Click and Drag the Local Pin to its new desired location. The Local Pin can also be moved by altering the LocPinX and LocPinY Values in the SmartShape symbol’s ShapeSheet.

The Pin is also the Point where an Instance of a Master SmartShape is dropped. This is worth considering when designing SmartShape symbol Masters for End Users of Visio Solutions.

Chapter 21: Controlling Physical Aspects of SmartShape Symbols through ShapeSheets

If you look at a Visio SmartShape Symbol as it exists on a Visio Drawing Page, the two properties that you first see are the Geometry Items (i.e. lines, arcs, and splines) that make up the Geometry Path of the SmartShape symbol and the Fill of the SmartShape symbol. As you have seen earlier, these properties are controlled by four Sections of a SmartShape symbol’s ShapeSheet; the Shape Transform Section, the Geometry Section, the Line Format Section and the Fill Format Section. By manipulating the Values and Formulae in the various Cells in these Sections, the Physical appearance of the SmartShape symbol is, obviously, changed as well.

In default, simple SmartShape symbols tend to have constant Values in the Shape Transform Section for things like Height, Width, Angle, PinX, and PinY. They tend to have Formulae based upon percentages of Height and Width in the LocPinX, LocPinY, and the Geometry Rows. By altering only the Values in the Height and Width Cells the entire size of the SmartShape symbol is altered and all of the Cells that refer to these two Cells are Evaluated by the Visio Recalculation Engine. Therefore each of the Geometry Path segments are recalculated and redisplayed, keeping the path closed and the Fill confined within the Path Boundaries.

As a ShapeSheet Developer, you have the ability to alter the Formulae in any of these Cells to constrain the behavior of the SmartShape to meet your needs. Perhaps you need to design a SmartShape symbol in such a manner that if the user alters the Width of the SmartShape symbol by tugging on a Green Sizing Handle at the Middle Right of the SmartShape symbol, the Height changes as well. When you first create the rectangle the Width Cell contains a Value of “3 in” and the Height Cell contains a Value of “2 in”. These Values are the same as the Formulae: simple static size values. However the specialized constraint that you need to program into the SmartShape symbol is that if the Width of the SmartShape is less than or equal to 3 inches the Height should be three-quarters of the Width, otherwise the Height should be one-half the Width. This can be entirely accomplished by changing the default Formula in the Height Cell from its original “2 in” to the following:

=IF(Width>3in,Width*0.5,Width*0.75)

Let’s analyze this formula a bit deeper. The Function that we are using here is a typical IF() Function. The IF() Function takes three arguments. Each Argument is separated by a comma. The First Argument is the Condition, the If part, if you will. “IF the Value in the Width Cell evaluates to a value Greater than 3 inches”. The Second Argument is the Then part. “Then put a Value in the Height Cell that is the evaluation of the Value in the Width Cell multiplied by 0.5”. The Third Argument is the Else (Otherwise) part. “Else put a Value in the Height Cell that is the evaluation of the Value in the Width Cell multiplied by 0.75”. IF > THEN > ELSE.    = IF(Condition,Then,Else).    =IF(Width > 3 in, Width * 0.5, Width * 0.75).

This simple IF() Function adds a level of intelligence to the SmartShape symbol such that when the User of the SmartShape symbol adjusts the Width of the SmartShape, the Height of the SmartShape behaves in a manner which is consistent with how the symbol should behave in the “real world”. This is the hallmark of good ShapeSheet development: when creating SmartShape symbols, design them to behave exactly as they would in the user’s real world perception.

For example, if you are designing a Grand Piano… pianos have 88 keys. Pianos do not grow or shrink in width across the keyboard. Pianos keyboard depth is a fixed distance. There are two general sizes of Grand Pianos; Full Grand Pianos, and Baby Grand Pianos. These two sizes have different dimensions regarding their physical length front to back. A well designed Grand Piano SmartShape symbol would have a fixed keyboard, a fixed width and a length which can be altered to only two specific lengths by the selection of the Piano type.

Always consider how the Visio user will interact with the SmartShape symbol you design. Analyze the ShapeSheet to see what Cells will be affected when the user interacts with the SmartShape Symbol. Utilize the Formulae and Values to optimize the Recalculation Engine’s processing of the ShapeSheet. These tips will greatly assist you in developing the best possible SmartShape Symbols via the ShapeSheet.

ShapeSheet - Chapter 22 : Geometry – The Path of the Line/Arc/etc. in a SmartShape Symbol

When we looked at the collection of Sections that make up a really simple Rectangle SmartShape symbol above, I offered the analogy that you could think of yourself as a pen plotter and that each row in the Geometry Section of the ShapeSheet described a movement of the pen in the pen plotter. With the Rectangle, this was very simple.

(1)    Move the pen, without drawing, to a point of, relative to the SmartShape symbol’s Bounding Box, X=0, Y=0, which is the lower left corner, or origin.

(2)    Draw a line to a point of X = the Width of the Smart Shape Symbol’s Bounding Box, Y = 0

(3)    Draw a line to a point of X = the Width of the Smart Shape Symbol’s Bounding Box, Y = the Height of the Smart Shape Symbol’s Bounding Box

(4)    Draw a line to a point of X = 0, Y = the Height of the Smart Shape Symbol’s Bounding Box

(5)    Draw a line back to a point referencing the same point you located in step (1) above. This creates a closed Geometry Path.

This is pretty logical and I am certain you can clearly visualize this set of steps.

Keep in mind that there are quite a few “drawing tools” at your disposal when it comes to each row of a Geometry Section. Among these are Lines, Arcs, Elliptical Arcs, Splines, and Polylines. Each of these “tools” creates a row with varying Cells. I will not go through each row type and describe each and every Cell in the Row in this Chapter, however, in the Appendix at the end of this text, you will find a complete compendium of these rows and what each Cell entails.

LineTo, MoveTo, etc.

I do want to take a moment to assist you in understanding how to change a Row Type from within a simple ShapeSheet and during this process, assist you in making choices for the Row Type you might want to use.

In order to do this, consider the following SmartShape symbol:

Notice that there are four places where the lines stop and then after a gap begin again. As you have seen previously, a Geometry Path is a continuous movement from its origin back to its origin again. In order to create this type of Visual look to this SmartShape symbol, I have modified four of the Rows in the Geometry Section of the ShapeSheet. The modification I made was to change the Row Type from LineTo to MoveTo. Again, using the Pen Plotter analogy, I simply told the Geometry Path to pick up the pen and Move it to the next location and then set the pen back down again to ready it for the next drawing movement.

Here is the Geometry Section of this ShapeSheet to illustrate the changed rows

To change a Row Type perform the following steps:

(1)    Open the ShapeSheet for the subject SmartShape symbol

(2)    Scroll down until you locate the Geometry1 Section

(3)    Plant your mouse cursor into either the X or the Y Cell of a Given Row. If you look back to the Drawing Page and at the Subject SmartShape Symbol, you will see a small black hollow box over the particular vertex which equates to the corresponding Row in the Geometry Section. (Trivia note: This functionality was named “Pappa Smurf” during the development of Visio 1.0.)

(4)    Right-Click on the X or Y Cell and select Change Row Type from the Context Menu of the ShapeSheet.

(5)    In the Change Row Type Dialog, Click on the Radio Button for MoveTo (it should be currently set to LineTo) and Click the OK Command Button

(6)    Note that the Line now has a gap at that particular location

Here is what the Change Row Type Dialog looks like:

You can add Rows to a Geometry Section by simply planting your mouse cursor into a Row,  then selecting Insert > Row or Insert > Row After from the Visio Insert Menu.

By adding Rows, modifying Rows by Change Row Type, and entering custom Formulae in specific Cells of a Geometry Section you can create highly sophisticated Geometry Paths and ensure that the SmartShape symbol will perform in a manner consistent with its behavior in the real world.

1 - 10 Next

 Visibility.biz

Visibility.biz Logo

 ‭(Hidden)‬ Admin Links