Solved

MS VISIO, Set Database Properties of Entity shape programatically

Posted on 2011-09-19
2
1,619 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The Question Several times in recent years, someone has posted a question at EE asking whether they could display the Windows directory structure – folders and subfolders – using Visio. When one person specifically asked about displaying directory …
Book Review: Using Microsoft Visio 2010 by Chris Roth   Disclaimer: The author of Using Visio 2010 is a friend and fellow Visio MVP. Whether you’re new to Visio or are upgrading to Visio 2010 from a previous version, you will find a lot to like…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

930 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

18 Experts available now in Live!

Get 1:1 Help Now