I want to one-time get all visio and image collection- add a unified serial number

hi:
I want to one-time get all visio and image collection, add a unified serial number, how to obtain visio and photo collections at the same time.
GetChildNodes(NodeType.DrawingML) or GetChildNodes(NodeType.Shape) Can only obtain respectively, Could not add a unified serial number.

Hi there,

Thanks for your inquiry. I suggest you please read following documentation links for your kind reference.
https://docs.aspose.com/words/net/aspose-words-document-object-model/
https://docs.aspose.com/words/net/logical-levels-of-nodes-in-a-document/

Images
in Word documents are either represented by Shape nodes or by DrawingML
nodes when loading into Aspose.Words’ DOM. DrawingML represents a DrawingML shape, picture, chart or diagram in a document. Shape represents an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture.

The CompositeNode.GetChildNodes returns a live collection of child nodes that match the specified type. You need to call CompositeNode.GetChildNodes method for DrawingML and Shape node type separately.

Regarding setting serial number, I suggest you please use DrawingML.AlternativeText and Shape.AlternativeText properties.

Please use the following code snippet to get all visio diagrams from MS Word document.

// Open Document
Document doc = new Document(MyDir + "in.doc");
// Get all shapes from the document.
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int i = 1;
foreach (Shape shape in shapes)
{
    // Check if the shape is OLE object
    if (shape.OleFormat != null)
    {
        switch (shape.OleFormat.ProgId)
        {
            case "Visio.Drawing.11":
                // Your code... 
                break;
        }
    }
}

I mean: a document has many visio object and images,I want to get the whole collection, not respectively,fuction GetChildNodes(NodeType.Shape,true) can only get number of visio object,does not contain number of image .for example:a document has 1 visio object and 2 images, GetChildNodes(NodeType.Shape,true) return the total number of visio is 1, GetChildNodes(NodeType.DrawingML) can only return the total number of visio is 2, I want get collection of visio object and images, the collection has three members,than give them the serial number.

for example:number 1 visio,number 2 image,number 3 image…

Attachment is the test file and target file

Hi there,

Thanks for your inquiry.

Images
in Word documents are either represented by Shape nodes or by DrawingML
nodes when loading into Aspose.Words’ DOM.

There is no API which returns the collection of Visio and images together. Could you please share why you want Visio and images in one collection? We will then provide you more information about your query.

You can use Document.GetChildNodes(NodeType.Any) to get the all node types. This will return the collection of all nodes in the document. You can iterate through this collection and get the required nodes from this collection.

You may also traverse all nodes of document and add the Shape and DrawingML nodes into one collection. Please check the following code example.

Document doc = new Document(MyDir + "Test.docx");
ArrayList nodes = new ArrayList();
Node curNode = doc;
while (curNode != null)
{
    Node nextNode = curNode.NextPreOrder(doc);
    if (nextNode == null)
        break;
    if (nextNode.NodeType == NodeType.Shape || nextNode.NodeType == NodeType.DrawingML)
        nodes.Add(nextNode);
    curNode = nextNode;
}