Reading/retrieving Shape Info and Properties

I am trying to use the aspose.diagram API for Java and .Net to read my visio (vsdx) file and extract the information of shapes, stencils, connectors, etc. In examples/diagram/shapes when I try to run retrieveShapeInfo class of Java with a file specified in the code, it does not extract all the information. Example, if there are 20 shapes in total in the diagram, it gives the information for only lets say 10, not all. Again when I try to import my own file and run the class, it gives a null pointer exception. (Screenshot shared.) What should be done here?
image.png (467.4 KB)aspose.png (599.8 KB)

@dbuch1707

Would you please make sure to use the API with valid license. You can try using 30-days free temporary license in order to evaluate the API without any limitation. In case you still face any issue, please share your sample Diagram file with us. We will test the scenario in our environment and address it accordingly.

Hi Asad thanks for responding. I am using Java aspose github repository and retriveShapeInfo class in specific. The issue is the code is not able to retrieve the information inside of the group in my diagram. It considers the group as one shape and ignores the shapes inside of the group. Here is my file.(not able to upload my vsdx file and thus uploading pdf format.) AWS_1.pdf (61.8 KB)

@dbuch1707

The file you have shared seems corrupted. We tried to rename its extension as .vsdx but it did not open with MS Visio. Would you please share the original file while adding it to ZIP Archive so that we can proceed further.

Sure, here is it zipped file. aws_1 2.zip (37.4 KB)

@dbuch1707

We tested the scenario in our environment and retrieved following information from your file.

Shape ID : 1
Name : Square.1

Shape ID : 2
Name : Square.2

Shape ID : 3
Name : Square.3

Shape ID : 4
Name : Square.4

Shape ID : 5
Name : Square.5

Shape ID : 6
Name : Square.6

Shape ID : 9
Name : Circle.9

Shape ID : 10
Name : Circle.10

Shape ID : 11
Name : Dynamic connector.11

Shape ID : 12
Name : Dynamic connector.12

Shape ID : 15
Name : Hexagon.15

Shape ID : 16
Name : Hexagon.16

Shape ID : 19
Name : Dynamic connector.19

Shape ID : 20
Name : Dynamic connector.20

Shape ID : 21
Name : Dynamic connector.21

Shape ID : 22
Name : Dynamic connector.22

Shape ID : 24
Name : Dynamic connector.24

Shape ID : 26
Name : Dynamic connector.26

Shape ID : 27
Name : Dynamic connector.27

Shape ID : 29
Name : Dynamic connector.29

Shape ID : 30
Name : Dynamic connector.30

Shape ID : 33
Name : Dynamic connector.33

Shape ID : 36
Name : 

Could you please confirm if you are using valid license before processing the file. In case you have further concerns, please let us know.

This is what I am getting as an output as well. If you observe, you will notice it is not somehow covering all the shapes and their info. (Generally the shapes in a group or has a parent shape group)
Here is the link from where I downloaded the repository.

I see that it has an MIT license associated with it.

@dbuch1707

We have logged an investigation ticket as DIAGRAMJAVA-50687 in our issue tracking system. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hi Asad, I can see that my ticket status has changed to ‘won’t fixed’. Could you please let me know what went wrong in this Aspose JAVA repository? Thanks!

@dbuch1707

The ticket status is so because we found that it was not an issue with the API. Please use following code snippet when shapes are in group:

