private static void SaveNCForSetup(FMDocument doc, FMSetup setup,
                                           string fname_no_ext, string ext, string output_dirpath,
                                           out int nc_files_num, out object nc_file_names,
                                           out string err_msg, ref bool is_op_error)
        {
            int    doc_files_num, macro_files_num;
            object doc_file_names, macro_file_names;


            nc_files_num  = 0;
            err_msg       = "";
            nc_file_names = null;

            LogFile.Write(String.Format("Run sim and save nc for setup {0}", setup.Name));
            setup.Activate();
            doc.SimToolpath(false);

            is_op_error = false;
            foreach (FeatureCAM.FMFeature feat in setup.Features)
            {
                for (int i = 1; i <= feat.Operations.Count; i++)
                {
                    if (feat.Operations.Item(i).Errors.Trim() != "")
                    {
                        is_op_error = true;
                    }
                }
            }

            if (is_op_error)
            {
                LogFile.Write("There are errors in the setup's operations list. NC code will not be exported. Project file won't be exported as well.");
                return;
            }

            doc.SaveNC(fname_no_ext + ext, output_dirpath, true,
                       FeatureCAM.tagFMSaveNCFileType.eNCFT_NCCode, false, out err_msg,
                       out nc_files_num, out nc_file_names, out doc_files_num, out doc_file_names,
                       out macro_files_num, out macro_file_names);
            LogFile.Write(String.Format("{0} file(s) created", nc_files_num));
        }