We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Unable to set Text Position at the bottom

Hi Team,

Tried various ways unable to set the text position at the bottom any help is appreciated. Please check the image to see how it renders. Trying to set text to bottom/close to the box it belongs to.

image.png (17.6 KB)

// Set text position at the bottom,
shape.TextXForm.TxtLocPinY.Value = shape.TextXForm.TxtHeight.Value;
shape.TextXForm.TxtPinY.Value = 0;

or

            //https://docs.aspose.com/diagram/net/working-with-text-boxes/#:~:text=Aspose.Diagram%20API%20allows%20developers%20to%20control%20the%20text,interact%20with%20these%20properties%20programmatically%20using%20Aspose.Diagram%20for.NET.
            shape.TextXForm.TxtLocPinY.Value = shape.TextXForm.TxtHeight.Value;
            //shape.TextXForm.TxtLocPinX.Value = shape.TextXForm.TxtHeight.Value;
            shape.TextXForm.TxtPinY.Value = 0;
            shape.TextXForm.TxtPinX.Value = 0;

@ak1234

Could you please share sample source files along with complete code snippet with us? We will test the scenario in our environment and address it accordingly.

Hi Team please find the sample snippet, source file and output file

using Aspose.Diagram;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aspose.Diagram.Examples.CSharp.Working_with_Text_Boxes
{
public class SetShapeTextPositionAtBottom
{
public static void Run()
{
// ExStart:SetShapeTextPositionAtBottom
// The path to the documents directory.

        License license = new License();

        license.SetLicense(@"C:/Test1<a class="attachment" href="/uploads/discourse_instance3/60003">Drawing1.zip</a> (394.2 KB)

/Test/Downloads/Aspose.Total.NET.lic");

        string dataDir = RunExamples.GetDataDir_ShapeTextBoxData();


        // Load source Visio diagram
        Diagram diagram = new Diagram(dataDir + "Drawing1.vsdm");

        var shapes = diagram.Pages.GetPage("Page-1").Shapes;
        var index = 0;
        foreach (Shape shape in shapes)
        {
            shape.Text.Value.SetWholeText($"Index - {index}");

            // Set text position at the bottom,
            // TxtLocPinY = "TxtHeight*1" and TxtPinY = "Height*0"


            shape.TextXForm.TxtLocPinY.Value = 0;
            shape.TextXForm.TxtPinY.Value = shape.XForm.Height.Value;

            // Set orientation angle
            double angleDeg = 0;
            double angleRad = (Math.PI / 180) * angleDeg;
            shape.TextXForm.TxtAngle.Value = angleRad;
            index++;
        }
        //// Get shape
        //long shapeid = 1;
        //Shape shape = diagram.Pages.GetPage("Page-1").Shapes.GetShape(shapeid);

        //// Set text position at the bottom,
        //// TxtLocPinY = "TxtHeight*1" and TxtPinY = "Height*0"
        //shape.TextXForm.TxtLocPinY.Value = shape.TextXForm.TxtHeight.Value;
        //shape.TextXForm.TxtPinY.Value = 0;

        //// Set orientation angle
        //double angleDeg = 0;
        //double angleRad = (Math.PI / 180) * angleDeg;
        //shape.TextXForm.TxtAngle.Value = angleRad;

        // Save Visio diagram in the local storage
        diagram.Save(dataDir + "SetShapeTextPositionAtBottom_out.vsdm", SaveFileFormat.VSDM);
        // ExEnd:SetShapeTextPositionAtBottom
    }
}

}

For all the nodes when setting text position at bottom. Seeing on the line. Please advise

image.png (8.3 KB)Drawing1.zip (394.2 KB)

@arun.rudrangi

An investigation ticket as DIAGRAMNET-52649 has been logged in our issue management system to analyze this requirement. We will further look into it and let you know as soon as it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

@asad.ali Thank you.

@arun.rudrangi

Could you please try using the below code and let us know in case you still face any issues:

foreach (Shape shape in shapes)
{
if (shape.NameU.Contains("Dynamic connector"))
{
continue;
}
shape.Text.Value.SetWholeText("Index - {index}");
//Set vertical align to bottom
shape.TextBlock.VerticalAlign.Value = VerticalAlignValue.Bottom;

            // Set text position at the bottom,
            // TxtLocPinY = "TxtHeight*1" and TxtPinY = "Height*0"

            shape.TextXForm.TxtPinX.Value = shape.XForm.Width.Value*0.5;
            shape.TextXForm.TxtPinY.Value = shape.XForm.Height.Value*0.5;
            shape.TextXForm.TxtWidth.Value = shape.XForm.Width.Value;
            shape.TextXForm.TxtHeight.Value = shape.XForm.Height.Value;
            shape.TextXForm.TxtLocPinX.Value = shape.TextXForm.TxtWidth.Value*0.5;
            shape.TextXForm.TxtLocPinY.Value = shape.TextXForm.TxtHeight.Value*0.5;


            // Set orientation angle
            double angleDeg = 0;
            double angleRad = (Math.PI / 180) * angleDeg;
            shape.TextXForm.TxtAngle.Value = angleRad;
            index++;
        } 

@asad.ali Thank you for providing inputs and responding quick.

  1. Issue we are facing is with connectors. Here they are skipped Please don’t skip them.
    if (shape.NameU.Contains(“Dynamic connector”))
    {
    continue;
    }
  2. On the connector we are unable to set number close to arrow. so that will avoid confusion for which connector the number belongs to.
    Please set the text to index and remove dynamic connector skip. That will help us to see the issue. shape.Text.Value.SetWholeText("{index}");
  3. Want to set Number close to arrow on the connector bottom. To make it clear which connector that number belongs to.
    Please let me know if a call/Meeting helps.

@arun.rudrangi

We are checking it and will get back to you shortly.

@arun.rudrangi
Please refer to this sample code:

        foreach (Shape shape in shapes)
        {
            if (shape.NameU.Contains("Dynamic connector"))
            {

                //You can use other logic to manipulate these values
                shape.TextXForm.TxtPinY.Value -= 0.2;
                continue;
            }
            shape.Text.Value.SetWholeText(string.Format("Index - {0}",index));
            //Set vertical align to bottom
            shape.TextBlock.VerticalAlign.Value = VerticalAlignValue.Bottom;
            // Set text position at the bottom,
            // TxtLocPinY = "TxtHeight*1" and TxtPinY = "Height*0"

            shape.TextXForm.TxtPinX.Value = shape.XForm.Width.Value*0.5;
            shape.TextXForm.TxtPinY.Value = shape.XForm.Height.Value*0.5;
            shape.TextXForm.TxtWidth.Value = shape.XForm.Width.Value;
            shape.TextXForm.TxtHeight.Value = shape.XForm.Height.Value;
            shape.TextXForm.TxtLocPinX.Value = shape.TextXForm.TxtWidth.Value*0.5;
            shape.TextXForm.TxtLocPinY.Value = shape.TextXForm.TxtHeight.Value*0.5;


            // Set orientation angle
            double angleDeg = 0;
            double angleRad = (Math.PI / 180) * angleDeg;
            shape.TextXForm.TxtAngle.Value = angleRad;
            index++;
        }

Thanks.

Thank you Philip for the quick response. Here is the snipped i tried

Goal am trying to achieve is connectors need to show the number at the bottom of arrow so that will be readable when having multiple connectors.
Please check the attachment connector 3 iSetShapeTextPositionAtBottom_out (2).zip (404.1 KB)
s close to its bottom of the arrow/connector. But 11,13,15,
19,23,27,31 33 very hard to understand where they belong to.

Please use latest.zip sharing both input and output and let me know if any meeting helps. To expedite this. Thank you for all the support.
using Aspose.Diagram;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Aspose.Diagram.Examples.CSharp.Working_with_Text_Boxes
{
public class SetShapeTextPositionAtBottom
{
public static void Run()
{
// ExStart:SetShapeTextPositionAtBottom
// The path to the documents directory.

        License license = new License();

        license.SetLicense(@"C:/Users/rudraar/Downloads/Aspose.Total.NET.lic");

        string dataDir = RunExamples.GetDataDir_ShapeTextBoxData();

        // Load source Visio diagram
        Diagram diagram = new Diagram(dataDir + "Drawing1.vsdm");

        var shapes = diagram.Pages.GetPage("Page-1").Shapes;
        var index = 0;
        foreach (Shape shape in shapes)
        {
            index++;
            shape.Text.Value.SetWholeText($"{index}");
            if (shape.NameU.Contains("Dynamic connector"))
            {
                shape.TextBlock.VerticalAlign.Value = VerticalAlignValue.Bottom;
                //You can use other logic to manipulate these values
                shape.TextXForm.TxtPinY.Value -= 0.2;
                //shape.TextXForm.TxtPinX.Value -= 0.2;
                //shape.TextXForm.TxtPinY.Value = shape.XForm.Height.Value * 0.5;
                //shape.TextXForm.TxtPinX.Value = shape.XForm.Width.Value * 0.5;
                shape.TextXForm.TxtWidth.Value = shape.XForm.Width.Value;
                shape.TextXForm.TxtHeight.Value = shape.XForm.Height.Value;
                //shape.TextXForm.TxtLocPinX.Value = shape.TextXForm.TxtWidth.Value * 0.5;
                //shape.TextXForm.TxtLocPinY.Value = shape.TextXForm.TxtHeight.Value * 0.5;
                continue;
            }
            
            //Set vertical align to bottom
            shape.TextBlock.VerticalAlign.Value = VerticalAlignValue.Bottom;

            //// Set text position at the bottom,
            // //TxtLocPinY = "TxtHeight*1" and TxtPinY = "Height*0"

            shape.TextXForm.TxtPinX.Value = shape.XForm.Width.Value * 0.5;
            shape.TextXForm.TxtPinY.Value = shape.XForm.Height.Value * 0.5;
            shape.TextXForm.TxtWidth.Value = shape.XForm.Width.Value;
            shape.TextXForm.TxtHeight.Value = shape.XForm.Height.Value;
            shape.TextXForm.TxtLocPinX.Value = shape.TextXForm.TxtWidth.Value * 0.5;
            shape.TextXForm.TxtLocPinY.Value = shape.TextXForm.TxtHeight.Value * 0.5;


            // Set orientation angle
            double angleDeg = 0;
            double angleRad = (Math.PI / 180) * angleDeg;
            shape.TextXForm.TxtAngle.Value = angleRad;

            //shape.Text.Value.SetWholeText($"Index - {index}");

            //// Set text position at the bottom,
            //// TxtLocPinY = "TxtHeight*1" and TxtPinY = "Height*0"


            //shape.TextXForm.TxtLocPinY.Value = 0;
            //shape.TextXForm.TxtPinY.Value = shape.XForm.Height.Value;

            //// Set orientation angle
            //double angleDeg = 0;
            //double angleRad = (Math.PI / 180) * angleDeg;
            //shape.TextXForm.TxtAngle.Value = angleRad;
            //index++;
        }
        //// Get shape
        //long shapeid = 1;
        //Shape shape = diagram.Pages.GetPage("Page-1").Shapes.GetShape(shapeid);

        //// Set text position at the bottom,
        //// TxtLocPinY = "TxtHeight*1" and TxtPinY = "Height*0"
        //shape.TextXForm.TxtLocPinY.Value = shape.TextXForm.TxtHeight.Value;
        //shape.TextXForm.TxtPinY.Value = 0;

        //// Set orientation angle
        //double angleDeg = 0;
        //double angleRad = (Math.PI / 180) * angleDeg;
        //shape.TextXForm.TxtAngle.Value = angleRad;

        // Save Visio diagram in the local storage
        diagram.Save(dataDir + "SetShapeTextPositionAtBottom_out.vsdm", SaveFileFormat.Vsdm);
        // ExEnd:SetShapeTextPositionAtBottom
    }
}

}
SetShapeTextPositionAtBottom_out.zip (203.2 KB)

SetShapeTextPositionAtBottom_out (2).zip (404.1 KB)

@arun.rudrangi
Using Microsoft visio to set the align of the text manually on the connection line has no effect, so we can only control the position of the text on the connection line by modifying the properties of the textform.
Since some of the connecting lines are straight lines and some are polylines, this is a different situation. Please set the properties according to the different scenarios. Please refer to the following code: When the line segment is more complex, you can also use other logic:

            if (shape.NameU.Contains("Dynamic connector"))
            {
                //You can use other logic to manipulate these values
                //Get the line segment where the arrow is
                int lineCount = shape.Geoms[0].CoordinateCol.LineToCol.Count;
                LineTo lt = shape.Geoms[0].CoordinateCol.LineToCol[lineCount - 1];
                shape.TextXForm.TxtPinY.Value = lt.Y.Value + 0.15;
                continue;
            }

Thanks.