Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS VISIO, Set Database Properties of Entity shape programatically

Posted on 2011-09-19
2
Medium Priority
?
1,721 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 1500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you ever created a custom Visio stencil – a collection of your own unique master shapes – and then created a drawing by dragging masters onto the drawing page? Have you then made changes to the stencil master and wondered why the shapes on the …
Scott A. Helmers Partner, Harvard Computing Group Microsoft Visio MVP Background Microsoft has added more enhancements and new features to Visio 2010 than to any release since they purchased the Visio product line in 2000. In addition, the com…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Loops Section Overview

971 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