Manage Microsoft® Visio File Metadata via Python
View, add, update, remove or extract built-in and custom Visio file properties using server side Python APIs.
Java Visio API supports the management of system-defined (built-in) properties such as title, author name, document statistics etc as well as user-defined (custom) properties in the form of name-value pair. There is Diagram class to load the files, and PageCollection deals with collection of pages as well as Page class for representing single Page. Along with these classes, documentproperties, customprops makes the process simple for metadata management.
Managing Built-in Properties
For managing system-defined properties, API provides documentproperties , and programmers can easily access a built-in property and update its value.
Java Code to Manage Builtin Properties
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AutoFitShapesInVisio.class); | |
// load a Visio diagram | |
Diagram diagram = new Diagram(dataDir + "BFlowcht.vsdx"); | |
//// Display Visio version and document modification time at different stages | |
System.out.println(diagram.getVersion()); | |
System.out.println(diagram.getDocumentProps().getBuildNumberCreated()); | |
System.out.println(diagram.getDocumentProps().getBuildNumberEdited()); | |
System.out.println(diagram.getDocumentProps().getTimeCreated()); | |
System.out.println(diagram.getDocumentProps().getTimeEdited()); | |
System.out.println(diagram.getDocumentProps().getTimePrinted()); | |
System.out.println(diagram.getDocumentProps().getTimeSaved()); | |
System.out.println(diagram.getDocumentProps().getCustomProps().getCount()); |
Managing Custom Defined Properties
For managing user-defined properties, API provides customprops , and developers can easily access already added properties as well as add new properties. In order to add custom properties, Add method adds the property and returns a reference for the new property as an CustomProp object. CustomProp class is used to retrieve the name, value, and type of the document property as Name , customvalue , PropertyType enumeration values.
Java Code to Add Metadata in Visio File
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AutoFitShapesInVisio.class); | |
// Load a Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
//// Get CustomProperties of diagram | |
CustomPropCollection customProperties = diagram.getDocumentProps().getCustomProps(); | |
//Set property of CustomProp | |
CustomProp customProp = new CustomProp(); | |
customProp.setPropType(PropType.STRING); | |
customProp.getCustomValue().setValueString ("Test"); | |
//Add CustomProp to Collection | |
customProperties.add(customProp); |
Java Code to Remove Property in Visio File
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AutoFitShapesInVisio.class); | |
// Load a Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
//// Get CustomProperties of diagram | |
CustomPropCollection customProperties = diagram.getDocumentProps().getCustomProps(); | |
//Remove CustomProp | |
for (int i = 0; i < customProperties.getCount(); i++) | |
{ | |
CustomProp customProp = customProperties.get(i); | |
if (customProp.getName()== "Test") | |
{ | |
customProperties.remove(customProp); | |
} | |
} |