I recently ran into performance issues when using ChangeAttribute on a larger number of elements in a PythonPart.

There is an older discussion about this here:
https://connect.allplan.com/forum/topics/topic/topics/pythonparts/pythonparts-changing-the-attributes-of-a-list-of-elements.html?apug=431fbeed

However, that thread is now closed, so I cannot comment there. For this reason, I created this new post.

I investigated the behavior and found that a major part of the slowdown comes from repeated graphics engine updates triggered during batch modifications.

A simple way to improve performance is to temporarily lock the graphics engine updates while performing multiple attribute changes, and unlock it afterwards. To make this easy and readable, I wrapped this behavior in a small context manager.

Here is a minimal example showing the pattern:
https://github.com/sLercher/allplan-pythonpart-deferred-graphics-update

This significantly reduces execution time when modifying many elements in a loop and can be reused in other performance-critical PythonParts as well.

Happy coding!

https://www.soil-parts.at
https://www.soil-parts.at/kontakt/