public static double getMateValue(Component2 component) { Feature mate = swAssembly.FeatureByName(component.Name2 + "-distance"); if (mate == null) { return(-1); } IDisplayDimension dispDim = (IDisplayDimension)mate.GetFirstDisplayDimension(); IDimension dim = dispDim.IGetDimension(); double[] someRet = dim.GetSystemValue3((int)swSetValueInConfiguration_e.swSetValue_InSpecificConfigurations, new string[] { component.ReferencedConfiguration }); return(someRet[0]); }
/// <summary> /// Gets the <see cref="ModelFeature"/> of the item in the feature tree based on its name /// </summary> /// <param name="featureName">Name of the feature</param> /// <returns>The <see cref="ModelFeature"/> for the named feature</returns> public void GetFeatureByName(string featureName, Action <ModelFeature> action) { // Wrap any error SolidDnaErrors.Wrap(() => { // Create feature using (var model = new ModelFeature((Feature)mBaseObject.FeatureByName(featureName))) { // Run action action(model); } }, SolidDnaErrorTypeCode.SolidWorksModel, SolidDnaErrorCode.SolidWorksModelAssemblyGetFeatureByNameError, Localization.GetString(nameof(SolidDnaErrorCode.SolidWorksModelAssemblyGetFeatureByNameError))); }
public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath) { //创建项目模型存放地址 string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName; if (!Directory.Exists(itemPath)) { Directory.CreateDirectory(itemPath); } else { DialogResult result = MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } //Pack的后缀 string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6); //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack //packango后需要接收打包完成的地址,参数为后缀 string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm"; if (!File.Exists(packedAssyPath)) { packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath); } //查询参数 UCJDB800 item = (UCJDB800)objUCJDB800Service.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令 int warnings = 0; int errors = 0; suffix = "_" + suffix;//后缀 ModelDoc2 swModel = default(ModelDoc2); ModelDoc2 swPart = default(ModelDoc2); AssemblyDoc swAssy = default(AssemblyDoc); Component2 swComp; Feature swFeat = default(Feature); object configNames = null; ModelDocExtension swModelDocExt = default(ModelDocExtension); bool status = false; string compReName = string.Empty; //打开Pack后的模型 swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; swAssy = swModel as AssemblyDoc; //装配体 string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称 swModelDocExt = (ModelDocExtension)swModel.Extension; //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错 swModel.ForceRebuild3(true); //TopOnly参数设置成true,只重建顶层,不重建零件内部 /*注意SolidWorks单位是m,计算是应当/1000m * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了 * (int)不进行四舍五入,Convert.ToInt32会四舍五入 */ //-----------计算中间值,---------- int fcNo = (int)((item.Length - item.FCSideLeft - item.FCSideRight) / 499m) - item.FCBlindNo; try { //----------Top Level---------- //判断FC数量,FC侧板长度 if (item.FCBlindNo > 0) { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-5")); swComp.SetSuppression2(2); //2解压缩,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern4"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern4").SystemValue = item.FCBlindNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D1@Distance29").SystemValue = item.FCSideLeft / 1000m; } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-5")); swComp.SetSuppression2(0); //2解压缩,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "UCJ FC COMBI-12")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "UCJ FC COMBI-15")); swComp.SetSuppression2(2); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern3"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern3").SystemValue = fcNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D1@Distance35").SystemValue = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m; //----------HCL---------- if (item.LightType == "HCL") { //灯腔 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0054-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Linear austragen1").SystemValue = item.Length / 1000m; swFeat = swComp.FeatureByName("LIGHT T8"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("FC SUPPORT"); swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("FC SUPPORT B"); swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("JAP LED M8"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 if (item.LightCable == "LEFT") { swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else if (item.LightCable == "RIGHT") { swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0066-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0066-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0069-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 5m) / 1000m; swPart.Parameter("D1@LPattern1").SystemValue = fcNo + item.FCBlindNo; swPart.Parameter("D3@Sketch6").SystemValue = (item.FCSideLeft + 250m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0071-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 5m) / 1000m; swPart.Parameter("D1@LPattern1").SystemValue = fcNo + item.FCBlindNo; swPart.Parameter("D3@Sketch6").SystemValue = (item.FCSideLeft + 250m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0116-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0114-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0114-4")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0145-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0161-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. } else { //灯腔 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0054-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0066-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0066-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0069-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0071-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0116-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Linear austragen1").SystemValue = item.Length / 1000m; swFeat = swComp.FeatureByName("LIGHT T8"); if (item.LightType == "T8") { swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("FC SUPPORT"); swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("FC SUPPORT B"); swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("JAP LED M8"); if (item.Japan == "YES") { swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } if (item.LightCable == "LEFT") { swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else if (item.LightCable == "RIGHT") { swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0114-3")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0114-4")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0145-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 5m) / 1000m; swPart.Parameter("D1@LPattern1").SystemValue = fcNo + item.FCBlindNo; swPart.Parameter("D3@Sketch6").SystemValue = (item.FCSideLeft + 250m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0161-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 5m) / 1000m; swPart.Parameter("D1@LPattern1").SystemValue = fcNo + item.FCBlindNo; swPart.Parameter("D3@Sketch6").SystemValue = (item.FCSideLeft + 250m) / 1000m; } //----------UV灯---------- if (item.UVType == "LONG") { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "CEILING UVRACK SPECIAL 4S-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "CEILING UVRACK SPECIAL 4L-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "CEILING UVRACK SPECIAL 4S-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "CEILING UVRACK SPECIAL 4L-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. } //----------油网侧板---------- switch (item.FCSide) { case "LEFT": //重命名装配体内部 compReName = "FNCE0108[BP-" + tree.Module + ".1]{" + (int)(item.FCSideLeft - fcNo * 1m - 4m) + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-2"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - fcNo * 1m - 4m) / 1000m; } //重命名装配体内部 compReName = "FNCE0136[BP-" + tree.Module + ".2]{" + (int)(item.FCSideLeft - fcNo * 1m - 4m) + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0136[BP-]{}-3") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-3" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-3"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - fcNo * 1m - 4m) / 1000m; } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0162[BP-]{}-4")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; case "RIGHT": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0136[BP-]{}-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. //重命名装配体内部 compReName = "FNCE0109[BP-" + tree.Module + ".1]{" + (int)(item.FCSideRight - fcNo * 1m - 4m) + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-3") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-3" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-3"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - fcNo * 1m - 4m) / 1000m; } //重命名装配体内部 compReName = "FNCE0162[BP-" + tree.Module + ".2]{" + (int)(item.FCSideRight - fcNo * 1m - 4m) + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0162[BP-]{}-4") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-4" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-4"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - fcNo * 1m - 4m) / 1000m; } break; case "BOTH": //重命名装配体内部 compReName = "FNCE0108[BP-" + tree.Module + ".1]{" + (int)(item.FCSideLeft - fcNo * 1m - 2m) + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-2"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - fcNo * 1m - 2m) / 1000m; } //重命名装配体内部 compReName = "FNCE0136[BP-" + tree.Module + ".2]{" + (int)(item.FCSideLeft - fcNo * 1m - 2m) + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0136[BP-]{}-3") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-3" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-3"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - fcNo * 1m - 2m) / 1000m; } //重命名装配体内部 compReName = "FNCE0109[BP-" + tree.Module + ".3]{" + (int)(item.FCSideRight - fcNo * 1m - 2m) + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-3") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-3" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-3"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - fcNo * 1m - 2m) / 1000m; } //重命名装配体内部 compReName = "FNCE0162[BP-" + tree.Module + ".4]{" + (int)(item.FCSideRight - fcNo * 1m - 2m) + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0162[BP-]{}-4") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-4" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-4"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - fcNo * 1m - 2m) / 1000m; } break; default: swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0136[BP-]{}-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0162[BP-]{}-4")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; } //----------日本项目需要压缩零件---------- if (item.Japan == "YES") { //吊装垫片 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-10")); swComp.SetSuppression2(0); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern22"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //排风脖颈 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. //排风腔 //重命名装配体内部 compReName = "FNCE0141[UCJDB800-" + tree.Module + "]{" + (int)item.Length + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0141-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Linear austragen1").SystemValue = item.Length / 1000m; swFeat = swComp.FeatureByName("EX"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("Cut-Extrude4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC3"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC5"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 if (item.MARVEL == "YES") { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } else { //吊装垫片 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-10")); swComp.SetSuppression2(2); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern2"); swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩 //排风脖颈 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0019-1")); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swFeat = swComp.FeatureByName("ANSUL"); if (item.ANSUL == "YES") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0020-1")); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0047-1")); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swFeat = swComp.FeatureByName("ANDTEC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0048-2")); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swFeat = swComp.FeatureByName("ANDTEC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //排风腔 //重命名装配体内部 compReName = "FNCE0141[UCJDB800-" + tree.Module + "]{" + (int)item.Length + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0141-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Linear austragen1").SystemValue = item.Length / 1000m; swFeat = swComp.FeatureByName("EX"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("Cut-Extrude4"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch3").SystemValue = item.ExRightDis / 1000m; swPart.Parameter("D1@Sketch3").SystemValue = item.ExLength / 1000m; swPart.Parameter("D2@Sketch3").SystemValue = item.ExWidth / 1000m; if (item.ANSUL == "YES") { //侧喷 if (item.ANSide == "LEFT") { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else if (item.ANSide == "RIGHT") { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //探测器 swFeat = swComp.FeatureByName("ANDTEC1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC3"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC5"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 if (item.ANDetectorNo > 0) { swFeat = swComp.FeatureByName("ANDTEC1"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch9").SystemValue = item.ANDetectorDis1 / 1000m; if (item.ANDetectorEnd == "RIGHT" || (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 1)) { swPart.Parameter("D1@Sketch9").SystemValue = 195m / 1000m; } else { swPart.Parameter("D1@Sketch9").SystemValue = 175m / 1000m; } } if (item.ANDetectorNo > 1) { swFeat = swComp.FeatureByName("ANDTEC2"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch15").SystemValue = item.ANDetectorDis2 / 1000m; if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 2) { swPart.Parameter("D2@Sketch15").SystemValue = 195m / 1000m; } else { swPart.Parameter("D2@Sketch15").SystemValue = 175m / 1000m; } } if (item.ANDetectorNo > 2) { swFeat = swComp.FeatureByName("ANDTEC3"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch16").SystemValue = item.ANDetectorDis3 / 1000m; if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 3) { swPart.Parameter("D2@Sketch16").SystemValue = 195m / 1000m; } else { swPart.Parameter("D2@Sketch16").SystemValue = 175m / 1000m; } } if (item.ANDetectorNo > 3) { swFeat = swComp.FeatureByName("ANDTEC4"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch17").SystemValue = item.ANDetectorDis4 / 1000m; if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 4) { swPart.Parameter("D2@Sketch17").SystemValue = 195m / 1000m; } else { swPart.Parameter("D2@Sketch17").SystemValue = 175m / 1000m; } } if (item.ANDetectorNo > 4) { swFeat = swComp.FeatureByName("ANDTEC5"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch18").SystemValue = item.ANDetectorDis5 / 1000m; if (item.ANDetectorEnd == "LEFT" && item.ANDetectorNo == 5) { swPart.Parameter("D2@Sketch18").SystemValue = 195m / 1000m; } else { swPart.Parameter("D2@Sketch18").SystemValue = 175m / 1000m; } } } else { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC3"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC5"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } if (item.MARVEL == "YES") { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } if (item.LightCable == "LEFT") { swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else if (item.LightCable == "RIGHT") { swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("LIGHT HOLE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LIGHT HOLE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //UV灯 if (item.UVType == "LONG") { swFeat = swComp.FeatureByName("UV L"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D5@Sketch4").SystemValue = (item.ExRightDis - 800m) / 1000m; swPart.Parameter("D8@Sketch4").SystemValue = (item.ExRightDis - 600m) / 1000m; swFeat = swComp.FeatureByName("UV S"); swFeat.SetSuppression2(0, 2, configNames); } else { swFeat = swComp.FeatureByName("UV S"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch11").SystemValue = (item.ExRightDis - 446.5m) / 1000m; swPart.Parameter("D8@Sketch11").SystemValue = (item.ExRightDis - 300m) / 1000m; swFeat = swComp.FeatureByName("UV L"); swFeat.SetSuppression2(0, 2, configNames); } } } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0056-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D1@Skizze1").SystemValue = item.Length / 1000m; //----------SSP灯板支撑条---------- if (item.SSPType == "DOME") { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-4")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-5")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-6")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-5")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m; if (item.Gutter == "YES") { swModel.Parameter("D1@Distance27").SystemValue = item.GutterWidth / 1000m; swModel.Parameter("D1@Distance36").SystemValue = item.GutterWidth / 1000m; } else { swModel.Parameter("D1@Distance27").SystemValue = 0.5m / 1000m; swModel.Parameter("D1@Distance36").SystemValue = 0.5m / 1000m; } } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-4")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-5")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m; if (item.Gutter == "YES") { swModel.Parameter("D1@Distance28").SystemValue = item.GutterWidth / 1000m; swModel.Parameter("D1@Distance37").SystemValue = item.GutterWidth / 1000m; } else { swModel.Parameter("D1@Distance28").SystemValue = 0.5m / 1000m; swModel.Parameter("D1@Distance37").SystemValue = 0.5m / 1000m; } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-6")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-5")); swComp.SetSuppression2(0); //2解压缩,0压缩. } swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }
public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath) { //创建项目模型存放地址 string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName; if (!Directory.Exists(itemPath)) { Directory.CreateDirectory(itemPath); } else { DialogResult result = MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } //Pack的后缀 string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6); //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack //packango后需要接收打包完成的地址,参数为后缀 string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm"; if (!File.Exists(packedAssyPath)) { packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath); } //查询参数 KCJSB265 item = (KCJSB265)objKCJSB265Service.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令 int warnings = 0; int errors = 0; suffix = "_" + suffix;//后缀 ModelDoc2 swModel = default(ModelDoc2); ModelDoc2 swPart = default(ModelDoc2); AssemblyDoc swAssy = default(AssemblyDoc); Component2 swComp; Feature swFeat = default(Feature); object configNames = null; ModelDocExtension swModelDocExt = default(ModelDocExtension); bool status = false; string compReName = string.Empty; //打开Pack后的模型 swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; swAssy = swModel as AssemblyDoc; //装配体 string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称 swModelDocExt = (ModelDocExtension)swModel.Extension; //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错 swModel.ForceRebuild3(true); //TopOnly参数设置成true,只重建顶层,不重建零件内部 /*注意SolidWorks单位是m,计算是应当/1000m * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了 * (int)不进行四舍五入,Convert.ToInt32会四舍五入 */ //-----------计算中间值,---------- int fcNo = (int)((item.Length - item.FCSideLeft - item.FCSideRight) / 499m) - item.FCBlindNo; try { //----------Top Level---------- //判断FC数量,FC侧板长度 if (item.FCBlindNo > 0) { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern3"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern3").SystemValue = item.FCBlindNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D1@Distance11").SystemValue = item.FCSideLeft / 1000m; } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0107[BP-500]{500}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern3"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //判断FC/KSA if (item.FCType == "KSA") { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5202040401-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern4"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern4").SystemValue = fcNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D1@Distance9").SystemValue = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "KCJ FC FILTER-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern2"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern2").SystemValue = fcNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D1@Distance10").SystemValue = (item.FCSideLeft + 500m * item.FCBlindNo) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5202040401-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //----------油网侧板---------- switch (item.FCSide) { case "LEFT": //重命名装配体内部 if (item.FCType == "KSA") { compReName = "FNCE0108[BP-" + tree.Module + "]{" + (int)(item.FCSideLeft + fcNo * 2.5m) + "}"; } else { compReName = "FNCE0108[BP-" + tree.Module + "]{" + (int)(item.FCSideLeft - 4m) + "}"; } status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 if (item.FCType == "KSA") { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft + fcNo * 2.5m) / 1000m; } else { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - 4m) / 1000m; } } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; case "RIGHT": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. //重命名装配体内部 if (item.FCType == "KSA") { compReName = "FNCE0109[BP-" + tree.Module + "]{" + (int)(item.FCSideRight + fcNo * 2.5m) + "}"; } else { compReName = "FNCE0109[BP-" + tree.Module + "]{" + (int)(item.FCSideRight - 4m) + "}"; } status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 if (item.FCType == "KSA") { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight + fcNo * 2.5m) / 1000m; } else { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - 4m) / 1000m; } } break; case "BOTH": //重命名装配体内部 if (item.FCType == "KSA") { compReName = "FNCE0108[BP-" + tree.Module + ".1]{" + (int)(item.FCSideLeft + fcNo * 1.25m) + "}"; } else { compReName = "FNCE0108[BP-" + tree.Module + "]{" + (int)(item.FCSideLeft - 2m) + "}"; } status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 if (item.FCType == "KSA") { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft + fcNo * 1.25m) / 1000m; } else { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideLeft - 2m) / 1000m; } } //重命名装配体内部 if (item.FCType == "KSA") { compReName = "FNCE0109[BP-" + tree.Module + ".2]{" + (int)(item.FCSideRight + fcNo * 1.25m) + "}"; } else { compReName = "FNCE0109[BP-" + tree.Module + "]{" + (int)(item.FCSideRight - 2m) + "}"; } status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 if (item.FCType == "KSA") { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight + fcNo * 1.25m) / 1000m; } else { swPart.Parameter("D2@草图1").SystemValue = (item.FCSideRight - 2m) / 1000m; } } break; default: swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0108[BP-]{}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0109[BP-]{}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; } //----------日本项目需要压缩零件---------- if (item.Japan == "YES") { //吊装垫片 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9")); swComp.SetSuppression2(0); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //排风脖颈 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. //排风滑门 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXDOOR-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. //排风腔 //重命名装配体内部 compReName = "FNCE0125[KCJSB265-" + tree.Module + "]{" + (int)item.Length + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0125-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-2"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Aufsatz-Linear austragen1").SystemValue = item.Length / 1000m; swFeat = swComp.FeatureByName("EX"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("Cut-Extrude4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 if (item.MARVEL == "YES") { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } else { //吊装垫片 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9")); swComp.SetSuppression2(2); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(2, 2, configNames); //参数1:1解压,0压缩 //排风脖颈 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXSPIGOT-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0019-1")); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swFeat = swComp.FeatureByName("ANSUL"); if (item.ANSUL == "YES") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0020-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = (item.ExLength + 50m) / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0047-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swFeat = swComp.FeatureByName("ANDTEC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0048-2")); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@基体-法兰1").SystemValue = item.ExWidth / 1000m; swPart.Parameter("D3@草图1").SystemValue = item.ExHeight / 1000m; swFeat = swComp.FeatureByName("ANDTEC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //排风滑门 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "EXDOOR-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Distance3").SystemValue = (item.ExWidth + 20m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0018-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D2@Base-Flange1").SystemValue = (item.ExLength * 2m + 100m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0013-1")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D1@Sketch1").SystemValue = (item.ExLength / 2m + 10m) / 1000m; swPart.Parameter("D2@Sketch1").SystemValue = (item.ExWidth + 40m) / 1000m; //排风腔 //重命名装配体内部 compReName = "FNCE0125[KCJSB265-" + tree.Module + "]{" + (int)item.Length + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0125-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-2"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Aufsatz-Linear austragen1").SystemValue = item.Length / 1000m; swFeat = swComp.FeatureByName("EX"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("Cut-Extrude4"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch2").SystemValue = item.ExRightDis / 1000m; swPart.Parameter("D1@Sketch2").SystemValue = item.ExLength / 1000m; swPart.Parameter("D2@Sketch2").SystemValue = item.ExWidth / 1000m; if (item.ANSUL == "YES") { //侧喷 if (item.ANSide == "LEFT") { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else if (item.ANSide == "RIGHT") { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //探测器 if (item.ANDetector == "LEFT") { swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else if (item.ANDetector == "RIGHT") { swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else if (item.ANDetector == "BOTH") { swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } else { swFeat = swComp.FeatureByName("ANSULSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANSULSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTECSIDE LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } if (item.MARVEL == "YES") { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("MA-NTC"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA-TAB"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } //----------SSP灯板支撑条---------- if (item.SSPType == "DOME") { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m; if (item.Gutter == "YES") { swModel.Parameter("D1@Distance12").SystemValue = item.GutterWidth / 1000m; } else { swModel.Parameter("D1@Distance12").SystemValue = 0.5m / 1000m; } } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0036-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Sketch1").SystemValue = item.Length / 1000m; if (item.Gutter == "YES") { swModel.Parameter("D1@Distance2").SystemValue = item.GutterWidth / 1000m; } else { swModel.Parameter("D1@Distance2").SystemValue = 0.5m / 1000m; } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0035-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. } swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }
public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath) { //创建项目模型存放地址 string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName; if (!Directory.Exists(itemPath)) { Directory.CreateDirectory(itemPath); } else { DialogResult result = MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } //Pack的后缀 string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6); //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack //packango后需要接收打包完成的地址,参数为后缀 string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm"; if (!File.Exists(packedAssyPath)) { packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath); } //查询参数 LLEDS item = (LLEDS)objLLEDSService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令 int warnings = 0; int errors = 0; suffix = "_" + suffix;//后缀 ModelDoc2 swModel = default(ModelDoc2); ModelDoc2 swPart = default(ModelDoc2); AssemblyDoc swAssy = default(AssemblyDoc); Component2 swComp; Feature swFeat = default(Feature); object configNames = null; ModelDocExtension swModelDocExt = default(ModelDocExtension); bool status = false; string compReName = string.Empty; //打开Pack后的模型 swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; swAssy = swModel as AssemblyDoc; //装配体 string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称 swModelDocExt = (ModelDocExtension)swModel.Extension; //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错 swModel.ForceRebuild3(true); //TopOnly参数设置成true,只重建顶层,不重建零件内部 /*注意SolidWorks单位是m,计算是应当/1000m * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了 * (int)不进行四舍五入,Convert.ToInt32会四舍五入 */ //-----------计算中间值,---------- int stdPanelNo = (int)((item.Length - 300.5m) / 1500m);//1500+300直接做成一块 decimal sideLength = item.Length - stdPanelNo * 1500m; int ledNo = (int)((sideLength - 300m) / 500m); try { //----------Top Level---------- swModel.Parameter("D1@Distance3").SystemValue = item.Length / 1000m; //----------边缘板---------- //重命名装配体内部 compReName = "FNCL0023[LLEDS-" + tree.Module + "]{" + (int)sideLength + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCL0023[LLEDS-]{}-2") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-2" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-2"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Skizze1").SystemValue = sideLength / 1000m; swFeat = swComp.FeatureByName("LPattern1"); if (ledNo > 0) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@LPattern1").SystemValue = ledNo + 1; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } //----------标准板---------- if (stdPanelNo > 0) { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0022[LLEDS-STD]{1483}-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600003-1")); swComp.SetSuppression2(2); //2解压缩,0压缩. } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCL0022[LLEDS-STD]{1483}-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200600003-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. } swFeat = swAssy.FeatureByName("LocalLPattern1"); if (stdPanelNo > 1) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern1").SystemValue = stdPanelNo; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }
public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath) { //创建项目模型存放地址 string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName; if (!Directory.Exists(itemPath)) { Directory.CreateDirectory(itemPath); } else { DialogResult result = MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } //Pack的后缀 string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6); //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack //packango后需要接收打包完成的地址,参数为后缀 string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm"; if (!File.Exists(packedAssyPath)) { packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath); } //查询参数 LFUSA item = (LFUSA)objLFUSAService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令 int warnings = 0; int errors = 0; suffix = "_" + suffix;//后缀 ModelDoc2 swModel = default(ModelDoc2); ModelDoc2 swPart = default(ModelDoc2); AssemblyDoc swAssy = default(AssemblyDoc); Component2 swComp; Feature swFeat = default(Feature); object configNames = null; ModelDocExtension swModelDocExt = default(ModelDocExtension); bool status = false; string compReName = string.Empty; //打开Pack后的模型 swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; swAssy = swModel as AssemblyDoc; //装配体 string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称 swModelDocExt = (ModelDocExtension)swModel.Extension; //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错 swModel.ForceRebuild3(true); //TopOnly参数设置成true,只重建顶层,不重建零件内部 /*注意SolidWorks单位是m,计算是应当/1000m * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了 * (int)不进行四舍五入,Convert.ToInt32会四舍五入 */ //-----------计算中间值,---------- try { //----------Top Level---------- //----------散流器主体---------- //重命名装配体内部 compReName = "FNCA0001[LFUSA-" + tree.Module + "]{" + (int)item.Length + "}(" + (int)item.Width + ")"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCA0001-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Base-Flange1").SystemValue = item.Length / 1000m; swPart.Parameter("D1@Sketch1").SystemValue = (item.Width - 2m) / 1000m; swPart.Parameter("D2@Sketch2").SystemValue = item.SuDia / 1000m; swPart.Parameter("D1@Sketch2").SystemValue = (item.SuDis * (item.SuNo / 2m - 1m) + item.SuDis / 2m) / 1000m; if (item.SuNo < 2) { swFeat = swComp.FeatureByName("LPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("LPattern1"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@LPattern1").SystemValue = item.SuNo; swPart.Parameter("D3@LPattern1").SystemValue = item.SuDis / 1000m; } swFeat = swComp.FeatureByName("HANGERHOLE"); if (item.Japan == "YES") { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("CUTLEFT"); if (item.SidePanel == "LEFT" || item.SidePanel == "BOTH") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("CUTRIGHT"); if (item.SidePanel == "RIGHT" || item.SidePanel == "BOTH") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } //----------侧板---------- switch (item.SidePanel) { case "LEFT": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Sketch1").SystemValue = (item.Width - 2m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-4")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D9@Skizze1").SystemValue = (item.Width - 2m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; case "RIGHT": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-4")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-3")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Sketch1").SystemValue = (item.Width - 2m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-3")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D9@Skizze1").SystemValue = (item.Width - 2m) / 1000m; break; case "MIDDLE": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-4")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-3")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D9@Skizze1").SystemValue = (item.Width - 2m) / 1000m; break; default: swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D1@Sketch1").SystemValue = (item.Width - 2m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-4")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0002-3")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCA0003-3")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; } if (item.Japan == "YES") { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9")); swComp.SetSuppression2(0); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0070-9")); swComp.SetSuppression2(2); //2解压缩,0压缩. swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }
public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath) { //创建项目模型存放地址 string itemPath = projectPath + @"\" + tree.Item + "-" + tree.Module + "-" + tree.CategoryName; if (!Directory.Exists(itemPath)) { Directory.CreateDirectory(itemPath); } else { DialogResult result = MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } //Pack的后缀 string suffix = tree.Item + "-" + tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6); //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack //packango后需要接收打包完成的地址,参数为后缀 string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm"; if (!File.Exists(packedAssyPath)) { packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath); } //查询参数 KVS item = (KVS)objKVSService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令 int warnings = 0; int errors = 0; suffix = "_" + suffix;//后缀 ModelDoc2 swModel = default(ModelDoc2); ModelDoc2 swPart = default(ModelDoc2); AssemblyDoc swAssy = default(AssemblyDoc); Component2 swComp; Feature swFeat = default(Feature); object configNames = null; //打开Pack后的模型 swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; swAssy = swModel as AssemblyDoc; //装配体 //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错 swModel.ForceRebuild3(true); //TopOnly参数设置成true,只重建顶层,不重建零件内部 /*注意SolidWorks单位是m,计算是应当/1000m * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了 * (int)不进行四舍五入,Convert.ToInt32会四舍五入 */ //-----------计算中间值,---------- //新风CJ孔数量和新风CJ孔第一个CJ距离边缘距离 int frontCjNo = (int)((item.Length - 3m - 30m) / 32m) + 1; decimal frontCjFirstDis = (item.Length - 3m - (frontCjNo - 1) * 32m) / 2m; //铆钉数量 int rivetNo = (int)((item.Length - 200m) / 300m); decimal rivetDis = (item.Length - 200m) / rivetNo; //为了适应肯德基脖颈缺口 decimal midRoofSecondHoleDis = 0m; if (item.ExNo == 2) { midRoofSecondHoleDis = (item.Length - 300m - item.ExDis - item.ExLength) / 4m; } else if (item.ExNo == 1) { midRoofSecondHoleDis = (item.Length - 300m) / 2m; } //KSA数量,KSA侧板长度(以全长计算) int ksaNo = (int)((item.Length - 7m) / 498m); decimal ksaSideLength = (item.Length - 8m - ksaNo * 498m) / 2m; try { //----------Top Level---------- ////判断KSA数量,KSA侧板长度,如果太小,则使用特殊小侧板侧边 //swFeat = swAssy.FeatureByName("LocalLPattern1"); //if (ksaNo == 1) swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //else //{ // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swModel.Parameter("D1@LocalLPattern1").SystemValue = ksaNo; //D1阵列数量,D3阵列距离 //} ////KSA距离左边缘 //if (ksaSideLength < 12m / 1000m) swModel.Parameter("D1@Distance15").SystemValue = 0.5m / 1000m; //else swModel.Parameter("D1@Distance15").SystemValue = ksaSideLength; //排风脖颈数量和距离 if (item.ExNo == 1) { swModel.Parameter("D1@Distance52").SystemValue = (item.Length - item.ExLength) / 2000m; swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else if (item.ExNo == 2) { swModel.Parameter("D1@Distance52").SystemValue = ((item.Length - item.ExDis) / 2m - item.ExLength) / 1000m; swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern1").SystemValue = item.ExNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D3@LocalLPattern1").SystemValue = (item.ExDis + item.ExLength) / 1000m; //D1阵列数量,D3阵列距离 } //日光灯 if (item.LightType == "FSSHORT") { //SHORT swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0003-3")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0004-2")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0005-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0005-2")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020404-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020406-S-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-3")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-4")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300026-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300026-3")); swComp.SetSuppression2(2); //2解压缩,0压缩 //LONG swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0002-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0002-2")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0003-4")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0004-3")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020405-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020407-S-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-5")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-6")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300023-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300023-2")); swComp.SetSuppression2(0); //2解压缩,0压缩 } else { //SHORT swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0003-3")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0004-2")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0005-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0005-2")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020404-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020406-S-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-3")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-4")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300026-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300026-3")); swComp.SetSuppression2(0); //2解压缩,0压缩 //LONG swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0002-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0002-2")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0003-4")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0004-3")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020405-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020407-S-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-5")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020424-6")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300023-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "2200300023-2")); swComp.SetSuppression2(2); //2解压缩,0压缩 } //----------排风腔---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0110-1")); swPart = swComp.GetModelDoc2();//打开零件3 swPart.Parameter("D1@Sketch1").SystemValue = (item.Length - 7m) / 1000m; swPart.Parameter("D5@Sketch62").SystemValue = (item.ExDis + item.ExLength) / 1000m; //排风口 if (item.ExNo == 1) { swFeat = swComp.FeatureByName("EXCOONE"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("EXCOTWO"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch115").SystemValue = item.ExLength / 1000m; swPart.Parameter("D2@Sketch115").SystemValue = item.ExWidth / 1000m; swPart.Parameter("D5@Sketch62").SystemValue = midRoofSecondHoleDis / 1000m; } else { swFeat = swComp.FeatureByName("EXCOONE"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("EXCOTWO"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch114").SystemValue = item.ExDis / 1000m; swPart.Parameter("D2@Sketch114").SystemValue = item.ExLength / 1000m; swPart.Parameter("D1@Sketch114").SystemValue = item.ExWidth / 1000m; swPart.Parameter("D5@Sketch62").SystemValue = (item.ExDis + item.ExLength) / 1000m; if (midRoofSecondHoleDis > 300m) { swFeat = swComp.FeatureByName("MIDROOFINSDIS2"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch116").SystemValue = midRoofSecondHoleDis / 1000m; } else { swFeat = swComp.FeatureByName("MIDROOFINSDIS2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } //----------其他零件---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0111-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Sketch1").SystemValue = (item.Length - 6m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0112-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Sketch3").SystemValue = ksaSideLength / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0113-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Sketch3").SystemValue = ksaSideLength / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0114-2")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D1@Sketch1").SystemValue = (item.ExLength + 50m) / 1000m; swPart.Parameter("D2@Sketch1").SystemValue = (item.ExHeight + 54.8m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0115-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D1@Sketch1").SystemValue = (item.ExLength + 50m) / 1000m; swPart.Parameter("D2@Sketch1").SystemValue = (item.ExHeight + 54.8m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0117-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D1@Sketch1").SystemValue = item.ExLength / 2000m; swPart.Parameter("D2@Sketch1").SystemValue = (item.ExWidth + 20m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0118-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Sketch1").SystemValue = (item.ExLength * 2m) / 1000m; //----------MiddleRoof灯板---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHM0023-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Sketch1").SystemValue = (item.Length - 3m) / 1000m; swPart.Parameter("D1@Sketch1").SystemValue = (item.Deepth - 788.5m) / 1000m; if (item.ExNo == 1) { swFeat = swComp.FeatureByName("MIDROOFINSDIS2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D2@Sketch20").SystemValue = midRoofSecondHoleDis / 1000m; } else { swPart.Parameter("D2@Sketch20").SystemValue = (item.ExDis + item.ExLength) / 1000m; if (midRoofSecondHoleDis > 300m) { swFeat = swComp.FeatureByName("MIDROOFINSDIS2"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch26").SystemValue = midRoofSecondHoleDis / 1000m; } else { swFeat = swComp.FeatureByName("MIDROOFINSDIS2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } //灯具 if (item.LightType == "FSSHORT") { swFeat = swComp.FeatureByName("FSLONG"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("FSSHORT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("FSLONG"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("FSSHORT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201020401-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Deepth - 793m) / 1000m; //----------大侧板---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHS0036-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Sketch1").SystemValue = item.Deepth / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHS0037-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Sketch1").SystemValue = item.Deepth / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHS0038-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Sketch1").SystemValue = item.Deepth / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHS0039-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Sketch1").SystemValue = item.Deepth / 1000m; //------------新风腔---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHA0052-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 7m) / 1000m; if (item.ExNo == 1) { swFeat = swComp.FeatureByName("MIDROOFINSDIS2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch50").SystemValue = midRoofSecondHoleDis / 1000m; } else { swPart.Parameter("D3@Sketch50").SystemValue = (item.ExDis + item.ExLength) / 1000m; if (midRoofSecondHoleDis > 300m) { swFeat = swComp.FeatureByName("MIDROOFINSDIS2"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch127").SystemValue = midRoofSecondHoleDis / 1000m; } else { swFeat = swComp.FeatureByName("MIDROOFINSDIS2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } swPart.Parameter("D1@LPattern2").SystemValue = rivetNo + 1; swPart.Parameter("D3@LPattern2").SystemValue = rivetDis / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHA0053-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 103m) / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHA0054-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 3m) / 1000m; swPart.Parameter("D1@LPattern1").SystemValue = frontCjNo; swPart.Parameter("D10@Sketch8").SystemValue = frontCjFirstDis / 1000m; swPart.Parameter("D1@LPattern2").SystemValue = rivetNo + 1; swPart.Parameter("D3@LPattern2").SystemValue = rivetDis / 1000m; swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHA0055-1")); swPart = swComp.GetModelDoc2(); swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 7m) / 1000m; swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }
public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath) { //创建项目模型存放地址 string itemPath = projectPath + @"\" + tree.Item + "-" + tree.Module + "-" + tree.CategoryName; if (!Directory.Exists(itemPath)) { Directory.CreateDirectory(itemPath); } else { DialogResult result = MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } //Pack的后缀 string suffix = tree.Item + "-" + tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6); //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack //packango后需要接收打包完成的地址,参数为后缀 string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm"; if (!File.Exists(packedAssyPath)) { packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath); } //查询参数 LSDOST item = (LSDOST)objLSDOSTService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令 int warnings = 0; int errors = 0; suffix = "_" + suffix;//后缀 ModelDoc2 swModel = default(ModelDoc2); ModelDoc2 swPart = default(ModelDoc2); AssemblyDoc swAssy = default(AssemblyDoc); Component2 swComp; Feature swFeat = default(Feature); object configNames = null; //打开Pack后的模型 swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; swAssy = swModel as AssemblyDoc; //装配体 //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错 swModel.ForceRebuild3(true); //TopOnly参数设置成true,只重建顶层,不重建零件内部 /*注意SolidWorks单位是m,计算是应当/1000m * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了 * (int)不进行四舍五入,Convert.ToInt32会四舍五入 */ //-----------计算中间值,---------- //铆钉数量 int rivetNo = (int)((item.Length - 47m) / 400m); decimal rivetDis = (item.Length - 47m) / rivetNo; try { //----------Top Level---------- //排风脖颈数量和距离 if (item.SuNo == 1) { swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D1@LocalLPattern1").SystemValue = item.SuNo; //D1阵列数量,D3阵列距离 swModel.Parameter("D3@LocalLPattern1").SystemValue = item.SuDis / 1000m; //D1阵列数量,D3阵列距离 } //中间测风压孔,三个脖颈时解压,两块网孔板 if (item.SuNo == 3) { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNLC0005-2")); swComp.SetSuppression2(2); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNLC0006-1")); swComp.SetSuppression2(2); //2解压缩,0压缩 swModel.Parameter("D1@LocalLPattern2").SystemValue = 4; //D1阵列数量,D3阵列距离 swModel.Parameter("D3@LocalLPattern2").SystemValue = (item.Length - 400m) / 3000m; } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNLC0005-2")); swComp.SetSuppression2(0); //2解压缩,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNLC0006-1")); swComp.SetSuppression2(0); //2解压缩,0压缩 swModel.Parameter("D1@LocalLPattern2").SystemValue = 2; //D1阵列数量,D3阵列距离 swModel.Parameter("D3@LocalLPattern2").SystemValue = item.Length - 400m / 3000m; } //----------散流器---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNLC0001-1")); swPart = swComp.GetModelDoc2();//打开零件3 swPart.Parameter("D2@Sketch1").SystemValue = (item.Length - 7m) / 1000m; if (item.SuNo == 1) { swFeat = swComp.FeatureByName("LPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch30").SystemValue = 0; } else { swPart.Parameter("D3@Sketch30").SystemValue = (item.SuDis * (item.SuNo / 2m - 1) + item.SuDis / 2m) / 1000; swFeat = swComp.FeatureByName("LPattern1"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@LPattern1").SystemValue = item.SuNo; //D1阵列数量,D3阵列距离 swPart.Parameter("D3@LPattern1").SystemValue = item.SuDis / 1000m; //D1阵列数量,D3阵列距离 } if (rivetNo < 2) { swFeat = swComp.FeatureByName("Cut-Extrude10"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LPattern2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swPart.Parameter("D1@Sketch43").SystemValue = rivetDis / 1000m; swFeat = swComp.FeatureByName("Cut-Extrude10"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LPattern2"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@LPattern2").SystemValue = rivetNo; //D1阵列数量,D3阵列距离 swPart.Parameter("D3@LPattern2").SystemValue = rivetDis / 1000m; } swFeat = swComp.FeatureByName("Cut-Extrude11"); if (item.SuNo == 3) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNLC0003-3")); swPart = swComp.GetModelDoc2();//打开零件3 swPart.Parameter("D2@Sketch1").SystemValue = (item.Length - 4m) / 1000m; if (rivetNo < 2) { swFeat = swComp.FeatureByName("Cut-Extrude4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swPart.Parameter("D1@Sketch11").SystemValue = rivetDis / 1000m; swFeat = swComp.FeatureByName("Cut-Extrude4"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("LPattern1"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@LPattern1").SystemValue = rivetNo; //D1阵列数量,D3阵列距离 swPart.Parameter("D3@LPattern1").SystemValue = rivetDis / 1000m; } swFeat = swComp.FeatureByName("Cut-Extrude3"); if (item.SuNo == 3) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNLC0005-1")); swPart = swComp.GetModelDoc2();//打开零件3 if (item.SuNo == 3) { swPart.Parameter("D1@Skizze1").SystemValue = (item.Length - 112m - 34m) / 2000m; } else { swPart.Parameter("D1@Skizze1").SystemValue = (item.Length - 112m) / 1000m; } swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }
public void AutoDrawing(SldWorks swApp, ModuleTree tree, string projectPath) { //创建项目模型存放地址 string itemPath = projectPath + @"\" + tree.Module + "-" + tree.CategoryName; if (!Directory.Exists(itemPath)) { Directory.CreateDirectory(itemPath); } else { DialogResult result = MessageBox.Show("模型文件夹" + itemPath + "存在,如果之前pack已经执行过,将不执行pack过程而是直接修改模型,如果要继续请点击YES,否请点击No中断作图", "提示信息", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } //Pack的后缀 string suffix = tree.Module + "-" + tree.ODPNo.Substring(tree.ODPNo.Length - 6); //判断文件是否存在,如果存在将不执行pack,如果不存在则执行pack //packango后需要接收打包完成的地址,参数为后缀 string packedAssyPath = itemPath + @"\" + tree.CategoryName.ToLower() + "_" + suffix + ".sldasm"; if (!File.Exists(packedAssyPath)) { packedAssyPath = CommonFunc.PackAndGoFunc(suffix, swApp, tree.ModelPath, itemPath); } //查询参数 AN item = (AN)objANService.GetModelByModuleTreeId(tree.ModuleTreeId.ToString()); swApp.CommandInProgress = true; //告诉SolidWorks,现在是用外部程序调用命令 int warnings = 0; int errors = 0; suffix = "_" + suffix;//后缀 ModelDoc2 swModel = default(ModelDoc2); ModelDoc2 swPart = default(ModelDoc2); AssemblyDoc swAssy = default(AssemblyDoc); Component2 swComp; Feature swFeat = default(Feature); object configNames = null; ModelDocExtension swModelDocExt = default(ModelDocExtension); bool status = false; string compReName = string.Empty; //打开Pack后的模型 swModel = swApp.OpenDoc6(packedAssyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; swAssy = swModel as AssemblyDoc; //装配体 string assyName = swModel.GetTitle().Substring(0, swModel.GetTitle().Length - 7); //获取装配体名称 swModelDocExt = (ModelDocExtension)swModel.Extension; //打开装配体后必须重建,使Pack后的零件名都更新到带后缀的状态,否则程序出错 swModel.ForceRebuild3(true); //TopOnly参数设置成true,只重建顶层,不重建零件内部 /*注意SolidWorks单位是m,计算是应当/1000m * 整形与整形运算得出的结果仍然时整形,1640 / 1000m结果为0,因此必须将其中一个转化成decimal型,使用后缀m就可以了 * (int)不进行四舍五入,Convert.ToInt32会四舍五入 */ //-----------计算中间值,---------- try { //----------Top Level---------- //----------IR保护支架---------- if (item.MARVEL == "NO") { swFeat = swAssy.FeatureByName("LocalLPattern1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCB0001-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCB0001-1")); if (item.IRNo > 0) { swComp.SetSuppression2(2); //2解压缩,0压缩. } else { swComp.SetSuppression2(0); //2解压缩,0压缩. } swFeat = swAssy.FeatureByName("LocalLPattern1"); if (item.IRNo > 1) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D3@LocalLPattern1").SystemValue = item.IRDis2 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swAssy.FeatureByName("LocalLPattern2"); if (item.IRNo > 2) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D3@LocalLPattern2").SystemValue = (item.IRDis2 + item.IRDis3) / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } //----------ANSUL探测器盒子---------- if (item.ANSUL == "NO") { swFeat = swAssy.FeatureByName("LocalLPattern3"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern5"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swAssy.FeatureByName("LocalLPattern6"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201990405-1")); swComp.SetSuppression2(0); //2解压缩,0压缩. } else { swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "5201990405-1")); if (item.ANDetectorNo > 0) { swComp.SetSuppression2(2); //2解压缩,0压缩. } else { swComp.SetSuppression2(0); //2解压缩,0压缩. } swFeat = swAssy.FeatureByName("LocalLPattern3"); if (item.ANDetectorNo > 1) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D3@LocalLPattern3").SystemValue = item.ANDetectorDis2 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swAssy.FeatureByName("LocalLPattern4"); if (item.ANDetectorNo > 2) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D3@LocalLPattern4").SystemValue = (item.ANDetectorDis2 + item.ANDetectorDis3) / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swAssy.FeatureByName("LocalLPattern5"); if (item.ANDetectorNo > 2) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D3@LocalLPattern5").SystemValue = (item.ANDetectorDis2 + item.ANDetectorDis3 + item.ANDetectorDis4) / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swAssy.FeatureByName("LocalLPattern6"); if (item.ANDetectorNo > 2) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swModel.Parameter("D3@LocalLPattern6").SystemValue = (item.ANDetectorDis2 + item.ANDetectorDis3 + item.ANDetectorDis4 + item.ANDetectorDis5) / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } //----------ANSUL腔体---------- //重命名装配体内部 compReName = "FNCE0025[AN-" + tree.Module + "]{" + (int)item.Length + "}(" + (int)item.Width + ")"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCE0025-1") + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); if (status) { swModelDocExt.RenameDocument(compReName); } swModel.ClearSelection2(true); status = swModelDocExt.SelectByID2(compReName + "-1" + "@" + assyName, "COMPONENT", 0, 0, 0, false, 0, null, 0); swModel.ClearSelection2(true); if (status) { swComp = swAssy.GetComponentByName(compReName + "-1"); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Base-Flange1").SystemValue = item.Length / 1000m; swPart.Parameter("D1@Sketch1").SystemValue = item.Width / 1000m; if (item.ANSUL == "NO") { swFeat = swComp.FeatureByName("AN1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("AN2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("AN3"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("AN4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("AN5"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC3"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC4"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ANDTEC5"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("AN1"); if (item.ANDropNo > 0) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch7").SystemValue = item.ANYDis / 1000m; swPart.Parameter("D2@Sketch7").SystemValue = item.ANDropDis1 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("AN2"); if (item.ANDropNo > 1) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D2@Sketch9").SystemValue = item.ANDropDis2 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("AN3"); if (item.ANDropNo > 2) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D2@Sketch10").SystemValue = item.ANDropDis3 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } if (item.ANDropNo > 3) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D2@Sketch11").SystemValue = item.ANDropDis4 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } if (item.ANDropNo > 4) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D2@Sketch12").SystemValue = item.ANDropDis5 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("ANDTEC1"); if (item.ANDetectorNo > 0) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch13").SystemValue = item.ANDetectorDis1 / 1000m; if (item.ANDetectorEnd == "RIGHT") { swPart.Parameter("D1@Sketch13").SystemValue = 195m / 1000m; } else { swPart.Parameter("D1@Sketch13").SystemValue = 175m / 1000m; } } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("ANDTEC2"); if (item.ANDetectorNo > 1) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch14").SystemValue = item.ANDetectorDis2 / 1000m; if (item.ANDetectorEnd == "RIGHT") { swPart.Parameter("D1@Sketch14").SystemValue = 195m / 1000m; } else { swPart.Parameter("D1@Sketch14").SystemValue = 175m / 1000m; } } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("ANDTEC3"); if (item.ANDetectorNo > 2) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch15").SystemValue = item.ANDetectorDis3 / 1000m; if (item.ANDetectorEnd == "RIGHT") { swPart.Parameter("D1@Sketch15").SystemValue = 195m / 1000m; } else { swPart.Parameter("D1@Sketch15").SystemValue = 175m / 1000m; } } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("ANDTEC4"); if (item.ANDetectorNo > 3) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch16").SystemValue = item.ANDetectorDis4 / 1000m; if (item.ANDetectorEnd == "RIGHT") { swPart.Parameter("D1@Sketch16").SystemValue = 195m / 1000m; } else { swPart.Parameter("D1@Sketch16").SystemValue = 175m / 1000m; } } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("ANDTEC5"); if (item.ANDetectorNo > 4) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D3@Sketch17").SystemValue = item.ANDetectorDis5 / 1000m; if (item.ANDetectorEnd == "RIGHT") { swPart.Parameter("D1@Sketch17").SystemValue = 195m / 1000m; } else { swPart.Parameter("D1@Sketch17").SystemValue = 175m / 1000m; } } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } if (item.MARVEL == "NO") { swFeat = swComp.FeatureByName("MA1"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA2"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("MA3"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("MA1"); if (item.IRNo > 0) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D2@Sketch18").SystemValue = item.ANYDis / 1000m; swPart.Parameter("D1@Sketch18").SystemValue = item.IRDis1 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("MA2"); if (item.IRNo > 1) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch19").SystemValue = item.IRDis2 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("MA3"); if (item.IRNo > 2) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch20").SystemValue = item.IRDis3 / 1000m; } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } } } //----------ANSUL腔侧板---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCE0001-1")); swPart = swComp.GetModelDoc2(); //打开零件 swPart.Parameter("D2@Sketch2").SystemValue = (item.Width - 2m) / 1000m; swFeat = swComp.FeatureByName("ANDTEC HOLE"); if (item.ANSUL == "YES" && item.ANDetectorNo > 0) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swModel.ForceRebuild3(true); //设置成true,直接更新顶层,速度很快,设置成false,每个零件都会更新,很慢 swModel.Save(); //保存,很耗时间 swApp.CloseDoc(packedAssyPath); //关闭,很快 } catch (Exception ex) { throw new Exception(packedAssyPath + "作图过程发生异常,详细:" + ex.Message); } finally { swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } }