Jump to content
Private Messaging is activated - check "How to" on how to disable it ×

Export data from GOM to XML


---
 Share

Recommended Posts

Hello everyone !

I am currently stuck with an issue: I need to export dimensional data, such as the average, max, min etc... as an XML. I want to do it through a script. The real issue is that I need to have that file written in a particular way so that it can be understood by a third party software. It does not seem possible by using the script recorder in GOM.

Any idea ?

It has to look something like the attached file.Sanstitre.png.28d968e958a1bd91f7613308f3b2aafa.png

Thank you.

Link to comment
Share on other sites

Hi,

You create an XML file like this with the following Python script:

import xml.etree.ElementTree as ET
from xml.dom import minidom

# Step 1: Create the root element
root = ET.Element("ListOfMeas")

# Step 2: Create child elements
meas = ET.SubElement(root, "Meas")
charac = ET.SubElement(meas, "Charac")
charac.text = "THE CHARACTERISTIC I WANT TO EXPORT"
val = ET.SubElement(meas, "Val")
val.text = "777"

# Step 3: Create an ElementTree object
tree = ET.ElementTree(root)

# Step 4: Convert to string and pretty-print
xml_str = ET.tostring(root, encoding='utf-8', method='xml')
parsed_xml = minidom.parseString(xml_str)
pretty_xml_str = parsed_xml.toprettyxml(indent="    ")

# Step 4: Write to an XML file
with open("my_data.xml", "w", encoding='utf-8') as fh:
    fh.write(pretty_xml_str)

You find the required elements using Selecting elements in scripts — App Development Documentation and then selecting the desired element properties (ZEISS INSPECT Python API Introduction — App Development Documentation - Access element properties).

Instead of using a fixed filename as in the example above, you use Selecting a file or folder — App Development Documentation (ZEISS INSPECT 2025) or you create a dialog.

Hope this helps!

Best regards

Matthias

Edited
Link to comment
Share on other sites

 Share

×
×
  • Create New...