Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zSetField not working #95

Open
Allvvaro opened this issue Aug 9, 2019 · 3 comments
Open

zSetField not working #95

Allvvaro opened this issue Aug 9, 2019 · 3 comments
Assignees
Labels

Comments

@Allvvaro
Copy link

Allvvaro commented Aug 9, 2019

Hi there!. I am having problems with zSetField function. Either when using n=0 or n!=0, it returns that number of arguments are not what were expected. I am not sure what I am doing wrong.

For example, using "zSetField(0, 0, 9, 1)" I get TypeError: Expected 5 arguments, got 2.

Similar, if I try "zSetField(3, 0.001, 0.003, 1, 0, 0, 0, 0, 0)" I get "TypeError: Expected 8 arguments, got 2"

What am I missing? Thank you!

@LucVV
Copy link
Contributor

LucVV commented Nov 14, 2019

Hi @Allvvaro,

First of all, sorry for the delayed reply. There was a probleem with the zSetField function for newer Zemax versions, as the return was corrupted. I made a fix, but this is not yet in the package that you install through pip. To use this fix, you could either clone the code from GitHub, or adjust your local package using this fix. Using this fix, the return is as expected again.

Does this help you?

Kind regards,

Luc

@LucVV LucVV self-assigned this Nov 14, 2019
@LucVV LucVV added the bug label Nov 14, 2019
@turygj
Copy link

turygj commented Oct 25, 2021

The Zemax version I used is 181119, and I have the same problems.
I have tried the fix, but I still haven't solved the problem.
The problem is "fieldData = fd._make([float(elem) for elem in rs])". When I use "print(len(rs))", the result is "2". So I think that the problem maybe the length of "rs".
How can I solve this problem? Thank you!

@LucVV
Copy link
Contributor

LucVV commented Oct 25, 2021

Sorry to hear that the fix is not working properly for you. I made that fix because I had a bug on my version, but it seems as if the bug changed for you. I do not have your version, so I cannot really reproduce your issue. However, in the fix linked above, the code that should be executed in your case (as len(rs)==2) is:

if len(rs) == 2:  # The behaviour with the Zemax bug
    fieldData = self.zGetField(n)

Can you debug to see why this is not the case? If you are not using the return obtained with zSetField(), and just want to make a field adjustment, you could try to define a function that does not handle the reply, such as:

def zSetFieldNoReply(self, n, arg1, arg2, arg3=None, vdx=0.0, vdy=0.0,
    fd = _co.namedtuple('fieldData', ['xf', 'yf', 'wgt',
                                      'vdx', 'vdy',
                                      'vcx', 'vcy', 'van'])
    arg3 = 1.0 if arg3 is None else arg3 # default weight
    cmd = ("SetField,{:d},{:1.20g},{:1.20g},{:1.20g},{:1.20g},{:1.20g}"
           ",{:1.20g},{:1.20g},{:1.20g}"
           .format(n, arg1, arg2, arg3, vdx, vdy, vcx, vcy, van))
    
    reply = self._sendDDEcommand(cmd)

However, please check carefully if this works, it could be that the bug is located in the send side of the DDE. In that case, I'm afraid you will have to switch to the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants