Python Code: execution aborted: recursive execution has been detected... (FIXED)

Mike.Thompson
Mike.Thompson Member, Employee Posts: 345
25 Answers 100 Comments 25 Likes First Anniversary
✭✭✭✭
edited July 29 in Structures

What is this message? (new at 24.2 release)

On python code objects that use the callback On Object Changed you can get this error in mechanical.

It is mechanical catching recursion in the code, meaning you are likely using this code to change another object, which is then also triggering this same code, potentially in an infinite loop.

To avoid infinite recursion (calling the method from within the method) you can use the if statement if object_changed==this:

This will allow you to make changes to other objects from within this code safely as they will call the method, but nothing will happen as this if statement will prevent it from executing in the loop.

The error message will appear even when doing a safe, non-infinite recursive call, but you can suppress the message by toggling property Advanced>Allow Recursion = YES on the python code object.

Why Would I Ever Use This?
It is common to implement a custom, user-defined property on the python code object, and use this callback to change something else in the model based on this input. For example changing a loading value that is part of a loads tabular data and not able to be parameterized natively. You can implement a custom property that is a parameter that links to any kind of data.
See this for example:
https://discuss.ansys.com/discussion/2244

Tagged: