xzos / PyZDDE

Zemax/ OpticStudio Extension using Python
MIT License
154 stars 64 forks source link

zSetNSCProperty(1, 1, 0, 86, "1,2,1") to set the wavelength shift string doesn't work #97

Closed echatziz closed 4 years ago

echatziz commented 4 years ago

I have set up a rectangular volume as a bulk scatterer. All the properties, parameters, position work fine. I just can't pass the wavelength shift string.

Is this working for other people? Could you check if it works? I don't get any error messages, the command is just ignored

echatziz commented 4 years ago

Is there anybody supporting this library or opening issues is a waste of time?

ulip commented 4 years ago

The PyZDDE library was mainly created by @indranilsinharoy.

Maybe you try to contact him? I don't know if he still wants to maintain this library since Zemax/OpticStudio deprecated DDE and switched to a COM API.

indranilsinharoy commented 4 years ago

Hi @ulip Thanks for providing the comments. This is not the first time you have done this 👍 Hi @echatziz I would very much love to actively maintain this library. Unfortunately, after leaving school, I do not have access to a Zemax license. Therefore, I really have no way way of fixing bugs and verifying. That's one of the reason, based on @LucVV 's suggestion, I moved PyZDDE into the organization xzos so that other people interested in maintaining this look could do it.

Regarding the above function zSetNSCProperty(), I don't exactly remember, do you need to be in the NSC mode? Do you have any error messages? What is the return value from the function? If successful, the function is expected to return the same same data as returned by zGetNSCProperty() . If the command fails, it returns -1.

Hi @LucVV , if you have some time, can you please take a look at this. Thank you very much.

LucVV commented 4 years ago

Hi @echatziz, @ulip and @indranilsinharoy, sorry for the late reply. I have little experience with the zSetNSCProperty() function, but I tried is just now and I got it to work by changing "1,2,1" to '"1,2,1"'. It looks as if the command that is parsed needs the brackets within the string.

These are the steps that I used:

  1. Open a new file in the NSC editor.
  2. Define the first object as rectangular volume
  3. Set the volume physics model to angle scattering
  4. Set the wavelength to preset F,d,C (visible)
  5. Run the following code from python:
import pyzdde.zdde as pyz
ln = pyz.createLink(True)
ln.zSetNSCProperty(1, 1, 0, 86, '"1,2,1"')
wlshift = ln.zGetNSCProperty(1, 1, 0, 86)
print(wlshift)

Does this work for you?

I will think about a way to circumvent this error. Is it only this functionality that does not work, of do you have other problems as well?

Luc

echatziz commented 4 years ago

Yes, adding single quotes around double quotes worked.

Thank you. I don't have some other issue for now.

By the way, is there a way to access the "Phosphors and Fluorescence" tab of the newer versions of Zemax, with PyZDDE? Not even Zemax ZPL supports that, the Zemax people told me to use the ZOS-API if I want to access that tab programmatically.

LucVV commented 4 years ago

Glad to hear that it worked! For your other question, I do not have the premium edition, so I cannot access it at all.. I give you little chance if the ZPL does not support it, but you could check the logical next increment. Else, you could check PyZOS to use the API if you really need it.

indranilsinharoy commented 4 years ago

@LucVV Thanks very much for your help :-)

@echatziz , @LucVV I'm not sure why we need to use the single quotes around the double quotes '"1,2,1"'. It could be a Zemax thing! Would you input the wavelength shift as "1,2,1" in Zemax if you used Zemax directly? Something to check!

Regarding the other question. If "Phosphors and Fluorescence" is a recent feature, most likely PyZDDE cannot be used for that since Zemax stopped updating there DDE based interface following the release of ZOS-API.

LucVV commented 4 years ago

My best guess is that it goes wrong in the interpretation of the string that Zemax recieves. Without the quotation marks, this string is 'SETNSCPROPERTY, 1, 1, 0, 86, 1,2,1', in which it might assume that the 1,2,1 are three separate passed arguments. In the ZPL, you would use SETNSCPROPERTY, 1, 1, 0, 86, "1,2,1", so by adding an additional set of quotation marks, we match the ZPL.

As for the recent feature, I estimate (but cannot check) that it is not possible. However, it is an additional option on an already existing feature, which has 3 in stead of 2 options, which is why I gave it a slight chance to actually work. @echatziz could you inform us if it does?

indranilsinharoy commented 4 years ago

@LucVV Thanks for the explanation. It makes sense. Does that mean we need to account for this (i.e., when the data is expected to be string) in the zSetNSCProperty() function?

echatziz commented 4 years ago

No, just incrementing the zSetNSCProperty(1, 1, 0, 81, 2) by one didn't work for accessing the Phosphors and Fluorescence tab, but thank you for the suggestion.

The feature by the way is not that new, it's been there for some years

LucVV commented 4 years ago

@indranilsinharoy I think it is just this specific case, were there is a string with commas in it that might be evaluated as additional arguments. When I was checking this function, I also used it to set the comment on a filed and that worked fine. (In hindsight, it might be good to check what happens if I want a comma within that comment). I will try to check how it works with the comment somewhere this week. If this also gives the error, then I guess we have two options:

  1. Add information to the docstring on strings with commas
  2. Make the double quotations the standard behaviour ( not sure if this has an effect on the functionality)

I will try to do the evaluation this week