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.
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 = i]
# 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:
y2, 5]
Does that make sense?
Take care,
David
Hi
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
Quick update that
Thank you!
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.