/// <summary>
 /// 设置刀具名
 /// </summary>
 /// <param name="tool"></param>
 public void SetToolName(string tool)
 {
     this.toolName = tool;
     if (operModel != null)
     {
         if (template == null)
         {
             template = new ElectrodeCAMTemplateModel();
         }
         NCGroup toolGroup = template.FindTool(tool);
         if (toolGroup == null)
         {
             throw new Exception("无法找到" + tool + "刀具!");
         }
         operModel.MoveOperationToTool(toolGroup);
     }
 }
        private static NCGroupModel GetNcGroupModelOfName(OperationNameModel model, ElectrodeCAMTemplateModel template)
        {
            Part         workPart = Session.GetSession().Parts.Work;
            NCGroupModel group    = new NCGroupModel()
            {
                GeometryGroup = template.FindGeometry("WORKPIECE"),
                MethodGroup   = template.MethodGroup.Find(a => a.Name.ToUpper().Equals("CU")),
                ToolGroup     = template.FindTool(model.ToolName)
            };

            if (group.GeometryGroup == null)
            {
                throw new Exception("无法获取加工模板WORKPIECE!");
            }
            if (group.MethodGroup == null)
            {
                throw new Exception("无法获取加工模板加工方法!");
            }
            if (group.ToolGroup == null)
            {
                throw new Exception("无法获取加工模板刀具!");
            }
            NCGroup temp = template.FindProgram(model.ProgramName);

            if (temp == null)
            {
                NXOpen.CAM.NCGroup nCGroup1 = (NXOpen.CAM.NCGroup)workPart.CAMSetup.CAMGroupCollection.FindObject("AAA");
                NXOpen.CAM.NCGroup nCGroup2 = workPart.CAMSetup.CAMGroupCollection.CreateProgram(nCGroup1, "electrode", "AAA_1", NXOpen.CAM.NCGroupCollection.UseDefaultName.True, model.ProgramName);
                group.ProgramGroup = nCGroup2;
            }
            else
            {
                group.ProgramGroup = temp;
            }
            return(group);
        }