Skip to main content
Solved

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


Amy Entin

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.

Best answer by David.Nguyen

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

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

4 replies

David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1089 replies
  • Answer
  • June 27, 2023

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


jwbeenakker

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


jwbeenakker

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.


Amy Entin
  • Author
  • Infrared
  • 7 replies
  • August 10, 2023

Thank you!


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