if(shape.getType()==TypeValue.GROUP) {
for (com.aspose.diagram.Shape child : (Iterable<com.aspose.diagram.Shape>) shape.getShapes()) {
System.out.println("\n Parent Shape ID : " + shape.getID());
System.out.println("Parent Name : " + shape.getName());
System.out.println("\nShape ID : " + child.getID());
System.out.println("Name : " + child.getName());

Hey Asad, I already had this snippet in my code.
My java file can be found here. The output generated is not traversing through all the shapes in the container and is also unable to print all the shape names and ids of the group.
aspose.zip (1.1 KB)

Here is the output generated-

Shape ID : 1
Name : Square.1
Text from shape added: ​Amazon route 53

Shape ID : 2
Name : Square.2
Text from shape added: ​AWS WAF

Shape ID : 3
Name : Square.3
Text from shape added: CloudFRont Distribution​

Shape ID : 4
Name : Square.4
Text from shape added: ​S3

Shape ID : 5
Name : Square.5
Text from shape added: ​AWS cognito user pool

Shape ID : 6
Name : Square.6
Text from shape added: ​AWS quicksight

Shape ID : 9
Name : Circle.9
Text from shape added: ​AWS aurora

Shape ID : 10
Name : Circle.10
Text from shape added: ​Redshift

Shape ID : 15
Name : Hexagon.15
Text from shape added: ​Dynamo db

Shape ID : 16
Name : Hexagon.16
Text from shape added: ​Amazon Athena

Shape ID : 36
Name :
Text from shape added: ​logic tier

Parent Shape ID : 36
Parent Name :

Shape ID : 18
Name : Circle.18
Text from shape added : ​cloudWatch

Parent Shape ID : 36
Parent Name :

Shape ID : 35
Name :

@dbuch1707

We have re-opened the ticket and will re-investigate it. Will inform you as soon as we have some results.

Thanks Asad! Kindly let me know when there is any update.

Hi there, I would like to know if there are any updates regarding the issue I was facing. KIndly let me know if any. Thank you.

@dbuch1707

We used following code snippet with recursive method and were unable to notice any missing information in the console output. For your kind reference, attached is the code snippet with console output. All Shape IDs and Names are there in the output. For the shapes IDs 35 or 36, no name has been defined in the source diagram which is why it is empty in the output:

private void RetrieveShapes() {
        try {
            com.aspose.diagram.Diagram diagram = new com.aspose.diagram.Diagram(dataDir + "AWS_1.vsdx");
            for (com.aspose.diagram.Shape shape : (Iterable<com.aspose.diagram.Shape>) diagram.getPages().getPage(0).getShapes()) {
                // Display information about the shapes
                PrintShape(shape);
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

    static void PrintShape(com.aspose.diagram.Shape shape) {
        if (shape.getType() == com.aspose.diagram.TypeValue.GROUP) {
            System.out.println("Group Shape ID : " + shape.getID());
            System.out.println("Group Shape Name : " + shape.getName());
            for (com.aspose.diagram.Shape child : (Iterable<com.aspose.diagram.Shape>) shape.getShapes()) {
//                System.out.println("\n Parent Shape ID : " + child.getID());
//                System.out.println("Parent Name : " + child.getName());
                PrintShape(child);
            }
        } else {
            System.out.println("Shape ID : " + shape.getID());
            System.out.println("Name : " + shape.getName());
        }
    }

Console Output:

Shape ID : 1
Name : Square.1
Shape ID : 2
Name : Square.2
Shape ID : 3
Name : Square.3
Shape ID : 4
Name : Square.4
Shape ID : 5
Name : Square.5
Shape ID : 6
Name : Square.6
Shape ID : 9
Name : Circle.9
Shape ID : 10
Name : Circle.10
Shape ID : 11
Name : Dynamic connector.11
Shape ID : 12
Name : Dynamic connector.12
Shape ID : 15
Name : Hexagon.15
Shape ID : 16
Name : Hexagon.16
Shape ID : 19
Name : Dynamic connector.19
Shape ID : 20
Name : Dynamic connector.20
Shape ID : 21
Name : Dynamic connector.21
Shape ID : 22
Name : Dynamic connector.22
Shape ID : 24
Name : Dynamic connector.24
Shape ID : 26
Name : Dynamic connector.26
Shape ID : 27
Name : Dynamic connector.27
Shape ID : 29
Name : Dynamic connector.29
Shape ID : 30
Name : Dynamic connector.30
Shape ID : 33
Name : Dynamic connector.33
Group Shape ID : 36
Group Shape Name : 
Shape ID : 18
Name : Circle.18
Group Shape ID : 35
Group Shape Name : 
Shape ID : 7
Name : Circle.7
Shape ID : 8
Name : Circle.8
Shape ID : 13
Name : Hexagon.13
Shape ID : 14
Name : Hexagon.14
Shape ID : 17
Name : Circle.17
Shape ID : 25
Name : Dynamic connector.25
Shape ID : 28
Name : Dynamic connector.28
Shape ID : 31
Name : Dynamic connector.31
Shape ID : 32
Name : Dynamic connector.32
Shape ID : 34
Name : Dynamic connector.34

Thank you so much Asad! It is working fine now!

1 Like

Hi, hope you are doing well. I am using AWS toolkit downloaded from AWS Architecture Icons and using the stencils in my visio diagram. When I am trying to parse the same file in the code, the recursive function works fine in extracting the shapes present in the container but it repeats and prints the shape multiple times. I fail to understand the issue here.aws_stencil.zip (84.0 KB)

Here is the file.

@dbuch1707

We were unable to notice the issue in our environment. Would you please make sure that your recursive function looks like following:

static void PrintShape(com.aspose.diagram.Shape shape) {
        if (shape.getType() == com.aspose.diagram.TypeValue.GROUP) {
            System.out.println("Group Shape ID : " + shape.getID());
            System.out.println("Group Shape Name : " + shape.getName());
            for (com.aspose.diagram.Shape child : (Iterable<com.aspose.diagram.Shape>) shape.getShapes()) {
//                System.out.println("\n Parent Shape ID : " + child.getID());
//                System.out.println("Parent Name : " + child.getName());
                PrintShape(child);
            }
        } else {
            System.out.println("Shape ID : " + shape.getID());
            System.out.println("Name : " + shape.getName());
        }
    }

Also, please share some more details so that issue can be replicated and addressed accordingly. Please share complete environment details along with screenshots of the console output.