Wednesday, 19 November 2014

Creating custom data graphics with programmable behavior with Visio 2010

About a year ago I was designing a wiring cabinet layout for work.  I was using Visio to make a drawing, but I ended up re-organizing my terminal blocks several times.  This meant that I was constantly re-editing the drawing which was time consuming.

I have used external data sources before, so I thought would look into using them for this as well, after all, modifying lists of information in Excel is much easier than in Visio.  However, for my drawing I wanted to have a somewhat custom result.  This ended up being much more complicated than I expected.  Since I was not able to find much useful info on this on other websites, I figured I should probably write down what I learned to help the next poor sap out.  But I never did.

Recently, I did a similar thing again, and was shocked to realize how much I had forgotten.  Hence, I am writing it down now so that I will remember.

Step 1: Create a new shape to serve as a template

The blank shape template
There are generally pretty good instruction on creating new master shapes, so I am not going to go into that.  This step ends up being pretty easy once you know how.  The important thing in this step that I did not think was obvious is this: Do not add any fields or forms in the master template that you want from your data source.  This comes later.  However if you want any connection points, it's best to add them now.  For my little JB layout, this was my final result.  Pretty simple.






Step 2: Add external data to the shape

Once again, there are lots of tutorials on the basics of adding external data.  But basically build up your Excel sheet with all the data fields you want to add.  If you forget a field and want to add one later, I think you pretty much have to start the process again from this point.  Once you have added the external data source, add a copy of your shape template to your workbook and link it to the external data.  This part is all pretty standard.  The result is sort of messy.  Here's mine:
The blank template with an unorganized data source

Step 3: Organize the data

 This part is pretty much just clicking, but it takes a bit to get the hang of it.  I recommend you get familiar with the ctrl+1-4 shortcut keys.  You will be doing a lot of switching between the pointer, and the text block object at this stage.  First though, you want to select the 'Edit Data Graphic' option to set up the basic shape parameters and positioning.  To do this properly, you need to select the 'Edit Item' option.  This is pretty intuitive but the one gotcha I found is that even though the edit item menu makes it appear that you can modify all of the items in one go, you really can only change one item at a time if you want different items to have different parameters.  So make your changes to each one and click 'OK' to close the dialog for that item.  Then open the 'Edit Item' for the next item in your list.  Rinse and repeat.  

Clicking the 'Apply' button between changes is useful as it allows you see what your changes have done.  It's not always intuitive.
Basic Data graphic editing


Manual data graphic editing
Once you've got this part done, close this dialog.  From here you'll have to manually edit the position of each of your fields.  It can be a little tedious as you have to click through the automated grouping to hit each item, but it's not too bad.  Here was my final result.

All this is pretty well covered in other places / obvious.  It's the next step, which while really simple, is the one that took me a while to figure out.

Step 4: Save this modified graphic as a new master shape

Simply select the now pretty shape you have just finished making (make sure you have selected the whole group) and drag that bad boy into your custom shapes category.  This saves all the work you have done for future use.  You probably want to leave your blank template saved as well.  If you need to modify anything in the future, it's usually easier to start at square one than to fight with your existing template.

It's pretty easy, but as I said, I couldn't find any good tutorials on this.  So that's it.  You're done.  Unless, like me, you tend to fixate on silly things.

For me it was that sometimes some of my terminal block don't have any real wiring attached.  Then my template looks silly when the line is blank but a wire is shown in the drawing.

See!  It looks dumb

Bonus: Basic dynamic manipulations with VB 

So what I wanted was a way to make the right line on the 2nd row invisible when there was no data associated with it.  Again, the end result is pretty easy to accomplish, but it took me a while to figure out how.

Select only the line
I made the line visible by selecting the 'Border: Bottom' option in the 'Edit Shape' dialog earlier.  Turns out this property is also shown in the 'shapesheet' under the developer tab.  (You may need to perform additional steps to make the developer tab visible).  To see the shapesheet for only the line you want to edit, you'll need to right click on the line itself and click on 'show shapesheet'.  At this point it's really easy to select the whole group's shapesheet, which you don't want.

Once the shape sheet is open, you can do whatever you want to the objects properties.  However the documentation on this is not great.  My VB skills are decent, but the hard part was figuring out where to start.  However eventually I figured out that the User.BorderType field was the one I wanted.

By default this field pointed to some internal value that basically said it was getting its value from the one you selected in the earlier drop down menu.  I changed it to this rather simple (once I figured it out...) chunk of code and badda bing badda boom, now my border disappears if no text is entered in that field.  I did the same for my little fuse rating, but using the border value 2 for outline instead of 1 for bottom.

=IF(LEN(User.ValueText)=0,0,1) 
Obviously, this gets pretty powerful.  But that's all I wanted to do so I packed it away at this.  It was getting pretty hard to justify this use of time at work as it was.  I made this change to both lines in my shape, and then saved this new object as the new master shape.

Much Better.  The OCD side of me is happy now.

Anyway, hope that helps somebody.


No comments:

Post a Comment