Visio Guy

Visio Discussions => Programming & Code => Topic started by: rmarma on April 19, 2012, 03:42:44 PM

Title: creating Visio doc from a vb.net program
Post by: rmarma on April 19, 2012, 03:42:44 PM
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
Title: Re: creating Visio doc from a vb.net program
Post by: aledlund on April 19, 2012, 03:53:21 PM
some thoughts
http://www.youtube.com/playlist?list=PLA8338A6E5726E9E1&feature=view_all

some further thoughts
http://www.youtube.com/playlist?list=PLBAFAAC68D36484CA&feature=view_all

al
Title: Re: creating Visio doc from a vb.net program
Post by: JohnGoldsmith on April 19, 2012, 04:39:12 PM
...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 (http://www.microsoft.com/download/en/details.aspx?id=12365)

Best regards

John
Title: Re: creating Visio doc from a vb.net program
Post by: rmarma on April 26, 2012, 04:45:04 PM
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.

Title: Re: creating Visio doc from a vb.net program
Post by: aledlund on April 26, 2012, 05:28:50 PM
You might check this out
http://visguy.com/vgforum/index.php?topic=1160.msg4999
it's vba, but should be easily portable to vb.net

al
Title: Re: creating Visio doc from a vb.net program
Post by: rmarma on April 26, 2012, 05:50:48 PM
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
'
Title: Re: creating Visio doc from a vb.net program
Post by: aledlund on April 26, 2012, 07:00:21 PM
"thisDocument" is the vba project. If you check at the top of the file you should find a property tlStartDate.
al
Title: Re: creating Visio doc from a vb.net program
Post by: rmarma on April 27, 2012, 05:55:32 PM
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
Title: Re: creating Visio doc from a vb.net program
Post by: aledlund on April 27, 2012, 07:38:56 PM
google application.alertresponse

http://msdn.microsoft.com/en-us/library/ff767782.aspx

al
Title: Re: creating Visio doc from a vb.net program
Post by: rmarma on May 02, 2012, 03:02:58 PM
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
Title: Re: creating Visio doc from a vb.net program
Post by: aledlund on May 02, 2012, 03:54:35 PM
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
Title: Re: creating Visio doc from a vb.net program
Post by: rmarma on May 02, 2012, 04:34:24 PM
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
Title: Re: creating Visio doc from a vb.net program
Post by: aledlund on May 03, 2012, 11:56:41 AM
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
Title: Re: creating Visio doc from a vb.net program
Post by: rmarma on May 07, 2012, 02:44:47 PM
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
Title: Re: creating Visio doc from a vb.net program
Post by: Paul Herber on May 07, 2012, 04:20:54 PM
timelineShape.Connects is the collection.

Console.Write sends text to the VBA immediate console.

Title: Re: creating Visio doc from a vb.net program
Post by: aledlund on May 07, 2012, 07:20:03 PM
The timeline add-in doesn't use connection id's, it uses guid's. In the modTLManipulation you should find a routine that is called findSynchronizedParent that is used to match the guid that is stored in the child shape.
al
Title: Re: creating Visio doc from a vb.net program
Post by: rmarma on May 08, 2012, 02:27:32 PM
forgive my ignorance but where do I find modTLManipulation or findSynchronizedParent
Title: Re: creating Visio doc from a vb.net program
Post by: aledlund on May 08, 2012, 03:47:38 PM
It's in the example software that was referenced earlier
http://visguy.com/vgforum/index.php?topic=1160.msg4999#msg4999

al