Solved

Is there a ZOS-API equivalent to the ZPL OBJC(A$)?

  • 15 June 2023
  • 4 replies
  • 91 views

In particular, I’m using the Python API. I would like to be able to look for objects by name to make the scripts more reusable.

icon

Best answer by David.Nguyen 27 June 2023, 14:23

View original

4 replies

Userlevel 7
Badge +2

Hi Amy,

 

I don’t think this functions readily exists, but its relatively easy to program. Here’s a Python example for you:

# Function similar to ZPL OBJC
def object_comment(NCE, comment, case_sensitive=False):
# Number of objects in the NCE
object_num = NCE.NumberOfObjects

# Is the search case-sensitive?
if not case_sensitive:
# If the search is NOT case-sensitive put
# input comment in all small letters
comment = comment.lower()

# Initialize list of return indexes
ret_idx = []

# Loop over the objects and check the comments
for obj_idx in range(1, object_num+1):
# Retrieve current object comment
obj_comment = NCE.GetObjectAt(obj_idx).Comment

# Is the search case-sensitive?
if not case_sensitive:
# If the search is NOT case-sensitive put
# current object comment in all small letters
obj_comment = obj_comment.lower()

# If the comment matches, store the object index
if comment == obj_comment:
ret_idx.append(obj_idx)

# If list is empty return -1
if not ret_idx:
ret_idx = -1

# Return list of inices
return ret_idx


# Test the function
object_comment(TheSystem.NCE, 'aa')

If I use this snippet in an interactive extension with this NCE:

I get the following output:

[2, 5]

Does that make sense?

@jwbeenakker does it make sense to add this kind of stuff to your ZOSPy? I can put it on GitHub if you think so.

Take care,

 

David

Userlevel 3

Hi @David.Nguyen 

Thanks for reaching out. Looks like a useful contribution to ZOSPy. If you could push it to ZOSPy on GitHub (eg. in zospy.functions.nce), we are happy to incorporate it, similar to polarisation analyses recently contributed by AndiBarg.

 

Best, Jan-Willem

Userlevel 3

Quick update that @David.Nguyen proposal has been included in the newest release of ZOSPy, together with some other user contributions such as polarization_pupil_map.

Thank you!

Reply