ansys / optical-automation

Optical Automation Framework
https://ansys-internal.github.io/optical-automation/
MIT License
29 stars 11 forks source link

COMError when trying to export a template #124

Closed adamkoval closed 1 year ago

adamkoval commented 1 year ago

Hi, this is my first attempt at using your API to automate some analysis of SPEOS results.

I used your template code at: https://github.com/ansys/optical-automation/blob/main/ansys_optical_automation/application/export_measures.py

Upon selecting the location of the xmp file I want to work with, the script fails (line 34).

Please help me understand what I'm doing incorrectly to help me get started with what looks like a very useful API!

Thank you in advance!

Below is the error traceback:

In [9]: %run template.py
---------------------------------------------------------------------------
COMError                                  Traceback (most recent call last)
File ~\Documents\CREO_work\scripts\automation\template.py:40
     36     path_export = getfilename("*.txt", True)
     37     xmp.export_template_measures(path_xml, path_export)
---> 40 main()

File ~\Documents\CREO_work\scripts\automation\template.py:34, in main()
     32 xmp = DpfXmpViewer()
     33 path_xmp = getfilename("*.xmp")
---> 34 xmp.open_file(path_xmp)
     35 path_xml = getfilename("*.xml")
     36 path_export = getfilename("*.txt", True)

File ~\AppData\Roaming\SpaceClaim\Published Scripts\ansys_optical_automation\post_process\dpf_xmp_viewer.py:361, in DpfXmpViewer.open_file(self, str_path)
    359     self.source_list = []
    360     if self.dpf_instance.MapType == 2 or self.dpf_instance.MapType == 3:
--> 361         self.__get_source_list()
    362 else:
    363     raise ImportError("Opening the file failed.")

File ~\AppData\Roaming\SpaceClaim\Published Scripts\ansys_optical_automation\post_process\dpf_xmp_viewer.py:575, in DpfXmpViewer.__get_source_list(self)
    573 for layer in range(total_sources):
    574     name = automation.VARIANT()
--> 575     self.dpf_instance.ExtendedGetSourceName(layer, pointer(name))
    576     self.source_list.append(name.value[0])
    577 return self.source_list

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\comtypes\client\dynamic.py:111, in _Dispatch.__getattr__(self, name)
    109 dispid = self._ids.get(name)
    110 if not dispid:
--> 111     dispid = self._comobj.GetIDsOfNames(name)[0]
    112     self._ids[name] = dispid
    114 if name in self._methods:

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\comtypes\automation.py:725, in IDispatch.GetIDsOfNames(self, *names, **kw)
    723 arr = (c_wchar_p * len(names))(*names)
    724 ids = (DISPID * len(names))()
--> 725 self.__com_GetIDsOfNames(riid_null, arr, len(names), lcid, ids)
    726 return ids[:]

COMError: (-2147352570, 'Unknown name.', (None, None, None, 0, None))
adamkoval commented 1 year ago

Update: for now, I have worked around the issue by commenting the call to the troubled method, __get_source_list() in the DpfXmpViewer class (commented lines 360 & 361 in dpf_xmp_viewer.py). I don't need a source list for my current application, but I would certainly like to have this option in the future. Any help is appreciated.

StefanThoene commented 1 year ago

@adamkoval can you please check if you're file is seperated by layer so does the source list exist? if not could you please share the XMP file with official Ansys Support optiseuropesupport@ansys.com then we can adjust the code so if gives an appropriate error

adamkoval commented 1 year ago

@StefanThoene Thanks for your reply.

So the sensors all have "Data separated by source" checked, and indeed in the extended.txt file I see all the layers.

I cannot share my XMP file at the moment because the simulated data is bound by NDA. But I will try to find some time and run a generic simulation, and I will share the results of that.

P.S., A question regarding the extended.txt format - is the data given in RGBA format or something else? I am not sure how to process it as it seems there are channels for each source, and each channel contains 4 values per pixel. I tried to check the code by I cannot access the methods of XMPViewer.Application COM object, so it is a black box at the moment. I am new to image processing, so some guidance would greatly help me! I can open a new topic if needed.

StefanThoene commented 1 year ago

@adamkoval here you can find the exact format explanation https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v222/en/Optis_UG_LAB/Optis/UG_Lab/extended_map_format_31781.html if you need more guidance please reach out to us with an official support request and we can help you understand it in a direct call you can also check out the following parts of the git repo where we create a datastruct of the XMP to allow pixel by pixel access to the data: https://github.com/ansys/optical-automation/blob/a3195edecb4b8915d0f5c8c704ce57ae1b2a336f/ansys_optical_automation/post_process/dpf_xmp_viewer.py#L492

adamkoval commented 1 year ago

@StefanThoene thanks for your guidance. I'll need to make an account to see that but I'm sure it will be a helpful resource.