Visio Guy

Visio Discussions => General Visio => Topic started by: whwaldrep on June 23, 2009, 06:36:14 PM

Title: Index shape data
Post by: whwaldrep on June 23, 2009, 06:36:14 PM
Hello all, I have a Shape that has a "Shape Data" called Step.  I want this to index +1 from the one above each time.  I need this for flowcharts I am creating and sometimes I need to add a step and I have to go thru and renumber all of them.  If there is not one above I want it to be manually entered.  So I guess my big question it how to obtain the shape's data that is above the current one.

Thank you for your help.
Title: Re: Index shape data
Post by: Paul Herber on June 24, 2009, 01:35:02 PM
Not going to be at all easy, you are going to need some code to do that and even that won't be easy.
The shape's index number is determined by the order in which shapes were dropped on the page and there is no ordering within Visio for a shape's physical position on a page.
Title: Re: Index shape data
Post by: whwaldrep on June 24, 2009, 08:06:38 PM
Ok thanks, I will just use this for now.

I just will need to add this to the right click context.  Any suggestions would be appreciated.


Sub Index()
    Dim xy As Visio.Selection
    Dim xyz As Integer
    Set xy = Visio.ActiveWindow.Selection
    xyz = 0
    Dim x As Visio.Shape
    For Each x In xy
        x.Cells("User.Step").FormulaForceU = Chr(34) & xyz & Chr(34)
        xyz = xyz + 1
    Next x
End Sub
Title: Re: Index shape data
Post by: whwaldrep on June 24, 2009, 10:10:30 PM
Ok so I was trying to create a right click menu for the shape, in the shape file I created the macro called Public Sub IndexSub().  In the action of the shape I put =Runaddon("ThisDocument.IndexSub")

But it does nothing...  Any Help?


*Edit:  Thank you all for your help.  I did firgure this out with =RUNMACRO(Module.Proc)
Title: Re: Index shape data
Post by: Paul Herber on June 25, 2009, 03:48:40 PM
Well, that code isn't going to do what you asked for, but it will set User.Step in the shapes but in the order in which the shapes were put on the page.
You could do something like:
1. clear the User.Step for each shape.
2. Create a data structure array (index: integer; Y: float)
3. for each shape get the shape.Index and shape.PinY and put the numbers into the array.
4. sort the array on the Y
5. set the User.Step in the order of the indexes in the sorted array.

Title: Re: Index shape data
Post by: whwaldrep on June 25, 2009, 05:36:50 PM
No you are exactly right, I kind of settled on this.  As I could not figure another way of doing it easily.