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

Free Support Forum - aspose.com

Locate textbox by Shape title or description

How can I locate a text box by it’s title or description? Locating by shapid can work however it would most efficient to locate by the shape title or description for a textbox in Visio, no? Please advise, thanks in advance.

Ok, after a bit of debugging I got things going, is there any better approach than the method i created below?


public static Shape GetShapeByName(string ShapeName,Page page)
    {
        Shape desiredShape = new Shape();
        foreach (Aspose.Diagram.Shape shape in page.Shapes)
            if (shape.Users?.Count > 0)
            {
                if (shape.Users[0].Value.Val==ShapeName)
                    return shape;
            }
        if (desiredShape.Name != ShapeName)
            Console.Write($"Unable to locate desired shape:{ShapeName}");
        return desiredShape;
    }

Value.Val for User 0= visAltText = Format Shape->Alt Text ->Title
Value.Val for User 1= visAltDiscription = Format Shape->Alt Text ->Description


@jeffrlynch,
Your method code will work if your source Visio drawing has custom user cells with the same shape name. There is no way to retrieve a shape by name. We have logged a feature request under the ticket ID DIAGRAMNET-51350 in our issue tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

After re-examining this the following method is more comprehensive and covers both use cases as documented within the sample code below:
public static Shape GetShapeByName(string ShapeName,Page page)
{
Shape desiredShape = new Shape();
foreach (Shape shape in page.Shapes)
{
//First Check by the Shape Name (set: Visio->Developer Tab->Shape Name)
if (shape.Name?.Length > 0)
if (shape.Name == ShapeName)
return shape;
//Check by Alt Text Title (set: Visio->Select Shape->Format Shape->Size&Properties->Alt Text->Title)
if (shape.Users?.Count > 0)
{
if (shape.Users[0].Value.Val == ShapeName)
return shape;
}
}
if (desiredShape.Name != ShapeName)
Console.Write($“Unable to locate desired shape:{ShapeName}”);
return desiredShape;
}

@jeffrlynch,
The linked ticket ID DIAGRAMNET-51350 will retrieve the shape by name from the collection of shapes. It will not cover user-defined cells because it is an operation where you are matching the shape name with the title of user-defined cell.

@jeffrlynch,
The linked ticket ID DIAGRAMNET-51350 has been resolved. If there is no issue in the quality assurance phase, then this fix will be included in the next version 17.9 of Aspose.Diagram for .NET API. We will let you know once a significant progress has been made in this regard.

@jeffrlynch,
The linked ticket ID DIAGRAMNET-51350 has been fixed. Please download and try the new version 17.9 of Aspose.Diagram for .NET API.