xzos / PyZDDE

Zemax/ OpticStudio Extension using Python
MIT License
159 stars 67 forks source link

Issues with saving NSC Detector text file #79

Open shbhuk opened 6 years ago

shbhuk commented 6 years ago

Hi, This is following issue #71 I get the following error on trying to use

self.ln.zGetDetectorViewer(displayData=True,settingsFile=settingsFile,txtFile=txtfile,keepFile=True,timeout=600)

C:\Users\shbhu\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pyzdde\zfileutils.py in readDetectorViewerTextFile(pyz, textFileName, displayData)
    649     >>> info, gridData = zfu.readDetectorViewerTextFile(pyz, textFileName, True)
    650     """
--> 651     line_list = pyz._readLinesFromFile(pyz._openFile(textFileName))
    652     # Meta data
    653     detNumSurfNumPat = r'Detector\s*\d{1,4}\s*,\s*NSCG\sSurface\s*\d{1,4}'
C:\Users\shbhu\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pyzdde\zdde.py in _openFile(fileName)
  12143     global _global_use_unicode_text
  12144     if _global_use_unicode_text:
> 12145         f = open(fileName, u'rb')
  12146     else:
  12147         f = open(fileName, 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/shbhu/Desktop/test.txt' 

I checked the source code, and this function which GetDetectorViewer() calls -

  ret = self.zGetTextFile(textFileName, 'Dvr', cfgFile, getTextFlag,
                                timeout)

This function runs without error and returns 0. However it is not creating the textFile. Thus the zfileutils are giving an error.

This sends the following DDE command -


            cmd = 'GetTextFile,"{tF}",{aT},"{sF}",{fl:d}'.format(tF=textFileName,
                                    aT=analysisType,sF=settingsFile,fl=flag)
            reply = self._sendDDEcommand(cmd, timeout)

This command runs without error and returns 'OK' when I call it - cmd = 'GetTextFile,"{tF}",{aT},"{sF}",{fl:d}'.format(tF=loc+'test.txt', aT='Dvr',sF='',fl=0)

However, there is no file generated in the directory specified by 'loc'

shbhuk commented 6 years ago

ln.zSaveDetector(1,det_zmxobj_no,fileName=txtfile[:-4]+'.ddr') returns 0 but no .DDR file is created.

Seems to be related?

ln.zSaveDetector(1,det_zmxobj_no,fileName='test.ddr') creates a file called Zemaxtest.ddr in 'C:/Users/shbhu/Documents/'

I am using Zemax 17 and Python 3.5

shbhuk commented 6 years ago

Hi @indranilsinharoy , Did you get time to look at this?

indranilsinharoy commented 6 years ago

Hi @shbhuk ,

Unfortunately, since I moved to a new job, I don't have a Zemax license right now. Therefore, I hope someone else with a Zemax key can resolve your issue. I'm very sorry.

Best Regards, Indranil.

shbhuk commented 6 years ago

Hi @indranilsinharoy , Best of luck with your new job.

Shubham

jrphysics commented 3 years ago

@shbhuk This is caused by the number of digits in the exponential for intensity / power values. The code is looking for 3 to 8, while some people have just 2.

@indranilsinharoy The ethernal license problem! I've sent a PR #103.

shbhuk commented 3 years ago

Great, thanks!