Solved

MS VISIO, Set Database Properties of Entity shape programatically

Posted on 2011-09-19
2
1,601 Views
Last Modified: 2012-06-21
Hi Experts,

How can one set Database Properties (add key and non-key columns with data types, etc.) of the Visio ENTITY shape programatically?

Please advise.
0
Comment
Question by:AnwaPeck
2 Comments
 
LVL 11

Accepted Solution

by:
Visio_Guy earned 500 total points
Comment Utility
Generally, the discipline-specific solutions are closed, with no published APIs or instructions on how to drive them programmatically.

There are, however, a few things to check out.

1. The Page's ShapeSheet. (Turn on Developer mode, right-click the page, choose Show ShapeSheet). Here you'll find a few cells in the User-defined Cells section that you can set programmatically, and that might help you to tweak the document to your liking.

 Database Page ShapeSheet
2. Look at individual Entity shape ShapeSheets. User-defined cells and Actions are interesting places to explore. Looks like you can show or hide various key-related items, but I'm not sure if that's what you need.

3. Look at the object stored in the Document (local) Stencil for the file. This master has a shape that is some sort of COM "bit bucket" that you might be able to tear apart, but I'm not sure if it's really possible. The solution itself reads and writes data to this object.

Probably more questions than answers, but hopefully helps.
0
 

Author Closing Comment

by:AnwaPeck
Comment Utility
Thank You Visio_Guy!

Regret the delay.

Had to find some time over the past few days to upskill myself so that I could understand and follow the advice given. (Newbie!)  Some notes on the experience:
1. Using the advice given, I could drive out - programmatically - what I needed
2. When inside cell values inside the ShapeSheet window, I hit PF1 (out of sheer desparation) and the exact page of VISIO Help that i needed popped up!
3. The ENTITY shape consists of two 'shapes' (with each having its own shapesheet).  My life become much easier when I stumbled upon that fact.
4. In my solution I generate an ENTITY the way it appears in Visio Professional... without requiring Visio Professional on the user machine!!!

My working solution(again, in VBScript). Would appreciate any feedback:

'VBScript for VISIO
Dim MyApp, MyTemplate, MyPage, MyDoc, MyShpPage, MyShapeChars, _
    MyEntityShape, CurShape, VertPos, HorizPos

'Create new Visio Page Object
Set MyApp = CreateObject("Visio.Application")
Set MyTemplate = MyApp.Documents.Add("dbmodl_m.vst")
For Each MyDoc In MyApp.Documents
  If (MyDoc.Name = "ENTITY_M.VSS") Then
    Set MyStencil = MyDoc
    Exit For
  End If
Next
Set MyDoc = Nothing
Set MyEntityShape = MyStencil.Masters.ItemU("Entity")
Set MyPage = MyApp.ActivePage
Set MyShpPage = MyPage.PageSheet
VertPos = MyShpPage.CellsU("PageWidth").ResultIU / 2
HorizPos = MyShpPage.CellsU("PageHeight").ResultIU - 1

'Drop an entity shape
Set CurrShape = MyPage.Drop(MyEntityShape, VertPos, HorizPos)

'Set character properties & text content of the the header sub-shape
CurShape.Shapes.Item(1).CellsU("Char.Font") = 4
CurShape.Shapes.Item(1).CellsU("Char.Size").Result("pt") = 8
CurShape.Shapes.Item(1).CellsU("Char.Style") = 0
CurShape.Shapes.Item(1).Text = "MYTABLE"

'Set character properties & text content of the the fields sub-shape
CurShape.Shapes.Item(2).CellsU("Char.Font") = 4
CurShape.Shapes.Item(2).CellsU("Char.Size").Result("pt") = 8
CurShape.Shapes.Item(2).CellsU("Char.Style") = 0
CurShape.Shapes.Item(2).Text = "PK" & Chr(9) & "MyKeyFld01" & Chr(10) & _
                                                     "PK" & Chr(9) & "MyKeyFld02" & Chr(10) & _
                                                     "PK" & Chr(9) & "MyKeyFld03" & Chr(10) & _
                                                     Chr(13) & Chr(10) & _
                                                     Chr(9) & "MyField01" & Chr(10) & _
                                                     Chr(9) & "MyField02" & Chr(10) & _
                                                     Chr(9) & "MyField03" & Chr(10) & _
                                                     Chr(9) & "MyField04" & Chr(10) & _
                                                     Chr(9) & "MyField05"

'Bold & underline key fields so that Entity looks (Visio) Professional....
Set MyShapeChars = CurrShape.Shapes.Item(2).Characters
MyShapeChars.Begin = 0
MyShapeChars.End = 3
MyShapeChars.CharProps(2) = 17
MyShapeChars.Begin = 3
MyShapeChars.End = 14
MyShapeChars.CharProps(2) = 21
MyShapeChars.Begin = 14
MyShapeChars.End = 17
MyShapeChars.CharProps(2) = 17
MyShapeChars.Begin = 17
MyShapeChars.End = 28
MyShapeChars.CharProps(2) = 21
MyShapeChars.Begin = 28
MyShapeChars.End = 31
MyShapeChars.CharProps(2) = 17
MyShapeChars.Begin = 31
MyShapeChars.End = 42
MyShapeChars.CharProps(2) = 21

'Insert dividing lines so that Entity looks (Visio) Professional....
CurrShape.Shapes.Item(2).CellsU("User.LineCount") = 9
CurrShape.Shapes.Item(2).CellsU("User.DBHidePKSeperatorLine") = False
CurrShape.Shapes.Item(2).CellsU("User.DBHideTabLine1") = False
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Periodically someone asks me whether there’s a way to automatically convert all of the pages in a Visio drawing to PowerPoint slides. There have even been a few times when I’ve wanted to do that myself but I never really had enough incentive to figu…
Meetings to discuss business process can waste time, and often do .  The meeting's dialog can get confusing when participants have different professional perspectives and backgrounds.  A jointly-developed process picture helps wade through the confu…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now