@elisenda v.
Its hard to troubleshoot such a complex macro without looking at your file. My educated guess would be to look at line 144 of the macro:
data = 1
Depending on how you’ve setup your Detector Volume, this data (from the NSDD numeric function) could amount to nothing. Can you try with data = 0
instead?
My feeling is that it would be worth implementing this macro with the ZOS-API as it is easier to troubleshoot more complex code in an integrated development environment (IDE).
Hope this helps and take care,
David