29 April 2020 at 03:14
#6133
jgnedy
Member
Thanks Ronald. I found your second method to work the best for me. I wrote a helper function in a separate module, then used the with block in my function that returns a cell. In this way, the expensive hull calculation is contained.
@contextmanager
def temp_attributes(obj, **kwargs):
prev_vals = {k: getattr(obj, k) for k in kwargs}
for k, v in kwargs.items():
setattr(obj, k, v)
try:
yield
finally:
for k, v in prev_vals.items():
setattr(obj, k, v)
---
with temp_attributes(nd.cfg, use_hull=True, hull_based_bbox=True):
with Cell('main') as main:
...