/* Save nc code for all setups (i.e., if part is non-indexed save 1 nc program is on).
         * In this case we save 1 nc program and set that program as nc code program for all setups.
         */
        private static bool SaveOneNCProgForAllSetups(FeatureCAM.FMDocument doc, string fname_no_ext,
                                                      string ext, string output_dirpath,
                                                      List <SetupInfo> setups_info, ref bool is_op_error)
        {
            int nc_files_num,
                doc_files_num,
                macro_files_num;
            object doc_file_names,
                   macro_file_names,
                   nc_file_names;
            string err_msg;

            for (int i = 1; i <= doc.Setups.Count; i++)
            {
                if (doc.Setups.Item(i).Enabled)
                {
                    doc.Setups.Item(i).Activate();
                    break;
                }
            }
            doc.SimToolpath(false);

            LogFile.Write("Run sim and save nc for the document (1 program for entire part)");

            is_op_error = false;
            foreach (FeatureCAM.FMOperation op in doc.Operations)
            {
                if (op.Errors.Trim() != "")
                {
                    is_op_error = true;
                }
            }

            if (is_op_error)
            {
                LogFile.Write("NC code will not be exported, because there are errors in the Operations list. Project file won't be exported as well.");
                return(false);
            }

            doc.SaveNC(fname_no_ext + ext, output_dirpath, false,
                       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);


            if ((int)nc_files_num > 0)
            {
                for (int i = 0; i < setups_info.Count; i++)
                {
                    foreach (string nc_fpath in (Array)nc_file_names)
                    {
                        if (setups_info[i].nc_fpaths == null)
                        {
                            setups_info[i].nc_fpaths = new List <string>();
                        }
                        setups_info[i].nc_fpaths.Add((string)nc_fpath);
                    }
                }
                LogFile.Write(String.Format("{0} file(s) created", nc_files_num));
                return(true);
            }
            else
            {
                is_op_error = true;
                return(false);
            }
        }