Solved

MS VISIO, Set Database Properties of Entity shape programatically

Posted on 2011-09-19
2
1,627 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
ID: 36560100
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
ID: 36572677
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unable to view Visio documents in Windows Explorer preview pane. 4 1,357
Visio 2010 - 4 367
Visio , croping 4 69
Command Button for all layers 3 34
David Parker’s latest book, Microsoft Visio 2010: Business Process Diagramming and Validation, will give you the tools to turn flowcharts and other business diagrams into valuable, data-driven corporate assets. Armed with the knowledge you’ll gain f…
The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article we’ll examine containers. We’ll explore lists (http://www.experts-exchange.com/Microsoft/Applications/M…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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