MarcelP102 Posted September 11, 2025 Share Posted September 11, 2025 (edited) When using vs.GetRect I need to use a callback when using this function in Python. Unfortuantly I'm unable to display the points of both corners of the box in the main code. I am able to display it within the callback code but I'm unable to pass the value to the main code. Here is is a simplified part of the code. Can anybody help me out. Thanks! import vs def _extract_xy(arg): if isinstance(arg, (tuple, list)): return float(arg[0]), float(arg[1]) else: return def on_rect_callback(*args): if len(args) == 2: # two points x1, y1 = _extract_xy(args[0]) x2, y2 = _extract_xy(args[1]) else: vs.AlrtDialog(f"Unexpected GetRect callback signature: {len(args)} arg(s).") return vs.AlrtDialog( f"P1 here is working: ({x1:.3f}, {y1:.3f})\n" f"P2 here is working: ({x2:.3f}, {y2:.3f})\n" ) def run(): # Ask the user to drag a marquee; callback receives the points. x1, y1, x2, y2 = vs.GetRect(on_rect_callback) # Here is the TypeError: cannot unpack non-iterable NoneType object vs.AlrtDialog( f"P1 in main code: ({x1:.3f}, {y1:.3f})\n" f"P2 in main code: ({x2:.3f}, {y2:.3f})\n" ) run() Edited September 11, 2025 by MarcelP102 Quote Link to comment
Yordan Kostadinov Posted September 13, 2025 Share Posted September 13, 2025 Unfortunately it works only for VectorScript (pascal), but not for Python. In Pascal Vectorscript the execution of the script is paused, the user interaction is performed, and then the script continues with returning the result of GetRect. In Python, the main script is completed, vs.GetRect returns always None and the rest of the code is executed, that's why you get the error. Then the user interaction is completed, leaving you only with the possibility to continue your logic only from within the callback function. You can see the result of this: vs.AlrtDialog( str(vs.GetRect(on_rect_callback) )) Same issue with vs.GetLine or vs.TrackObject. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.