0

Using C# and Microsoft Interop Office Visio, I am trying to change the direction of a cross-functional flowchart.

To do this manually, I have to do the following:

  1. click on cross-functional flowchart in the menu bar
  2. click on direction in the ribbon
  3. choose left to right or right to left

I'm using Visio 2019.

If this can be done using VB or VB.net, that's also good. Anything to automate this process.

1
  • cross-post Commented Apr 17, 2024 at 15:09

1 Answer 1

1

The Cross Functional Flowchart template is one of the solutions that has a backing addon. The addon puts up the ribbon controls and the writing to the various shapes in the solution. You can use the Event Monitor tool in the SDK to see what cells get changed, but sometimes it's better to let the addon handle the work, as it may be (as in this case) setting multiple cells.

For this solution you don't have to worry about the shape being selected it seems, so you just need to invoke the right addon with the right arguments.

An example might look like this:

void Main()
{
    var vApp = MyExtensions.GetRunningVisio();  
    var vPag = vApp.ActivePage;
    
    // Create selection based on master to get hold of the shape instance
    Visio.Master cffMaster = vPag.Document.Masters.ItemU["CFF Container"];
    Visio.Selection sel = vPag.CreateSelection(Visio.VisSelectionTypes.visSelTypeByMaster,
                                           Visio.VisSelectMode.visSelModeSkipSuper,
                                           cffMaster);
    Visio.Shape cffShape = sel.Count > 0 ? sel[1] : null;   
    
    ToggleCffDirection(cffShape);
}

private void ToggleCffDirection(Visio.Shape cffShape)
{
    if (cffShape is null)
        throw new ArgumentNullException(nameof(cffShape));

    if (cffShape.HasCategory("CFF Container"))
    {
        bool isRtl = cffShape.CellsU["User.RTL"].ResultIU != 0;
        
        // Find the Cross Functional Flowchart addon based on its universal name
        foreach (Visio.Addon addon in cffShape.Application.Addons)
        {
            if (addon.NameU.Equals("CFF", StringComparison.Ordinal))
            {
                if (isRtl)
                {
                    addon.Run("/left_to_right");
                }
                else
                {
                    addon.Run("/right_to_left");
                }
                break;
            }
        }
    }
}

You might want to improve the code by finding the addon outside of the method and passing it in as an argument, but it depends on what you're doing in the rest of your code.

Sign up to request clarification or add additional context in comments.

2 Comments

The 'GetRunningVisio' call is just my extension method for getting hold of the application object from LINQPad. I wrote about it here: visualsignals.typepad.co.uk/vislog/2015/12/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.