Add comments to Visio diagram in Python

In Microsoft Visio, comments are annotations or notes that can be added to shapes, diagrams, or specific areas within a diagram. These comments provide additional information, explanations, or instructions about the content of the diagram. Comments are a way to communicate context, details, or feedback related to the elements present in the Visio diagram. Visio allows users to attach comments to shapes, connectors, or the background of the diagram. In this article, we will learn how to add comments to Visio diagrams in Python. We will also learn how to edit existing comments in VSD or VSDX files programmatically using Python.

This article covers the following topics:

Python API to Add Comments to Visio Diagram

For adding comments to Visio diagram, we will use Aspose.Diagram for Python. It enables the developers to work with Microsoft Visio files programmatically in Python applications. It allows the creation of new diagrams, modifying existing ones, extracting information from diagrams, converting diagrams to different formats, and more. Aspose.Diagram for Python simplifies the development process when working with Visio files and provides a higher-level API for interacting with these files using Python.

Please download the package or install the API from PyPI using the following pip command in the console:

pip install aspose-diagram-python 

Add Comments to Visio Diagram in Python

We can easily add comments to a Visio diagram by following the steps below:

  1. Load the Visio diagram using the Diagram class.
  2. Get a specific page by index from pages collection.
  3. After that, insert a comment using the add_comment() method.
  4. Finally, save the Visio diagram using the save() method. It takes the output VSDX file path and SaveFileFormat as arguments.

The following code sample shows how to add a page level comment to a Visio diagram in Python.

Add Comments to Visio Diagram in Python

Add Comments to Visio Diagram in Python.

Add Comments to Shape in Visio Diagram using Python

Similarly, we can add comments to a specific shape of Visio diagram by following the steps below:

  1. Load the Visio diagram using the Diagram class.
  2. Get a specific page by index from pages collection.
  3. Get a specific shape by ID from page’s shapes collection.
  4. After that, insert a comment using the add_comment() method. Pass shape object and a comment as arguments.
  5. Finally, save the Visio diagram using the save() method. It takes the output VSDX file path and SaveFileFormat as arguments.

The following code sample shows how to add a comment to a shape in Visio diagram using Python.

Add Comments to Shape in Visio Diagram using Python

Add Comments to a Shape in Visio Diagram using Python.

Edit Comments in Visio Diagram using Python

We can also edit any comment in a Visio diagram by following the steps below:

  1. Load the Visio diagram using the Diagram class.
  2. Get a specific page by index from pages collection.
  3. Iterate through collection of the annotations.
  4. After that, read the comment.value property and update.
  5. Finally, save the Visio diagram using the save() method. It takes the output VSDX file path and SaveFileFormat as arguments.

The following code sample shows how to edit a comment in a Visio diagram using Python.

Edit Comments in Visio Diagram using Python

Edit Comments in Visio Diagram using Python.

Get a Free API License

Get a free temporary license and experience the library’s capabilities at no cost. Utilizing a free temporary license enables you to explore the features of the library without encountering any restrictions.

Add Comments to Visio Diagram – Learning Resources

Explore other features of the library and learn how to generate, convert, and manipulate Visio diagrams without using Microsoft Visio using the following resources:

Conclusion

In this blog post, we learned how to add comments to Visio diagrams in Python. By leveraging Aspose.Diagram for Python, developers can automate the process of annotating Visio diagram programmatically using Python. In case of any ambiguity, please contact us on our free support forum.

See Also