Guilin Sun
Ansys Employee

Did you use broadband source or single wavelength like the example online?
what is the value for "target_grating_order_out"? by default it is 0th order.

You can use question mark to get the values of the variables:

? target_grating_order_out;

? n_array;

and check why it shows the error.