creating Visio doc from a vb.net program

Started by rmarma, April 19, 2012, 03:42:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rmarma

I'm a vb.net newbie and a visio complete newbie - Ive written programs that create and update excel spreadsheets so I know a little about automation
what I want to do is create a Visio doc in VB.net from parameters in a database file (timeline, intervals, milestones)
my first effort was to records macros in Visio while I created a doc but I am  having difficulty translating the code to vb.net -

before showing the code I have currently I was wondering if anyone has any examples of creating a visio doc with shapes entirely within vb.net

I want to thank all you programmer types that spend time helping with these visio questions - we are all busy and to take time to assist is very much appreciated


JohnGoldsmith

...also, if you haven't already, make sure you download the Visio 2010 SDK.  It has a code library of VBA, VB.NET and C# examples:

http://www.microsoft.com/download/en/details.aspx?id=12365

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

rmarma

found an example in the sdk - so now can create a timeline with a milestone and interval - what I want to do now is set the properties (start stop date, scale, timeformat, description etc ) but I cant find a way to reference them - in aledlund's example vba code found in DR_TimeLine.vsd he can rightclick on  thisdocument and see a list of properties that include tlstartdate, tlstarttime, tlenddate, tlendtime etc
thisdocument is a visio object whose name value is DR_TimeLine.vsd (the name of the drawing)

but In my VB progam when I right click the document object whose name property is mytesting.vsd (the name of my drawing) I see a lesser list of properties
that dont include tlstarttime, tlendtime etc

2nd question which may be related how do I get / set values in the shapes shapesheet

thanks


the question being how do I reference shape objects properties in a VB program in order to set them.


aledlund


rmarma

thats the example I was using and the problem is I cant find the equivalent to the ThisDocument object  -
'
Dim visApp As Visio.Application
    Set visApp = Application
    Dim visDoc As Visio.Document
    Dim visMaster As Visio.Master
    Dim visTL As Visio.Shape
     Dim dblBeginDate As Double
    dblBeginDate = CDbl(ThisDocument.tlStartDate)
    If dblBeginDate = 0 Then Exit Sub
'

aledlund

"thisDocument" is the vba project. If you check at the top of the file you should find a property tlStartDate.
al

rmarma

using the MS article Article ID: 305199 - Last Review: April 16, 2007 - Revision: 6.2 "How to automate Visio with Visual Basic .NET"
I was able to create a timeline and set the begin and end dates
as in
  tlStartDate = CDate("01/01/2012")
  tlStopDate = CDate("1/01/2013")
  dblBeginDate = CDbl(tlStartDate.ToOADate)
  dblEndDate = CDbl(tlStopDate.ToOADate)
  timelineShape.Cells("user.visBeginDate").Formula = dblBeginDate.ToString()
  timelineShape.Cells("user.visEndDate").Formula = dblEndDate.ToString()

my question now is how do I prevent the visio app from popping up the timeline parameters data entry box when the timeline shape is dropped on the document

thanks


rmarma

thanks
the problem I'm having now is how to determine if a interval or milestone is above or below marker (user.visAboveMarker)
I'm looping thru the shapes and if its one of these type of shapes I want to read the property
tmpString = vShapes(i).Cells("User.visAboveMarker").Formula returns "Unexpected end of file."
when I look at the shapesheet for the milestone I dont see user.visAboveMarker in the list of user defined cells
I can flip the shape using   milestoneShape.FlipVertical() if I'm creating the doc but I want to determine the orientation when I read in a doc

aledlund

If you examine the shape and the user.? isn't there, then an error would be normal. If you're looking for a cell and there is a chance it is not going to be there you can adopt a couple of different strategies.
First wrap the call in a try...catch...endtry so the  error stays local to your call. Then check to see if you got a real response or Nothing. The second choices is to wrap your call in a "if visShape.CellExists( ? )" then go test for the cell value. My preference is to (almost) always check to see if the cell exists before attempting to read from it.

al

rmarma

some of the milestone shapes are above the timeline some are below - all return false when check for existence of cell.""User.visAboveMarker"
I'm reading a visio doc in VB storing all the shape data closing the doc then opening a blank one onto which I want to recreate the timeline
what property can I read to determine if an original shape was above or below the timeline in order to recreate the doc faithfully
if "User.visAboveMarker" doesnt exist is there another property I could examine

aledlund

since the root of your question is reading shape information, perhaps this will give you some ideas/insight

http://davidjpp.wordpress.com/2009/02/02/copying-data-from-one-shape-to-another/

al

rmarma

visio doc has 2 timelines on it and I'm trying to determine in a vb program which milestones , intervals are connected to which shape(timeline)

'this returns nothing

If blnHaveTimeline Then
                timelineShape = vShapes(i)
                For Each cnx In timelineShape.Connects
                    Console.WriteLine(cnx.FromCell.Name)
                Next cnx
            End If

as does

For Each cnx In vPage.Connects
            Console.WriteLine(cnx.FromCell.Name)
            Console.WriteLine(cnx.ToCell.Name)

        Next
any suggestions greatly appreciated

Paul Herber

timelineShape.Connects is the collection.

Console.Write sends text to the VBA immediate console.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/