0

I want to add multiple texts on the connector line as per the image below. I am using c# code to automate the process. Below is my code which I have used. It is not giving the exact output as I had expected. Any help in this regard would be highly appreciated.

Visio.Shape vsoLastShape = visioPage.Shapes.get_ItemFromID(lastshapeID);
vsoLastShape.ConvertToGroup();
                            
Visio.Selection vsoSelections = app.ActiveWindow.Selection;
vsoSelections.Select(vsoLastShape, (short)VisSelectArgs.visSelect);

Visio.Shape vsoGroupShape = vsoSelections.Group();

vsoGroupShape.Text = "Testing 12";
vsoGroupShape.TextStyle.PadLeft(10);

enter image description here

3 Answers 3

1

Whatever method (manual, C#, VBA or whatevber) you use, one shape can only contain one text. If you want to add more than one text then you need to convert the shape into a grouped shape. Then you can add a shape to the group and set that sub-shape's text to what you want.

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

2 Comments

I have doing the same this in my code to convert the shape to a group but while adding text to the group it will not work. Can you suggest the issue with my code as it is not working as i expect.
Your code is now grouping twice, a ConvertToGroup() and a Group(). You don't need the .Group(). Set vsoGroupShape as the result of the ConvertToGroup. Then add a new shape to the page, call it, say, vsoNewShape, set its text and location, then add it to the group.
0

Shape .Characters object used in conjunction with .Text allows for some flexibility.

    private string nl = Environment.NewLine;
    public void MultiText() {
    try {
        // using = System.Windows.Forms;
        // using Vis = Microsoft.Office.Interop.Visio;

        Vis.Application app = Globals.ThisAddIn.Application; // or launch Visio 
        Vis.Document vDoc = app.Documents.Add(""); // new blank document

        Vis.Shape c1 = app.ActivePage.DrawOval(1, 1, 1.5, 1.5);
        Vis.Shape s1 = app.ActivePage.DrawLine(1.5, 1.25, 4, 1.25);
        s1.Text = $"Shape1{nl}Line2";
        Vis.Shape c2 = app.ActivePage.DrawOval(4, 1, 4.5, 1.5);

        Vis.Shape c3 = app.ActivePage.DrawOval(1, 3, 1.5, 3.5);
        Vis.Shape s2 = app.ActivePage.DrawLine(1.5, 3.25, 4, 3.25);
        s2.Text = $"Shape2";
        Vis.Shape c4 = app.ActivePage.DrawOval(4, 3, 4.5, 3.5);
        
        app.ActiveWindow.CenterViewOnShape(c4, Vis.VisCenterViewFlags.visCenterViewDefault);
        app.ActiveWindow.Zoom = 1.2;
        app.ActiveWindow.Selection.DeselectAll();
        app.DoCmd((short)VisUICmds.visCmdDeselectAll);

        System.Windows.Forms.MessageBox.Show($"2 Shapes with text.", "Continue...");

        // reset the Text on Shape #2 and define 2 separate ranges
        s2.Text = "";
        // alocate a range 
        Characters range1 = s2.Characters;
        range1.Begin = 0;
        range1.End = 3;
        range1.Text = "Name";
        // alocate another
        Characters range2 = s2.Characters;
        range2.Begin = 4;
        //range2.End = 7;
        range2.Text = $"{Environment.NewLine}Type";

        MessageBox.Show($"Now change Font Size", "Continue...");
        // change font size or any of numerous properties 
        range1.CharProps[(short)Vis.VisCellIndices.visCharacterSize] = 16;
        range2.CharProps[(short)Vis.VisCellIndices.visCharacterSize] = 8;
        //range2.CharProps[(short)Vis.VisCellIndices.visCharacterStrikethru] = 1; // 1-true 0-false

        MessageBox.Show($"Big Name!{nl}little Type.", "OK to continue");

    } catch (Exception ex) {
        ta.LogIt($"Err {ex.Message} Trace {ex.StackTrace}");
    }

}

Comments

0

You may want to check this post and used the uploaded stencil. (Requires registration to see and download the attachment): http://visguy.com/vgforum/index.php?topic=6318.msg25957#msg25957

Comments

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.