NXOpen.UF.UFSession theUfSession = NXOpen.UF.UFSession.GetUFSession(); try { //初始化 NXOpen.UF.UFClone.OperationClass operationClass = NXOpen.UF.UFClone.OperationClass.CloneOperation; theUfSession.Clone.Initialise(operationClass); //添加原裝配到克隆裝配中,有Add Assembly和Add Part兩種方法,此處用Add Assembly NXOpen.UF.UFPart.LoadStatus loadStatus; theUfSession.Clone.AddAssembly(selectPath,out loadStatus); //theUfSession.Clone.AddPart(selectPath); //指定默認的克隆方式 NXOpen.UF.UFClone.Action action = NXOpen.UF.UFClone.Action.Clone; theUfSession.Clone.SetDefAction(action); //指定默認文件名的方法 NXOpen.UF.UFClone.NamingTechnique namingTechnique = NXOpen.UF.UFClone.NamingTechnique.NamingRule; theUfSession.Clone.SetDefNaming(namingTechnique); //定義新裝配的克隆命名規則 NXOpen.UF.UFClone.NameRuleDef nameRuleDef; nameRuleDef.type = UFClone.NameRuleType.PrependString; nameRuleDef.new_string = "M8"; nameRuleDef.base_string = ""; //在NX7.5版本之前,無需下面這句,可是NX7.5之後的版本中調用,必須添加下面這句,不然會顯示克隆出錯。 NXOpen.UF.UFClone.NamingFailures namingFailures; theUfSession.Clone.InitNamingFailures(out namingFailures); theUfSession.Clone.SetNameRule(ref nameRuleDef, ref namingFailures); theUfSession.Clone.SetDefDirectory(@"C:\temp\"); //string outputName = "C:\\xxxxx.prt"; //theUfSession.Clone.SetNaming(selectPath, UFClone.NamingTechnique.DefaultNaming, outputName); //theUI.NXMessageBox.Show("", NXMessageBox.DialogType.Information, namingFailures.n_failures.ToString()); theUfSession.Clone.PerformClone(ref namingFailures); //theUfSession.Clone.Terminate(); } catch (Exception ex1) { theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex1.ToString()); } finally { theUfSession.Clone.Terminate(); }