ShapeAccept Method
Accepts a visitor.

Namespace: Aspose.Words.Drawing
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.12
Syntax
public override bool Accept(
	DocumentVisitor visitor
)

Parameters

visitor
Type: Aspose.WordsDocumentVisitor
The visitor that will visit the nodes.

Return Value

Type: Boolean
True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes.
Remarks

Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.

For more info see the Visitor design pattern.

Remarks
Calls VisitShapeStart(Shape), then calls Accept(DocumentVisitor) for all child nodes of the shape and calls VisitShapeEnd(Shape) at the end.
Examples
Shows how to iterate over all the shapes in a document.
public void VisitShapes()
{
    // Open a document that contains shapes
    Document doc = new Document(MyDir + "Shape.Revisions.docx");

    // Create a ShapeVisitor and get the document to accept it
    ShapeVisitor shapeVisitor = new ShapeVisitor();
    doc.Accept(shapeVisitor);

    // Print all the information that the visitor has collected
    Console.WriteLine(shapeVisitor.GetText());
}

/// <summary>
/// DocumentVisitor implementation that collects information about visited shapes into a StringBuilder, to be printed to the console
/// </summary>
private class ShapeVisitor : DocumentVisitor
{
    public ShapeVisitor()
    {
        mShapesVisited = 0;
        mTextIndentLevel = 0;
        mStringBuilder = new StringBuilder();
    }

    /// <summary>
    /// Appends a line to the StringBuilder with one prepended tab character for each indent level 
    /// </summary>
    private void AppendLine(string text)
    {
        for (int i = 0; i < mTextIndentLevel; i++)
        {
            mStringBuilder.Append('\t');
        }

        mStringBuilder.AppendLine(text);
    }

    /// <summary>
    /// Return all the text that the StringBuilder has accumulated
    /// </summary>
    public string GetText()
    {
        return $"Shapes visited: {mShapesVisited}\n{mStringBuilder}";
    }

    /// <summary>
    /// Called when the start of a Shape node is visited
    /// </summary>
    public override VisitorAction VisitShapeStart(Shape shape)
    {
        AppendLine($"Shape found: {shape.ShapeType}");

        mTextIndentLevel++;

        if (shape.HasChart)
            AppendLine($"Has chart: {shape.Chart.Title.Text}");

        AppendLine($"Extrusion enabled: {shape.ExtrusionEnabled}");
        AppendLine($"Shadow enabled: {shape.ShadowEnabled}");
        AppendLine($"StoryType: {shape.StoryType}");

        if (shape.Stroked)
        {
            Assert.AreEqual(shape.Stroke.Color, shape.StrokeColor);
            AppendLine($"Stroke colors: {shape.Stroke.Color}, {shape.Stroke.Color2}");
            AppendLine($"Stroke weight: {shape.StrokeWeight}");

        }

        if (shape.Filled)
            AppendLine($"Filled: {shape.FillColor}");

        if (shape.OleFormat != null)
            AppendLine($"Ole found of type: {shape.OleFormat.ProgId}");

        if (shape.SignatureLine != null)
            AppendLine($"Found signature line for: {shape.SignatureLine.Signer}, {shape.SignatureLine.SignerTitle}");

        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when the end of a Shape node is visited
    /// </summary>
    public override VisitorAction VisitShapeEnd(Shape shape)
    {
        mTextIndentLevel--;
        mShapesVisited++;
        AppendLine($"End of {shape.ShapeType}");

        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when the start of a GroupShape node is visited
    /// </summary>
    public override VisitorAction VisitGroupShapeStart(GroupShape groupShape)
    {
        AppendLine($"Shape group found: {groupShape.ShapeType}");
        mTextIndentLevel++;

        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when the end of a GroupShape node is visited
    /// </summary>
    public override VisitorAction VisitGroupShapeEnd(GroupShape groupShape)
    {
        mTextIndentLevel--;
        AppendLine($"End of {groupShape.ShapeType}");

        return VisitorAction.Continue;
    }

    private int mShapesVisited;
    private int mTextIndentLevel;
    private readonly StringBuilder mStringBuilder;
}
See Also