Skip to main content
Solved

How to read out X half width and Y half width of a detector Rectangle using python.

  • December 9, 2024
  • 3 replies
  • 94 views

Erkang Wang

I need to read out the X half width and Y half width of a Detector Rectangle. The above code used to work but now it says no AttributeError: 'IObject' object has no attribute 'XHalfWidth'. Could you tell me a way to circumvent this problem. 

Best answer by David.Nguyen

@Erkang Wang 

 

When using the ZOS-API with Python. If something was working before and got broken, I always suspect this:

In your case, I think if you do:

x_half_width = d.ObjectData.__implementation__.XHalfWidth

It should fix your issue. I think it got broken when you installed a more recent version of Pythonnet (>2.5.2). You could also roll back Pythonnet to 2.5.2, but I think its less desirable. Also, I highly suggest looking at ZOSPy (mentioned at the end of the post I linked above), which alleviate such issues.

Take care,


David

View original
Did this topic help you find an answer to your question?

3 replies

David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1072 replies
  • Answer
  • December 10, 2024

@Erkang Wang 

 

When using the ZOS-API with Python. If something was working before and got broken, I always suspect this:

In your case, I think if you do:

x_half_width = d.ObjectData.__implementation__.XHalfWidth

It should fix your issue. I think it got broken when you installed a more recent version of Pythonnet (>2.5.2). You could also roll back Pythonnet to 2.5.2, but I think its less desirable. Also, I highly suggest looking at ZOSPy (mentioned at the end of the post I linked above), which alleviate such issues.

Take care,


David


Erkang Wang
  • Author
  • Infrared
  • 6 replies
  • December 11, 2024

Thanks, David, All works now. just one more thing to added, I noticed that access XHalfWidth and ZPosition need different syntax. It used to be identical. 

 

 

David.Nguyen wrote:

@Erkang Wang 

 

When using the ZOS-API with Python. If something was working before and got broken, I always suspect this:

In your case, I think if you do:

x_half_width = d.ObjectData.__implementation__.XHalfWidth

It should fix your issue. I think it got broken when you installed a more recent version of Pythonnet (>2.5.2). You could also roll back Pythonnet to 2.5.2, but I think its less desirable. Also, I highly suggest looking at ZOSPy (mentioned at the end of the post I linked above), which alleviate such issues.

Take care,


David

 


David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1072 replies
  • December 11, 2024

@Erkang Wang 

 

Good to hear. As far as I can remember, ZPosition has always been a property of the INCERow interface (instance of d in your code above). Are you saying that you were able to do the following before?

x_half_width = d.XhalfWidth

I don’t remember this being possible, but I could be wrong. You could also get the X Half-Width column by using the GetCellAt(int pos) method of INCERow, which lets you retrieve any cell of the NCE. Fox X Half-Width it would look like so:

d.GetCellAt(11).DoubleValue

It’s a little bit trial and error to figure out int pos, which is why there is ObjectData. But perhaps you find this method to be more direct.

In any case, don’t forget you can also read the Release Notes here:

https://community.zemax.com/opticstudio-release-notes-71

To check whether significant changes are being introduced in OpticStudio (including the ZOS-API).

Take care,


David


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings