void SwPartParamsChangeWithNewName(string partName, string newName, string[,] newParams, bool newFuncOfAdding) { try { Логгер.Информация($"Начало изменения детали {partName}", newName, null, "SwPartParamsChangeWithNewName"); var swDoc = _swApp.OpenDoc6(partName + ".SLDPRT", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0); var modName = swDoc.GetPathName(); for (var i = 0; i < newParams.Length / 2; i++) { try { var myDimension = ((Dimension)(swDoc.Parameter(newParams[i, 0] + "@" + partName + ".SLDPRT"))); var param = Convert.ToDouble(newParams[i, 1]); var swParametr = param; myDimension.SystemValue = swParametr / 1000; swDoc.EditRebuild3(); } catch (Exception e) { Логгер.Ошибка(string.Format("Во время изменения детали {4} произошла ошибка при изменении параметров {0}={1}. {2} {3}", newParams[i, 0], newParams[i, 1], e.TargetSite, e.Message, Path.GetFileNameWithoutExtension(modName)), newName, null, "SwPartParamsChangeWithNewName"); } } if (newName == "") { return; } swDoc.EditRebuild3(); swDoc.ForceRebuild3(false); if (!newFuncOfAdding) { NewComponents.Add(new VaultSystem.VentsCadFile { LocalPartFileInfo = new FileInfo(newName + ".SLDPRT").FullName }); } if (newFuncOfAdding) { NewComponents.Add(new VaultSystem.VentsCadFile { LocalPartFileInfo = new FileInfo(newName + ".SLDPRT").FullName, PartIdSql = Convert.ToInt32(newName.Substring(newName.LastIndexOf('-') + 1)) }); } swDoc.SaveAs2(newName + ".SLDPRT", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, false, true); _swApp.CloseDoc(newName + ".SLDPRT"); Логгер.Информация($"Деталь {partName} изменена и сохранена по пути {new FileInfo(newName).FullName}", null, newName, "SwPartParamsChangeWithNewName"); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { Invoke(new MethodInvoker(() => { if (templateDrawing != null) { sldWorks.CloseDoc(((ModelDoc2)templateDrawing).GetTitle()); templateDrawing = null; } activeDocTitleBox.Enabled = true; prefixTextBox.Enabled = true; comboBox1.Enabled = true; button1.Image = Properties.Resources.play; button1.Enabled = true; })); var duration = DateTime.Now - timeStarted; Print("Run time: " + duration.ToReadableFormat()); Print("Done.", Color.Green); sldWorks.ActiveModelDocChangeNotify += SldWorks_ActiveModelDocChangeNotify; }
public List <Files.Info> Convert(SldWorks swApp, List <Files.Info> filesToConvert) { var ListForBatchAdd = new List <Files.Info>(); var fileNameErr = ""; foreach (var item in filesToConvert) { fileNameErr = item.FullFilePath; edmTaskInstance.SetProgressPos(filesToProceed++, item.FullFilePath); Logger.Add($"Open in Solidworks : {item.FileName}"); ModelDoc2 swModel = swApp.OpenDoc6(item.FullFilePath, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0); // Запуск конвертации только для литовых деталей if (IsSheetMetalPart(swModel)) { Exception exOut = null; var confArray = (object[])swModel.GetConfigurationNames(); bool isFix = false; ExportDataToXmlSql(swApp, item, swModel, ref exOut, confArray, out isFix); ConvertToDxf(swApp, item, swModel, ref exOut, confArray, isFix); // ConvertToEprt(swApp, ListForBatchAdd, item, swModel); } Logger.Add($"CloseDoc: {item.FileName}"); swApp.CloseDoc(item.FullFilePath); } return(ListForBatchAdd); }
/// <summary> /// 关闭SW文件(指定的文件名) /// </summary> /// <param name="fileName"></param> public static void CloseDoc(string fileName) { if (swApp != null) { swApp.CloseDoc(fileName); } }
public static void AddModelsFromFolderM(List <string> modelsPaths) { try{ foreach (string modelPath in modelsPaths) { SldWorks swApp = Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")) as SldWorks; swApp.Visible = false; swApp.OpenDocSilent(modelPath, (int)swDocumentTypes_e.swDocPART, ref fileerror); ModelDoc2 swModel; swModel = swApp.ActiveDoc; if (swModel != null) { swModel.Visible = false; } double[] modelXYZ = SolidWorksUtil.GetModelXYZ((PartDoc)swModel); DataBaseUtil.AddModelToDataBase(swModel.GetTitle(), Convert.ToSingle(modelXYZ[0]), Convert.ToSingle(modelXYZ[1]), Convert.ToSingle(modelXYZ[2]), AddModelsFromFolder.privateModelCheckBox.Checked, Utils.ModelToBytes(swModel)); swApp.CloseDoc(swModel.GetTitle()); } } catch (Exception e) { MessageBox.Show(e.Message, "addModelsFromFolder()", MessageBoxButtons.OK); return; } MessageBox.Show("Models were added!", "Search 3D Modelsz", MessageBoxButtons.OK); }
public static void InsertPart(SldWorks swApp, ModelDoc2 Doc, string newpartpath) { swApp.OpenDoc(newpartpath, 1); ((AssemblyDoc)Doc).AddComponent5(newpartpath, 0, "", false, "", 0, 0.3, 0); ((AssemblyDoc)Doc).AddComponent5(newpartpath, 0, "", true, "实心", 0.5, 0.3, 0); ((AssemblyDoc)Doc).AddComponent5(newpartpath, 0, "", true, "挖孔", 1, 0.3, 0); swApp.CloseDoc(newpartpath); }
public TabletModelInformation() { string hobNumber = ((ModelDoc2)sldWorks.ActiveDoc).GetType() == (int)swDocumentTypes_e.swDocPART ? ((ModelDoc2)sldWorks.ActiveDoc).GetTitle() : ((ModelDoc2)sldWorks.ActiveDoc).GetTitle().Remove(((ModelDoc2)sldWorks.ActiveDoc).GetTitle().IndexOf(' ')); HobNumber = hobNumber; string modelPath = GetTabletPath(hobNumber) + ".SLDPRT"; ModelDoc2 tablet = (ModelDoc2)sldWorks.OpenDoc(modelPath, (int)swDocumentTypes_e.swDocPART); if (tablet is null) { tablet = (ModelDoc2)sldWorks.ActivateDoc(hobNumber); } CustomPropertyManager cpmTablet = (CustomPropertyManager)tablet.Extension.CustomPropertyManager[""]; GetDieNumber(tablet, cpmTablet); GetSize(tablet); sldWorks.CloseDoc(HobNumber); }
public static List <KeyValuePair <string, string> > GetAll(SldWorks swApp, ModelDoc2 childDoc, string configuration) { swApp.ActivateDoc(childDoc.GetTitle()); var swCustProp = childDoc.Extension.CustomPropertyManager[configuration]; var list = new List <KeyValuePair <string, string> >(); foreach (var item in Properties) { list.Add(new KeyValuePair <string, string>(item.Key, GetProperty(swCustProp, item.Key))); } swApp.CloseDoc(Path.GetFileName(childDoc.GetPathName())); return(list); }
/// <summary> /// 模型打包 /// </summary> /// <param name="suffix">后缀</param> /// <param name="swApp">SW程序</param> /// <param name="modelPath">模型地址</param> /// <param name="itemPath">目标地址</param> /// <returns></returns> public static string PackAndGoFunc(string suffix, SldWorks swApp, string modelPath, string itemPath) { swApp.CommandInProgress = true; int warnings = 0; int errors = 0; ModelDoc2 swModelDoc = default(ModelDoc2); ModelDocExtension swModelDocExt = default(ModelDocExtension); PackAndGo swPackAndGo = default(PackAndGo); //打开需要pack的模型 swModelDoc = (ModelDoc2)swApp.OpenDoc6(modelPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); swModelDocExt = (ModelDocExtension)swModelDoc.Extension; swPackAndGo = (PackAndGo)swModelDocExt.GetPackAndGo(); // Get number of documents in assembly //namesCount = swPackAndGo.GetDocumentNamesCount(); //Debug.Print(" Number of model documents: " + namesCount); // Include any drawings, SOLIDWORKS Simulation results, and SOLIDWORKS Toolbox components swPackAndGo.IncludeDrawings = false; swPackAndGo.IncludeSimulationResults = false; swPackAndGo.IncludeToolboxComponents = false; // Set folder where to save the files,目标存放地址 swPackAndGo.SetSaveToName(true, itemPath); //将文件展开到一个文件夹内,不要原始模型的文件夹结构 // Flatten the Pack and Go folder structure; save all files to the root directory swPackAndGo.FlattenToSingleFolder = true; // Add a prefix and suffix to the filenames //swPackAndGo.AddPrefix = "SW_";添加后缀 swPackAndGo.AddSuffix = "_" + suffix; try { // Pack and Go,执行PackAndGo swModelDocExt.SavePackAndGo(swPackAndGo); } catch (Exception ex) { throw new Exception("PackandGo过程中出现异常:" + ex.Message); } finally { swApp.CloseDoc(swModelDoc.GetTitle()); swModelDoc = null; swApp.CommandInProgress = false;//及时关闭外部命令调用,否则影响SolidWorks的使用 } string modelPathName = modelPath.Substring(modelPath.LastIndexOf(@"\") + 1); //返回packandgo后模型的地址 return(itemPath + @"\" + modelPathName.Substring(0, modelPathName.LastIndexOf(".")) + "_" + suffix + ".sldasm"); }
//public static bool TemSaveAsFor(this ModelDoc2 doc,string NewFilePathName) //{ // int errors = 0, warnings = 0; // bool success = doc.Extension.SaveAs(NewFilePathName, swSaveAsVersion_e.swSaveAsCurrentVersion.EnumCastToInt(), // (swSaveAsOptions_e.swSaveAsOptions_Copy | swSaveAsOptions_e.swSaveAsOptions_Silent).EnumCastToInt(), // null, ref errors, ref warnings); // if (!success) // { // throw new Exception(nameof(TemSaveAsFor) + "-" + errors.CastObj<swFileSaveError_e>().ToString()); // } // return true; //} /// <summary> /// 另存为并加载到内存,然后关闭源文档 /// </summary> /// <param name="doc"></param> /// <param name="app"></param> /// <param name="NewFilePathName"></param> /// <returns></returns> public static ModelDoc2 TemSaveAsFor(this IModelDoc2 doc, SldWorks app, string NewFilePathName) { int errors = 0, warnings = 0; bool success = doc.Extension.SaveAs(NewFilePathName, swSaveAsVersion_e.swSaveAsCurrentVersion.SWToInt(), (swSaveAsOptions_e.swSaveAsOptions_Copy | swSaveAsOptions_e.swSaveAsOptions_Silent).SWToInt(), null, ref errors, ref warnings); if (!success) { throw new Exception(nameof(TemSaveAsFor) + "-" + errors.CastObj <swFileSaveError_e>().ToString()); } app.CloseDoc(doc.GetTitle()); return(app.OpenInvisibleDocClient(NewFilePathName)); }
public static void CloseDoc(SldWorks iswApp) { int err = -1; int warn = -1; iswApp.OpenDoc6(AppDomain.CurrentDomain.BaseDirectory + @"RectanglePlug\PlugTopBox.SLDPRT", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_AutoMissingConfig, "圆壳", ref err, ref warn); iswApp.OpenDoc6(AppDomain.CurrentDomain.BaseDirectory + @"RectanglePlug\PlugBottomBox.SLDPRT", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_AutoMissingConfig, "", ref err, ref warn); iswApp.OpenDoc6(AppDomain.CurrentDomain.BaseDirectory + @"RectanglePlug\PlugWire.SLDPRT", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_AutoMissingConfig, "", ref err, ref warn); MessageBox.Show("三个文档已打开,点击后,将关闭PlugTopBox.SLDPRT"); iswApp.CloseDoc(AppDomain.CurrentDomain.BaseDirectory + @"RectanglePlug\PlugTopBox.SLDPRT"); MessageBox.Show("关闭成功,再次点击将关闭所有文档"); iswApp.CloseAllDocuments(true); MessageBox.Show("所有文档已关闭"); }
public void CloseDoc() { if (this.FilePath != null) { try { this.swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); swApp.CloseDoc(this.FilePath); } catch { //如果不能获取SolidWorks进程,说明软件没有打开,说明文件也没有打开 } } }
public void transfer(String fileitem, String folderitem, String nameitem) { int longstatus = 0; ModelDoc2 swDoc = null; SldWorks swApp = new SldWorks(); swApp.Visible = false; swDoc = swApp.OpenDoc6(fileitem, 3, 0, "", 0, 0); ModelDoc2 swModel = swApp.ActiveDoc; //swDoc = swApp.ActiveDoc; //swDoc.GetActiveSketch(); //swDoc.GraphicsRedraw2(); longstatus = swModel.SaveAs3(folderitem + "\\" + nameitem + ".PDF", 0, 0); longstatus = swModel.SaveAs3(folderitem + "\\" + nameitem + ".DWG", 0, 0); swDoc.ClearSelection2(true); swDoc = null; swApp.CloseDoc(fileitem); }
public LinkedList <PageInfo> CreateDrawings(SldWorks _swApp, LinkedList <PageInfo> _ll) { int dt = (int)swDocumentTypes_e.swDocDRAWING; int err = 0; int warn = 0; int saveVersion = (int)swSaveAsVersion_e.swSaveAsCurrentVersion; int saveOptions = (int)swSaveAsOptions_e.swSaveAsOptions_Silent; bool success; var nd_ = _ll.First; while (nd_ != null) { if (nd_.Value.fileInfo != null) { FileInfo slddrw_ = nd_.Value.fileInfo; string newName = slddrw_.Name.Replace(@".SLDDRW", @".PDF"); FileInfo tmpFile = new FileInfo(string.Format(@"{0}\{1}", Path.GetTempPath(), newName)); FileSystemEventArgs fsea_ = new FileSystemEventArgs(WatcherChangeTypes.All, Path.GetDirectoryName(tmpFile.FullName), tmpFile.Name); OnOpening(fsea_); if (slddrw_.FullName.ToUpper().EndsWith(@"SLDDRW")) { _swApp.OpenDocSilent(slddrw_.FullName, dt, ref err); _swApp.ActivateDoc3(slddrw_.FullName, true, (int)swRebuildOnActivation_e.swDontRebuildActiveDoc, ref err); DrawingDoc dd_ = (DrawingDoc)_swApp.ActiveDoc; ModelDoc2 md_ = (ModelDoc2)_swApp.ActiveDoc; if (md_ != null) { success = md_.SaveAs4(tmpFile.FullName, saveVersion, saveOptions, ref err, ref warn); } nd_.Value.fileInfo = tmpFile; OnClosing(fsea_); _swApp.CloseDoc(slddrw_.FullName); } } nd_ = nd_.Next; } return(_ll); }
//не работает при открытом документе public byte[] ModelBytes(string path) { byte[] modelBytes = new byte[] { }; if (path != string.Empty) { modelDoc = swApp?.ActiveDoc; swApp.CloseDoc(path); using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, System.IO.FileShare.ReadWrite)) { using (var reader = new BinaryReader(stream)) { modelBytes = reader.ReadBytes((int)stream.Length); } } swApp.OpenDoc(path, 1); } return(modelBytes); }
private void insertCamera() { int loadErrs = 0; int loadWarns = 0; swApp.OpenDoc6(FOV_FILE, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref loadErrs, ref loadWarns); if (loadErrs > 0) { swApp.SendMsgToUser2("something went wrong, try again", (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxBtn_e.swMbOk); } swAssembly.AddComponent(FOV_FILE, 0, 0, 0); swApp.CloseDoc(FOV_FILE); swAssembly.ForceRebuild(); }
public static void AddMate(SldWorks swApp, ModelDoc2 Doc, string newpartpath) { #region 添加部件 swApp.OpenDoc(newpartpath, 1); ((AssemblyDoc)Doc).AddComponent5(newpartpath, 0, "", false, "", 0, 0.3, 0); swApp.CloseDoc(newpartpath); #endregion Component2 BaseComp = ((AssemblyDoc)Doc).GetComponentByName("底座-1"); Component2 RoateComp = ((AssemblyDoc)Doc).GetComponentByName("转轴-1"); int err = 0; #region 轴装配 Feature BaseAxi = BaseComp.FeatureByName("基准轴1"); Feature RoateAxi = RoateComp.FeatureByName("转轴中心轴"); BaseAxi.Select(false); RoateAxi.Select(true); ((AssemblyDoc)Doc).AddMate5((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out err); #endregion #region 底面装配距离 Feature BaseBp = BaseComp.FeatureByName("Top"); Feature RoateBp = RoateComp.FeatureByName("Top"); BaseBp.Select(false); RoateBp.Select(true); ((AssemblyDoc)Doc).AddMate5((int)swMateType_e.swMateDISTANCE, (int)swMateAlign_e.swMateAlignALIGNED, false, 10 / 1000.0, 10 / 1000.0, 10 / 1000.0, 0, 0, 0, 0, 0, false, false, 0, out err); #endregion #region 方位装配 Feature BaseOir = BaseComp.FeatureByName("Right"); Feature RoateOir = RoateComp.FeatureByName("Right"); BaseOir.Select(false); RoateOir.Select(true); ((AssemblyDoc)Doc).AddMate5((int)swMateType_e.swMateANGLE, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, (30 / 180.0) * Math.PI, (30 / 180.0) * Math.PI, (30 / 180.0) * Math.PI, false, false, 0, out err); #endregion Doc.EditRebuild3(); }
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的使用 } }
/// <summary> /// Метод построения детали /// </summary> public void BuildCandle(CandleParametrs objParametr) { /// <summary> /// Экземпляру присваиваем значение объекта класса /// </summary> _parametr = objParametr; /// <summary> /// Проверка построена ли деталь /// </summary> _parametr.ExistDetail = true; /// <summary> /// Путь до рабочего стола /// </summary> var pathName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory); /// <summary> /// Присваивание параметров /// </summary> var carvingLength = _parametr.CarvingLength; var nutLength = _parametr.NutLength; var nutSize = _parametr.NutSize; var isolatorLength = _parametr.IsolatorLength; var chamferRadius = _parametr.ChamferRadius; var plinthLength = _parametr.PlinthLength; var headLength = _parametr.HeadLength; var pitchSize = _parametr.PitchSize; var carvingRadius = _parametr.CarvingRadius; var textEtching = _parametr.TextEtching; var electrodeLength = _parametr.ElectrodeLength; /// <summary> /// Методы класса CandleCreator /// </summary> if (_parametr.ExistHead == true) { CandleCreator.CreateHead(headLength, SwApp, SwModel, _detailNames, pathName); } CandleCreator.CreatePlinth(plinthLength, SwApp, SwModel, _detailNames, textEtching, pathName); CandleCreator.CreateNut(nutLength, nutSize, SwApp, SwModel, _detailNames, chamferRadius, pathName); CandleCreator.CreateIsolator(isolatorLength, SwApp, SwModel, _detailNames, pathName); CandleCreator.CreateCarving(carvingLength, SwApp, SwModel, _detailNames, pitchSize, carvingRadius, electrodeLength, pathName); /// <summary> /// Создание сборки /// </summary> AssemblyDoc swAssembly = SwApp.NewAssembly(); SwModel = ((ModelDoc2)(SwApp.ActiveDoc)); if (_parametr.ExistHead == true) { swAssembly.AddComponent2(_detailNames[0], 0, 0, headLength / 2); swAssembly.AddComponent2(_detailNames[1], 0, 0, plinthLength / 2 + headLength); swAssembly.AddComponent2(_detailNames[2], 0, 0, nutLength / 2 + headLength + plinthLength); swAssembly.AddComponent(_detailNames[3], 0, 0, isolatorLength / 2 + headLength + plinthLength + nutLength); swAssembly.AddComponent(_detailNames[4], 0, 0, carvingLength / 2 + headLength + plinthLength + isolatorLength + nutLength); } else { swAssembly.AddComponent2(_detailNames[0], 0, 0, plinthLength / 2 + headLength); swAssembly.AddComponent2(_detailNames[1], 0, 0, nutLength / 2 + headLength + plinthLength); swAssembly.AddComponent(_detailNames[2], 0, 0, isolatorLength / 2 + headLength + plinthLength + nutLength); swAssembly.AddComponent(_detailNames[3], 0, 0, carvingLength / 2 + headLength + plinthLength + isolatorLength + nutLength); } /// <summary> /// Выбор вида "Изометрия" /// </summary> SwModel.Extension.SelectByID2("", "FACE", 0, 0, 0, true, 0, null, 0); swAssembly.AddMate((int)swMateType_e.swMateCONCENTRIC, (int)swMateAlign_e.swAlignAGAINST, false, 1, 0); SwModel.ShowNamedView("*Изометрия"); SwModel.ClearSelection(); SwModel.EditRebuild3(); /// <summary> /// Закрытие созданных документов /// </summary> SwApp.CloseDoc(_detailNames[0]); SwApp.CloseDoc(_detailNames[1]); SwApp.CloseDoc(_detailNames[2]); SwApp.CloseDoc(_detailNames[3]); if (_parametr.ExistHead == true) { SwApp.CloseDoc(_detailNames[4]); } /// <summary> /// Сохранение сборки /// </summary> string modelName = pathName + "Свеча.SLDASM"; SwModel.SaveAs(modelName); }
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的使用 } }
private const string ШаблонЧертежаРазверткиВнеХранилища = "flattpattern.drwdot";//@"C:\flattpattern.drwdot"; public void CreateFlattPatternUpdateCutlistAndEdrawing() { #region Сбор информации по детали и сохранение разверток //SldWorks swApp = null; try { var swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); swApp = new SldWorks { Visible = true }; IModelDoc2 swModel = swApp.IActiveDoc2; swModel.Extension.ViewDisplayRealView = false; if (!IsSheetMetalPart((IPartDoc)swModel)) { MessageBox.Show("Деталь не из листового материала"); } string[] swModelConfNames; var activeconfiguration = (Configuration)swModel.GetActiveConfiguration(); swModelConfNames = (string[])swModel.GetConfigurationNames(); var swModelConfNames2 = (string[])swModel.GetConfigurationNames(); try { foreach (var configName in from name in swModelConfNames2 let config = (Configuration)swModel.GetConfigurationByName(name) where !config.IsDerived() select name) { swModel.ShowConfiguration2(configName); swModel.EditRebuild3(); FileInfo template = null; try { template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища); //MessageBox.Show(template.FullName); Thread.Sleep(1000); } catch (Exception exception) { MessageBox.Show(exception.ToString()); template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища); Thread.Sleep(1000); } finally { if (template == null) { template = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\" + ШаблонЧертежаРазверткиВнеХранилища); } } //MessageBox.Show(template.FullName); var swDraw = (DrawingDoc)swApp.INewDocument2(template.FullName, (int)swDwgPaperSizes_e.swDwgPaperA0size, 0.841, 0.594); swDraw.CreateFlatPatternViewFromModelView3(swModel.GetPathName(), configName, 0.841 / 2, 0.594 / 2, 0, true, false); ((IModelDoc2)swDraw).ForceRebuild3(true); #region Разгибание всех сгибов try { swModel.EditRebuild3(); var swPart = (IPartDoc)swModel; Feature swFeature = swPart.FirstFeature(); const string strSearch = "FlatPattern"; while (swFeature != null) { var nameTypeFeature = swFeature.GetTypeName2(); if (nameTypeFeature == strSearch) { swFeature.Select(true); swPart.EditUnsuppress(); Feature swSubFeature = swFeature.GetFirstSubFeature(); while (swSubFeature != null) { var nameTypeSubFeature = swSubFeature.GetTypeName2(); if (nameTypeSubFeature == "UiBend") { swFeature.Select(true); swPart.EditUnsuppress(); swModel.EditRebuild3(); try { swSubFeature.SetSuppression2( (int)swFeatureSuppressionAction_e.swUnSuppressFeature, (int)swInConfigurationOpts_e.swAllConfiguration, swModelConfNames2); } catch (Exception){} } swSubFeature = swSubFeature.GetNextSubFeature(); } } swFeature = swFeature.GetNextFeature(); } swModel.EditRebuild3(); } catch (Exception exception) { MessageBox.Show(exception.Message); } #endregion swModel.ForceRebuild3(false); var thikness = GetFromCutlist(swModel, "Толщина листового металла"); var errors = 0; var warnings = 0; var newDxf = (IModelDoc2)swDraw; try { Directory.CreateDirectory("C:\\Dxf\\"); } catch (Exception){} newDxf.Extension.SaveAs( "C:\\Dxf\\" + Path.GetFileNameWithoutExtension(swModel.GetPathName()) + "-" + configName + "-" + thikness + ".dxf", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_UpdateInactiveViews, null, ref errors, ref warnings); swApp.CloseDoc(Path.GetFileName(newDxf.GetPathName())); } } catch (Exception exception) { MessageBox.Show(exception.ToString()); } try { swModel.ShowConfiguration2(activeconfiguration.Name); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } #endregion } catch (Exception exception) { MessageBox.Show(exception.ToString()); } }
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); } //查询参数 ABD200 item = (ABD200)objABD200Service.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---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHO0136-1")); swPart = swComp.GetModelDoc2();//打开零件3 swPart.Parameter("D1@Sketch1").SystemValue = (item.Length - 5m) / 1000m; if (item.Length == 400m || item.Length == 500m) { swFeat = swComp.FeatureByName("MIDDLE"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("300"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("MIDDLE"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("300"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHO0134-1")); swPart = swComp.GetModelDoc2();//打开零件3 swPart.Parameter("D12@Sketch1").SystemValue = (item.Length - 6m) / 1000m; if (item.Length == 400m || item.Length == 750m) { swPart.Parameter("D5@Sketch27").SystemValue = 28.5m / 1000m; } else { swPart.Parameter("D5@Sketch27").SystemValue = 78.5m / 1000m; } swFeat = swComp.FeatureByName("750"); if (item.Length == 750m) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHO0135-2")); swPart = swComp.GetModelDoc2();//打开零件3 swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length - 25m) / 1000m; if (item.Length == 400m || item.Length == 750m) { swPart.Parameter("D4@Sketch7").SystemValue = 17.5m / 1000m; } else { swPart.Parameter("D4@Sketch7").SystemValue = 67.5m / 1000m; } swFeat = swComp.FeatureByName("750"); if (item.Length == 750m) { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0006-1")); swPart = swComp.GetModelDoc2();//打开零件3 swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length + 50m) / 1000m; swFeat = swComp.FeatureByName("ABD"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 if (item.Length == 400m || item.Length == 500m) { swFeat = swComp.FeatureByName("ABD-MIDDLE"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ABD-300"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("ABD-MIDDLE"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ABD-300"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNHE0007-1")); swPart = swComp.GetModelDoc2();//打开零件3 swPart.Parameter("D2@Base-Flange1").SystemValue = (item.Length + 50m) / 1000m; swFeat = swComp.FeatureByName("ABD"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 if (item.Length == 400m || item.Length == 500m) { swFeat = swComp.FeatureByName("ABD-MIDDLE"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ABD-300"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("ABD-MIDDLE"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("ABD-300"); 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 Main() { swSuccess = false; errors = 0; warnings = 0; string swSourcePath = swApp.GetCurrentWorkingDirectory(); string swExportPath = Path.Combine(swSourcePath, "IGS"); string[] tmp = Directory.GetFiles(swSourcePath, "*.SLDPRT", SearchOption.TopDirectoryOnly); if (Directory.Exists(swExportPath)) { Directory.Delete(swExportPath, true); } Directory.CreateDirectory(swExportPath); ModelDoc2 swModel = swApp.ActiveDoc as ModelDoc2; AssemblyDoc swAssem = (AssemblyDoc)swModel; #region TopLevel string igsFileName = MakeFileName(swModel.Extension.Document.GetTitle()); swModel.Extension.SaveAs(Path.Combine(swExportPath, igsFileName), (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Copy, null, ref errors, ref warnings); //PrintSaveResults(); #endregion TopLevel #region Subassemblies string swExportSubPath = Path.Combine(swExportPath, "Subassemblies"); Directory.CreateDirectory(swExportSubPath); object[] objComps = (object[])swAssem.GetComponents(true); ModelDoc2 igsModel; foreach (object obj in objComps) { swComponent = obj as Component2; Debug.WriteLine(String.Format("Working on {0}.. \n\t {1}", swComponent.Name2, swComponent.GetPathName())); igsModel = swApp.OpenDoc6(swComponent.GetPathName(), (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_ReadOnly, null, ref errors, ref warnings); swApp.ActivateDoc2(igsModel.GetTitle(), true, ref errors); igsFileName = MakeFileName(igsModel.Extension.Document.GetTitle()); igsModel.Extension.SaveAs(Path.Combine(swExportSubPath, igsFileName), (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Copy, null, ref errors, ref warnings); swApp.CloseDoc(igsModel.GetTitle()); } #endregion Subassemblies #region Parts string swExportPartPath = Path.Combine(swExportPath, "Parts"); Directory.CreateDirectory(swExportPartPath); string[] swPartFiles = Directory.GetFiles(swSourcePath, "*.SLDPRT", SearchOption.TopDirectoryOnly); foreach (string partFile in swPartFiles) { try { igsModel = swApp.OpenDoc6(partFile, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_ReadOnly, null, ref errors, ref warnings); swApp.ActivateDoc2(igsModel.GetTitle(), true, ref errors); string[] swConfigs = (string[])igsModel.GetConfigurationNames(); int swConfigCount = igsModel.GetConfigurationCount(); string swConfigFilename; for (int i = 0; i < swConfigCount; i++) { igsModel.ShowConfiguration2(swConfigs[i]); swConfigFilename = igsModel.Extension.Document.GetTitle(); if (swConfigCount > 1) { swConfigFilename += String.Format("-CFG{0}", (i + 1).ToString()); } igsFileName = MakeFileName(swConfigFilename); igsModel.Extension.SaveAs(Path.Combine(swExportPartPath, igsFileName), (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Copy, null, ref errors, ref warnings); } swApp.CloseDoc(igsModel.GetTitle()); } catch (NullReferenceException e) { Debug.WriteLine(e.Message); } } #endregion Parts string timeFilename = Path.Combine(swExportPath, "Timestamp.txt"); using (StreamWriter swTimeStamper = new StreamWriter(timeFilename)) { swTimeStamper.WriteLine("Exported on {0} at {1}", System.DateTime.Now.ToShortDateString(), System.DateTime.Now.ToShortTimeString()); swTimeStamper.Flush(); } }
/// <summary> /// 出工程图 /// </summary> /// <param name="dicValues"></param> /// <param name="prtTemp"></param> /// <param name="compTemp"></param> /// <param name="bomPaths"></param> /// <param name="savePaths">保存路径</param> /// <param name="newPath">新路径</param> private void Drawing(List <string> dicValues, string prtTemp, string compTemp, string bomPaths, string savePaths, string newPath) { string viewType = string.Empty; bool isometric = false; bool bom = false; string dimesion = string.Empty; double spaceX = 0.06; //x方向留白区域 double scale = 1; //定义比例初始值 List <double[]> viewBox = new List <double[]>(); //集合存放视图box List <double[]> viewOrigin = new List <double[]>(); //集合存放视图原点值 double[] outLine = new double[4]; //视图box值 double[] postion = new double[2]; //视图原点值 _swApp = (SldWorks)ConnectSW.iSwApp; //连接sw if (_swApp == null) { return; } foreach (string item in dicValues) { int errors = 0; int warnings = 0; double view1X = 0; double view1Y = 0; string filePath = item; //文件路径 string fileEx = filePath.Substring(filePath.LastIndexOf("."), 7); //获得后缀名 string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1, filePath.LastIndexOf(".") - filePath.LastIndexOf("\\") - 1); if (fileEx == ".SLDPRT") { _swModelDoc = (ModelDoc2)_swApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); __swDrawDoc = (DrawingDoc)_swApp.NewDrawing2((int)swDwgTemplates_e.swDwgTemplateCustom, prtTemp, (int)swDwgPaperSizes_e.swDwgPapersUserDefined, 0, 0); } if (fileEx == ".SLDASM") { _swModelDoc = (ModelDoc2)_swApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); __swDrawDoc = (DrawingDoc)_swApp.NewDrawing2((int)swDwgTemplates_e.swDwgTemplateCustom, compTemp, (int)swDwgPaperSizes_e.swDwgPapersUserDefined, 0, 0); } _swModelEx = (ModelDocExtension)_swModelDoc.Extension; if (newPath != null) { savePaths = newPath.Substring(0, newPath.LastIndexOf("\\")); } //新建工程图 _swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swAutomaticScaling3ViewDrawings, true); //自动缩放新工程图比例 if (standarView == false && isometric) //如果只生成等轴测视图 { CreatIsometric(__swDrawDoc, filePath); _currentSheet = (Sheet)__swDrawDoc.GetCurrentSheet(); __swDrawDoc.ActivateSheet(_currentSheet.GetName()); _swView = __swDrawDoc.GetFirstView(); _swView = _swView.GetNextView(); ChangeViewShow(tag, _swView); _swApp.CloseDoc(_swModelDoc.GetTitle());// ModelDoc2 tempDoc = (ModelDoc2)__swDrawDoc; bool ss0 = false; if (newPath != null && IfDwg) { ss0 = tempDoc.Extension.SaveAs(newPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings); } else if (newPath != null && IfDwg == false) { ss0 = tempDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()).Substring(0, (_swModelDoc.GetTitle()).LastIndexOf(".")) + ".DWG", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings); } else if (newPath == null && IfDwg) { ss0 = tempDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()).Substring(0, (_swModelDoc.GetTitle()).LastIndexOf(".")) + ".DWG", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings); } else { ss0 = tempDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()).Substring(0, (_swModelDoc.GetTitle()).LastIndexOf(".")) + ".slddrw", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings); } bool isHidden = tempDoc.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swViewDisplayHideAllTypes, true); //隐藏所有类型 _swApp.CloseDoc(tempDoc.GetTitle()); _numSucess += 1; //转换成功的数量 sucessFile.Add(filePath); return; } bool isCreate = false; #region 第三视角投影 if (thirProject) { isCreate = __swDrawDoc.Create3rdAngleViews2(filePath);//创建第三视角投影视图(视图位置有差别) //调整视图位置 _swView = __swDrawDoc.GetFirstView(); while (_swView != null) { double[] vBox = new double[] { }; double[] vPoint = new double[] { }; vBox = (double[])_swView.GetOutline(); vPoint = (double[])_swView.Position; viewBox.Add(vBox); viewOrigin.Add(vPoint); _swView = _swView.GetNextView(); } //调整视图1、2位置 if (viewBox[0][3] > viewBox[0][2])//纵向 { double[] posView1 = new double[] { viewBox[0][2] / 3.0, viewOrigin[1][1] }; _swView = __swDrawDoc.GetFirstView(); _swView = _swView.GetNextView(); _swView.Position = posView1; double[] posView2 = new double[] { viewOrigin[2][0], viewOrigin[2][1] - (viewBox[2][1] - viewBox[1][3]) / 1.9 };//调整视图2位置 _swView = _swView.GetNextView(); _swView.Position = posView2; } else { double[] posView1 = new double[] { viewBox[0][2] / 4.0, viewOrigin[1][1] }; _swView = __swDrawDoc.GetFirstView(); _swView = _swView.GetNextView(); _swView.Position = posView1; double[] posView2 = new double[] { viewOrigin[2][0], viewOrigin[2][1] - (viewBox[2][1] - viewBox[1][3]) / 2.0 };//调整视图2位置 _swView = _swView.GetNextView(); _swView.Position = posView2; } viewOrigin.Clear(); viewBox.Clear(); _swView = __swDrawDoc.GetFirstView(); while (_swView != null) { double[] vBox = new double[] { }; double[] vPoint = new double[] { }; vBox = (double[])_swView.GetOutline(); vPoint = (double[])_swView.Position; viewBox.Add(vBox); viewOrigin.Add(vPoint); _swView = _swView.GetNextView(); } if (isometric)//等轴测 { _swView = (IView)__swDrawDoc.CreateDrawViewFromModelView3(filePath, "*等轴测", viewOrigin[3][0], viewOrigin[2][1], 0); _swView = __swDrawDoc.GetFirstView(); double[] sca = new double[2]; sca = _swView.ScaleRatio;//获取比例 _swView = _swView.GetNextView(); _swView = _swView.GetNextView(); _swView = _swView.GetNextView(); _swView = _swView.GetNextView(); _swView.ScaleRatio = sca; double[] rePos = new double[] { viewOrigin[3][0] + 0.015, viewOrigin[2][1] }; _swView.Position = rePos; ChangeViewShow(tag, _swView); //视图样式 AddDimension(dimesion, __swDrawDoc, _swModelDoc); //尺寸标注 } } #endregion #region 第一视角投影 else { isCreate = __swDrawDoc.Create1stAngleViews(filePath);//创建第一视角投影视图 //获取视图boundingbox _swView = __swDrawDoc.GetFirstView(); while ((_swView != null)) { outLine = (double[])_swView.GetOutline(); //(x,y坐标最值) postion = (double[])_swView.Position; //视图位置值 viewBox.Add(outLine); viewOrigin.Add(postion); _swView = _swView.GetNextView(); } double newScale = CalcuScale(viewBox, __swDrawDoc, scale, spaceX, 3); //调整视图位置(position) if (viewBox[0][3] > viewBox[0][2]) { view1X = viewBox[0][2] / 2.8; //视图1的X坐标放在图纸坐标的三分之一处 view1Y = viewBox[0][3] - viewBox[0][3] / 4.85; //视图1的Y坐标放在图纸坐标的五分之一处 } else { view1X = viewBox[0][2] / 3.5; //视图1的X坐标放在图纸坐标的三分之一处 view1Y = viewBox[0][3] - viewBox[0][3] / 4.0; //视图1的Y坐标放在图纸坐标的四分之一处 } double[] view1Pos = new double[] { view1X, view1Y }; _swView = __swDrawDoc.GetFirstView(); //获取图纸 _swView = _swView.GetNextView(); //获取第一个视图 _swView.Position = view1Pos; bool isRebuild = _swModelDoc.EditRebuild3(); //viewBox.Clear(); List <double[]> tempBox = new List <double[]>(); viewOrigin.Clear(); while ((_swView != null)) { ChangeViewShow(tag, _swView); //改变视图显示样式 AddDimension(dimesion, __swDrawDoc, _swModelDoc); //添加尺寸 outLine = (double[])_swView.GetOutline(); //(x,y坐标最值) postion = (double[])_swView.Position; //视图位置值 tempBox.Add(outLine); viewOrigin.Add(postion); _swView = _swView.GetNextView(); } if (isometric) //是否创建等轴测视图(非钣金) { double[] scalArry = new double[2]; _swView = (IView)__swDrawDoc.CreateDrawViewFromModelView3(filePath, "*等轴测", viewOrigin[2][0], viewOrigin[1][1], 0); _swView = __swDrawDoc.GetFirstView(); //获取图纸 _swView = _swView.GetNextView(); //获取第一个视图 double sca = _swView.get_IScaleRatio(); if (sca == 1) //缩小比例 { scalArry[0] = 1; scalArry[1] = newScale; } else { scalArry[0] = sca; scalArry[1] = 1; } _swView = _swView.GetNextView(); _swView = _swView.GetNextView(); _swView = _swView.GetNextView(); _swView.ScaleRatio = scalArry;//调整轴测图比例 ChangeViewShow(tag, _swView); _swModelDoc.EditRebuild3(); } ////关掉文件(不保存) //_swApp.CloseDoc(_swModelDoc.GetTitle()); if (fileEx == ".SLDASM" && bom) //是否创建明细表 { //viewBox.Clear(); //viewOrigin.Clear(); double[] outArry = new double[4]; double[] posArry = new double[2]; double[] posArry1 = null; double[] posArry2 = null; double[] posArry3 = null; _currentSheet = (Sheet)__swDrawDoc.GetCurrentSheet(); __swDrawDoc.ActivateSheet(_currentSheet.GetName()); _swView = __swDrawDoc.GetFirstView(); //获取图纸 _swView = _swView.GetNextView(); //获取第一个视图 swBomTableAnno = (BomTableAnnotation)_swView.InsertBomTable4(true, 0.4, 0.1, (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomRight, (int)swBomType_e.swBomType_TopLevelOnly, "", bomPaths, false, 0, false); TableAnnotation tableAnnotation = (TableAnnotation)swBomTableAnno; tableAnnotation.GetAnnotation(); BomFeature bomFeature = swBomTableAnno.BomFeature; bool[] array = new bool[bomFeature.GetConfigurationCount(false)]; object Visible = array; object configurations = bomFeature.GetConfigurations(false, ref Visible); array[0] = true; bomFeature.SetConfigurations(true, array, configurations); FeatureManager featureManager = _swModelDoc.FeatureManager; featureManager.UpdateFeatureTree(); double num = 0.007; tableAnnotation.SetRowHeight(-2, num, 0); double totleHeight = num * tableAnnotation.RowCount; //计算总的tableBom高度 double heightSum = totleHeight + 0.070; //加上标题栏总高度 int columCount = tableAnnotation.ColumnCount; //获取总的列数 double columWidth = 0; for (int i = 0; i < columCount; i++) { double wid = tableAnnotation.GetColumnWidth(i); columWidth += wid; } _swView = _swView.GetNextView(); _swView = _swView.GetNextView(); outArry = (double[])_swView.GetOutline(); if (outArry[1] < heightSum)//有可能被遮挡 { //__swView = _swDrawDoc.GetFirstView(); //double[] tempArry = new double[] { }; //tempArry=(double[])__swView.GetOutline(); //viewBox.Insert(0, tempArry); scale = ((viewBox[1][2] - viewBox[1][0]) + (viewBox[3][2] - viewBox[3][0])) / (viewBox[0][2] - columWidth - 0.025);//计算X方向的比例 if (scale > 11) { double scaleCeil = System.Math.Ceiling(scale); if (scaleCeil > 11 && scaleCeil < 16) { scale = 20; } if (scaleCeil > 15 && scaleCeil < 21) { scale = 25; } if (scaleCeil > 20 && scaleCeil < 26) { scale = 30; } if (scaleCeil > 25 && scaleCeil < 34) { scale = 40; } if (scaleCeil > 33 && scaleCeil < 45) { scale = 50; } if (scaleCeil > 44 && scaleCeil < 55) { scale = 60; } } else if (scale > 5.8 && scale < 10.5) { double scaleCeil = System.Math.Ceiling(scale); //scale = scaleCeil + 4.0; //比例为10、11、12、13、14、15 if (scaleCeil > 5 && scaleCeil < 8) { scale = 10; } if (scaleCeil > 7 && scaleCeil < 12) { scale = 15; } } _currentSheet = (Sheet)__swDrawDoc.GetCurrentSheet(); __swDrawDoc.ActivateSheet(_currentSheet.GetName()); bool isScale = _currentSheet.SetScale(1, scale, false, false); //设置视图和图纸比例 _swView = __swDrawDoc.GetFirstView(); _swView = _swView.GetNextView(); //获取视图1 double[] pos1 = new double[2]; pos1 = _swView.Position; posArry1 = new double[] { pos1[0] - columWidth / 3.45, pos1[1] }; _swView.Position = posArry1; //重置视图1的位置 _swView = _swView.GetNextView(); //获取视图2 double[] pos2 = new double[2]; pos2 = _swView.Position; posArry2 = new double[] { pos2[0] - columWidth / 3.45, pos2[1] + 0.0015 }; _swView.Position = posArry2; //设置视图2位置 _swView = _swView.GetNextView(); //获取视图三 posArry = (double[])_swView.Position; posArry3 = new double[] { posArry[0] - columWidth / 3.5, posArry[1] }; _swView.Position = posArry3;//视图3坐标 } } }//第一视角投影 #endregion if (isCreate) { _numSucess += 1;//转换成功的数量 sucessFile.Add(filePath); } ModelDoc2 tempModelDoc = (ModelDoc2)__swDrawDoc; //获取到swDraw的父级(ModelDoc) _swApp.CloseDoc(_swModelDoc.GetTitle()); bool isHiden = tempModelDoc.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swViewDisplayHideAllTypes, true); //隐藏所有类型 _swModelDoc.ForceRebuild3(false); string saveName = (_swModelDoc.GetTitle()).Substring(0, (_swModelDoc.GetTitle()).LastIndexOf(".")); bool ss; if (newPath != null && IfDwg) { ss = tempModelDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()) + ".DWG", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings); } else if (newPath != null && IfDwg == false) { ss = tempModelDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()) + ".slddrw", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings); } else if (newPath == null && IfDwg) { ss = tempModelDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()) + ".DWG", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings); } else { ss = tempModelDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()) + ".slddrw", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings); } _swApp.CloseDoc(tempModelDoc.GetTitle());//关闭转换完成的文件 } }
//public static IEdmObject5 GetObject(IEdmVault12 vault, int objectId, EdmObjectType objectType) //{ // try // { // var obj = vault.GetObject(objectType, objectId); // return obj; // } // catch (Exception e) // { // Console.WriteLine("Ошибка в процедуре public static IEdmObject5 GetObject {0}:", e); // } // foreach (EdmObjectType enumObjectType in Enum.GetValues(typeof(EdmObjectType))) // { // try // { // var obj = vault.GetObject(enumObjectType, objectId); // return obj; // } // catch (Exception e) // { // Console.WriteLine("Ошибка в процедуре public static IEdmObject5 GetObject {0}:", e); // } // } // //nothing found // return null; //} static void CreateFlattPatternUpdateCutlist(string filePath, bool savedxf) { //var vault1 = new EdmVault5(); //IEdmFolder5 oFolder; //vault1.LoginAuto("Vents-PDM", 0); //var edmFile5 = vault1.GetFileFromPath("D:\\Vents-PDM\\Библиотека проектирования\\Templates\\flattpattern.drwdot", out oFolder); //edmFile5.GetFileCopy(0, 0, oFolder.ID, (int)EdmGetFlag.EdmGet_Simple); try { SwApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); } catch (Exception) { SwApp = new SldWorks { Visible = true }; } if (SwApp == null) { return; } var swModel = SwApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0); SwApp.SetUserPreferenceStringValue(((int)(swUserPreferenceStringValue_e.swFileLocationsDocumentTemplates)), "D:\\Vents-PDM\\Библиотека проектирования\\Templates\\"); try { if (!IsSheetMetalPart((IPartDoc)swModel)) { SwApp.CloseDoc(swModel.GetTitle()); return; } } catch (Exception) { return; } var activeconfiguration = (Configuration)swModel.GetActiveConfiguration(); var swModelConfNames = (string[])swModel.GetConfigurationNames(); foreach (var name in from name in swModelConfNames let config = (Configuration)swModel.GetConfigurationByName(name) where config.IsDerived() select name) { swModel.DeleteConfiguration(name); } var swModelDocExt = swModel.Extension; var swModelConfNames2 = (string[])swModel.GetConfigurationNames(); // Проход по всем родительским конфигурациям (т.е. - конфигурациям деталей) var dataList = new List<DataToExport>(); foreach (var configName in from name in swModelConfNames2 let config = (Configuration)swModel.GetConfigurationByName(name) where !config.IsDerived() select name) { swModel.ShowConfiguration2(configName); swModel.EditRebuild3(); var confiData = new DataToExport { Config = configName }; var swDraw = (DrawingDoc)SwApp.NewDrawing2((int)swDwgTemplates_e.swDwgTemplateA0size, "D:\\Vents-PDM\\Библиотека проектирования\\Templates\\flattpattern.drwdot",// "D:\\Vents-PDM\\Библиотека проектирования\\Templates\\flattpattern.drwdot", (int)swDwgPaperSizes_e.swDwgPaperA0size, 0.841, 0.594); swDraw.CreateFlatPatternViewFromModelView3(swModel.GetPathName(), configName, 0.841 / 2, 0.594 / 2, 0, true, true); swModel.ForceRebuild3(false); var swCustProp = swModelDocExt.CustomPropertyManager[configName]; string valOut; string codMaterial; swCustProp.Get4("Код материала", true, out valOut, out codMaterial); confiData.КодМатериала = codMaterial; string материал; swCustProp.Get4("Материал", true, out valOut, out материал); confiData.Материал = материал; string обозначение; swCustProp.Get4("Обозначение", true, out valOut, out обозначение); confiData.Обозначение = обозначение; var swCustPropForDescription = swModelDocExt.CustomPropertyManager[""]; string наименование; swCustPropForDescription.Get4("Наименование", true, out valOut, out наименование); confiData.Наименование = наименование; if (savedxf) { var newDxf = (IModelDoc2)swDraw; SwApp.CloseDoc(newDxf.GetPathName()); } else { var newDxf = (IModelDoc2)swDraw; SwApp.CloseDoc(newDxf.GetTitle()); } //UpdateCustomPropertyListFromCutList const string длинаГраничнойРамкиName = "Длина граничной рамки"; const string ширинаГраничнойРамкиName = "Ширина граничной рамки"; const string толщинаЛистовогоМеталлаNAme = "Толщина листового металла"; const string сгибыName = "Сгибы"; const string площадьПокрытияName = "Площадь покрытия"; Feature swFeat2 = swModel.FirstFeature(); while (swFeat2 != null) { if (swFeat2.GetTypeName2() == "SolidBodyFolder") { BodyFolder swBodyFolder = swFeat2.GetSpecificFeature2(); swFeat2.Select2(false, -1); swBodyFolder.SetAutomaticCutList(true); swBodyFolder.UpdateCutList(); Feature swSubFeat = swFeat2.GetFirstSubFeature(); while (swSubFeat != null) { if (swSubFeat.GetTypeName2() == "CutListFolder") { BodyFolder bodyFolder = swSubFeat.GetSpecificFeature2(); swSubFeat.Select2(false, -1); bodyFolder.SetAutomaticCutList(true); bodyFolder.UpdateCutList(); var swCustPrpMgr = swSubFeat.CustomPropertyManager; swCustPrpMgr.Add("Площадь поверхности", "Текст", "\"SW-SurfaceArea@@@Элемент списка вырезов1@" + Path.GetFileName(swModel.GetPathName())+"\""); string длинаГраничнойРамки; swCustPrpMgr.Get4(длинаГраничнойРамкиName, true, out valOut, out длинаГраничнойРамки); swCustProp.Set(длинаГраничнойРамкиName, длинаГраничнойРамки); confiData.ДлинаГраничнойРамки = длинаГраничнойРамки; string ширинаГраничнойРамки; swCustPrpMgr.Get4(ширинаГраничнойРамкиName, true, out valOut, out ширинаГраничнойРамки); swCustProp.Set(ширинаГраничнойРамкиName, ширинаГраничнойРамки); confiData.ШиринаГраничнойРамки = ширинаГраничнойРамки; string толщинаЛистовогоМеталла; swCustPrpMgr.Get4(толщинаЛистовогоМеталлаNAme, true, out valOut, out толщинаЛистовогоМеталла); swCustProp.Set(толщинаЛистовогоМеталлаNAme, толщинаЛистовогоМеталла); confiData.ТолщинаЛистовогоМеталла = толщинаЛистовогоМеталла; string сгибы; swCustPrpMgr.Get4(сгибыName, true, out valOut, out сгибы); swCustProp.Set(сгибыName, сгибы); confiData.Сгибы = сгибы; string площадьПоверхности; swCustPrpMgr.Get4("Площадь поверхности", true, out valOut, out площадьПоверхности); swCustProp.Set(площадьПокрытияName, площадьПоверхности); confiData.ПлощадьПокрытия = площадьПоверхности; } swSubFeat = swSubFeat.GetNextFeature(); } } swFeat2 = swFeat2.GetNextFeature(); } dataList.Add(confiData); } swModel.ShowConfiguration2(activeconfiguration.Name); //GetXml(swModel); ExportDataToXmlSql(swModel, dataList); SwApp.CloseDoc(swModel.GetTitle()); }
public void CeilingAssyToPackingList(SldWorks swApp, string assyPath, Project objProject, int userId) { swApp.CommandInProgress = true; List <CeilingAccessory> celingAccessories = new List <CeilingAccessory>(); try { //打开模型 ModelDoc2 swModel = swApp.OpenDoc6(assyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; if (swModel == null) { MessageBox.Show("模型不存在,请认真检查", "模型不存在"); return; } swModel.ForceRebuild3(true); AssemblyDoc swAssy = swModel as AssemblyDoc; //获取所有零部件集合 var compList = swAssy.GetComponents(false); //遍历集合中的所有零部件对象 foreach (var swComp in compList) { //判断零件是否被压缩,不显示,封套,零件名称不是以sldprt或SLDPRT结尾,(导出发货清单无需判断可见,封套,无需判断钣金,只要没有被压缩就行了) if (!swComp.IsSuppressed() && (swComp.GetPathName().EndsWith(".sldprt") || swComp.GetPathName().EndsWith(".SLDPRT"))) { Component2 swParentComp = swComp.GetParent(); //总装没有父装配体 if (swParentComp == null) { ConfigurationManager swConfigMgr = swModel.ConfigurationManager; Configuration swConfig2 = swConfigMgr.ActiveConfiguration; swParentComp = swConfig2.GetRootComponent3(true); } //判断父装配体是否可视,并且不封套(导出发货清单无需判断可见,封套,无需判断钣金,只要没有被压缩就行了) if (swParentComp.Visible == 1 && !swComp.IsSuppressed()) { //过滤需要的零件,全部转换成大写 if (swComp.GetPathName().Contains("[")) { //截取关键字 string keyWord = swComp.GetPathName(); if (keyWord.Contains(")")) { keyWord = keyWord.Substring(0, keyWord.IndexOf(")") + 1); keyWord = keyWord.Substring(keyWord.IndexOf("[")).ToUpper(); } else if (keyWord.Contains("}")) { keyWord = keyWord.Substring(0, keyWord.IndexOf("}") + 1); keyWord = keyWord.Substring(keyWord.IndexOf("[")).ToUpper(); } else { keyWord = keyWord.Substring(0, keyWord.IndexOf("]") + 1); keyWord = keyWord.Substring(keyWord.IndexOf("[")).ToUpper(); } if (sheetMetaDic.ContainsKey(keyWord)) { sheetMetaDic[keyWord] += 1; } else { sheetMetaDic.Add(keyWord, 1); } } } } } //关闭装配体零件 //swApp.CloseDoc(assyPath); foreach (var item in sheetMetaDic) { //获取关键字,查找对象 string partNo = ""; string length = ""; string width = ""; if (item.Key.Contains("-")) { partNo = item.Key.Substring(1, item.Key.IndexOf("-") - 1); } else { partNo = item.Key.Substring(1, item.Key.IndexOf("]") - 1); } CeilingAccessory objCeilingAccessory = objCeilingAccessoryService.GetCeilingAccessoryByPartNo(partNo); if (objCeilingAccessory == null) { continue; } //给对象赋值 objCeilingAccessory.PartNo = item.Key.Substring(1, item.Key.IndexOf("]") - 1); objCeilingAccessory.Quantity = item.Value; objCeilingAccessory.ProjectId = objProject.ProjectId; objCeilingAccessory.UserId = userId; objCeilingAccessory.Location = objDrawingPlanService.GetDrawingPlanByProjectId(objProject.ProjectId.ToString())[0].Item; if (item.Key.Contains(")")) { width = item.Key.Substring(0, item.Key.IndexOf(")")); width = width.Substring(width.IndexOf("(") + 1); objCeilingAccessory.Width = width; } if (item.Key.Contains("}")) { length = item.Key.Substring(0, item.Key.IndexOf("}")); length = length.Substring(length.IndexOf("{") + 1); objCeilingAccessory.Length = length; } //添加list ceilingAccessories.Add(objCeilingAccessory); } } catch (Exception ex) { throw new Exception(assyPath + "装配体导出发货清单过程发生异常,详细:" + ex.Message); } finally { sheetMetaDic.Clear(); swApp.CloseDoc(assyPath); //关闭,很快 swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } //基于事务ceilingCutLists提交SQLServer if (ceilingAccessories.Count == 0) { return; } try { if (objCeilingAccessoryService.ImportCeilingPackingListByTran(ceilingAccessories)) { ceilingAccessories.Clear(); } } catch (Exception ex) { throw new Exception("Cutlist导入数据库失败" + ex.Message); } }
public void OpenDoc(int idPdm, int revision, int taskType, string filePath, string fileName) { swApp = new SldWorks() {Visible = true}; Process[] processes = Process.GetProcessesByName("SLDWORKS"); var errors = 0; var warnings = 0; #region Case switch (taskType) { case 1: Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.Black)); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += (String.Format("Выполняется: {0}\r\n", filePath)))); swModel = swApp.OpenDoc6(filePath, (int) swDocumentTypes_e.swDocPART, (int) swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); swModel = swApp.ActiveDoc; if (!IsSheetMetalPart((IPartDoc) swModel)) { Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.DarkBlue)); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("Не листовой металл!\r\n"))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("--------------------------------------------------------------------------------------------------------------\r\n"))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("\r\n"))); swApp.CloseDoc(filePath); swApp.ExitApp(); swApp = null; foreach (Process process in processes) { process.CloseMainWindow(); process.Kill(); } return; } swExtension = (ModelDocExtension) swModel.Extension; swModel.EditRebuild3(); swModel.ForceRebuild3(false); CreateFlattPatternUpdate(); object[] confArray = swModel.GetConfigurationNames(); foreach (var confName in confArray) { Configuration swConf = swModel.GetConfigurationByName(confName.ToString()); if (swConf.IsDerived()) continue; Area(confName.ToString()); GabaritsForPaintingCamera(confName.ToString()); } ExportDataToXmlSql(fileName, idPdm, revision); ConvertToErpt(filePath); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.Black)); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += (String.Format("{0} - Выполнен!\r\n", filePath)))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("-----------------------------------------------------------------\r\n"))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("\r\n"))); break; case 2: swModel = swApp.OpenDoc6(filePath, (int) swDocumentTypes_e.swDocDRAWING, (int) swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); //if (warnings == (int)swFileLoadWarning_e.swFileLoadWarning_ReadOnly) //{MessageBox.Show("This file is read-only.");} swDraw = (DrawingDoc) swModel; swExtension = (ModelDocExtension) swModel.Extension; ConvertToPdf(filePath); break; case 3: //swModel = swApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); MessageBox.Show("3"); break; } //TODO: swApp exit swApp.CloseDoc(filePath); swApp.ExitApp(); swApp = null; foreach (Process process in processes) { process.CloseMainWindow(); process.Kill(); } #endregion }
/// <summary> /// Reubilds all docs. /// </summary> public void ReubildAllOpenedDocs() { try { _swApp = (SldWorks) Marshal.GetActiveObject("SldWorks.Application"); if (_swApp == null) return; var docs = _swApp.GetDocuments(); foreach (ModelDoc2 doc in docs) { doc.EditRebuild3(); doc.ForceRebuild3(false); doc.Save(); _swApp.CloseDoc(doc.GetTitle()); } } catch (Exception e) { MessageBox.Show(e.Message); } }
public static void GetCurrentConfigPartData(SldWorks swApp, int lastVer, int idPdm, bool closeDoc, bool fixBends, out List <DataToExport> dataList, out Exception exception) //public static void GetCurrentConfigPartData(SldWorks swApp, bool closeDoc, bool fixBends, out List<DataToExport> dataList, out Exception exception) { // Проход по всем родительским конфигурациям exception = null; dataList = new List <DataToExport>(); var swModel = swApp.IActiveDoc2; if (swModel == null) { return; } var configName = ((Configuration)swModel.GetActiveConfiguration()).Name; swModel.ShowConfiguration2(configName); swModel.EditRebuild3(); var swModelDocExt = swModel.Extension; var fileName = swModel.GetTitle().ToUpper().Replace(".SLDPRT", ""); AddDimentions(swModel, configName, out exception); var confiData = new DataToExport { Config = configName, FileName = fileName, IdPdm = idPdm, Version = lastVer }; #region азгибание всех сгибов fixBends = true; if (fixBends) { swModel.EditRebuild3(); List <PartBendInfo> list; Bends.Fix(swApp, out list, false); } #endregion swModel.ForceRebuild3(false); var swCustProp = swModelDocExt.CustomPropertyManager[configName]; string valOut; string materialId; // TO DO LOOK swCustProp.Get4("MaterialID", true, out valOut, out materialId); if (string.IsNullOrEmpty(materialId)) { confiData.MaterialId = null; } else { confiData.MaterialId = int.Parse(materialId); } string paintX; swCustProp.Get4("Длина", true, out valOut, out paintX); if (string.IsNullOrEmpty(paintX)) { confiData.PaintX = null; } else { confiData.PaintX = double.Parse(paintX); } string paintY; swCustProp.Get4("Ширина", true, out valOut, out paintY); if (string.IsNullOrEmpty(paintY)) { confiData.PaintY = null; } else { confiData.PaintY = double.Parse(paintY); } string paintZ; swCustProp.Get4("Высота", true, out valOut, out paintZ); if (string.IsNullOrEmpty(paintZ)) { confiData.PaintZ = null; } else { confiData.PaintZ = double.Parse(paintZ); } string codMaterial; swCustProp.Get4("Код материала", true, out valOut, out codMaterial); confiData.КодМатериала = codMaterial; string материал; swCustProp.Get4("Материал", true, out valOut, out материал); confiData.Материал = материал; string обозначение; swCustProp.Get4("Обозначение", true, out valOut, out обозначение); confiData.Обозначение = обозначение; var swCustPropForDescription = swModelDocExt.CustomPropertyManager[""]; string наименование; swCustPropForDescription.Get4("Наименование", true, out valOut, out наименование); confiData.Наименование = наименование; //UpdateCustomPropertyListFromCutList const string длинаГраничнойРамкиName = @"Длина граничной рамки"; const string длинаГраничнойРамкиName2 = @"Bounding Box Length"; const string ширинаГраничнойРамкиName = @"Ширина граничной рамки"; const string ширинаГраничнойРамкиName2 = @"Bounding Box Width"; const string толщинаЛистовогоМеталлаNAme = @"Толщина листового металла"; const string толщинаЛистовогоМеталлаNAme2 = @"Sheet Metal Thickness"; const string сгибыName = @"Сгибы"; const string сгибыName2 = @"Bends"; const string площадьПокрытияName = @"Площадь покрытия";//const string площадьПокрытияName2 = @"Bounding Box Area"; Feature swFeat2 = swModel.FirstFeature(); while (swFeat2 != null) { if (swFeat2.GetTypeName2() == "SolidBodyFolder") { BodyFolder swBodyFolder = swFeat2.GetSpecificFeature2(); swFeat2.Select2(false, -1); swBodyFolder.SetAutomaticCutList(true); swBodyFolder.UpdateCutList(); Feature swSubFeat = swFeat2.GetFirstSubFeature(); while (swSubFeat != null) { if (swSubFeat.GetTypeName2() == "CutListFolder") { BodyFolder bodyFolder = swSubFeat.GetSpecificFeature2(); if (bodyFolder.GetCutListType() != (int)swCutListType_e.swSheetmetalCutlist) { goto m1; } swSubFeat.Select2(false, -1); bodyFolder.SetAutomaticCutList(true); bodyFolder.UpdateCutList(); var swCustPrpMgr = swSubFeat.CustomPropertyManager; swCustPrpMgr.Add("Площадь поверхности", "Текст", "\"SW-SurfaceArea@@@Элемент списка вырезов1@" + Path.GetFileName(swModel.GetPathName()) + "\""); string длинаГраничнойРамки; swCustPrpMgr.Get4(длинаГраничнойРамкиName, true, out valOut, out длинаГраничнойРамки); if (string.IsNullOrEmpty(длинаГраничнойРамки)) { swCustPrpMgr.Get4(длинаГраничнойРамкиName2, true, out valOut, out длинаГраничнойРамки); } swCustProp.Set(длинаГраничнойРамкиName, длинаГраничнойРамки); confiData.ДлинаГраничнойРамки = длинаГраничнойРамки; string ширинаГраничнойРамки; swCustPrpMgr.Get4(ширинаГраничнойРамкиName, true, out valOut, out ширинаГраничнойРамки); if (string.IsNullOrEmpty(ширинаГраничнойРамки)) { swCustPrpMgr.Get4(ширинаГраничнойРамкиName2, true, out valOut, out ширинаГраничнойРамки); } swCustProp.Set(ширинаГраничнойРамкиName, ширинаГраничнойРамки); confiData.ШиринаГраничнойРамки = ширинаГраничнойРамки; string толщинаЛистовогоМеталла; swCustPrpMgr.Get4(толщинаЛистовогоМеталлаNAme, true, out valOut, out толщинаЛистовогоМеталла); if (string.IsNullOrEmpty(толщинаЛистовогоМеталла)) { swCustPrpMgr.Get4(толщинаЛистовогоМеталлаNAme2, true, out valOut, out толщинаЛистовогоМеталла); } swCustProp.Set(толщинаЛистовогоМеталлаNAme, толщинаЛистовогоМеталла); confiData.ТолщинаЛистовогоМеталла = толщинаЛистовогоМеталла; string сгибы; swCustPrpMgr.Get4(сгибыName, true, out valOut, out сгибы); if (string.IsNullOrEmpty(сгибы)) { swCustPrpMgr.Get4(сгибыName2, true, out valOut, out сгибы); } swCustProp.Set(сгибыName, сгибы); confiData.Сгибы = сгибы; var myMassProp = swModel.Extension.CreateMassProperty(); var площадьПоверхности = Convert.ToString(Math.Round(myMassProp.SurfaceArea * 1000) / 1000); swCustProp.Set(площадьПокрытияName, площадьПоверхности); try { confiData.ПлощадьПокрытия = double.Parse(площадьПоверхности.Replace(".", ",")); } catch (Exception e) { exception = e; } } m1: swSubFeat = swSubFeat.GetNextFeature(); } } swFeat2 = swFeat2.GetNextFeature(); } dataList.Add(confiData); if (!closeDoc) { return; } var namePrt = swApp.IActiveDoc2.GetTitle().ToLower().Contains(".sldprt") ? swApp.IActiveDoc2.GetTitle() : swApp.IActiveDoc2.GetTitle() + ".sldprt"; swApp.CloseDoc(namePrt); }
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); } //查询参数 DP330 item = (DP330)objDP330Service.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会四舍五入 */ //-----------计算中间值,---------- decimal leftSBDis = item.LeftDis; decimal rightSBDis = item.RightDis; try { //----------Top Level---------- if (item.Length < 1000m) { swModel.Parameter("D1@LocalLPattern2").SystemValue = 2; swModel.Parameter("D3@LocalLPattern2").SystemValue = (item.Length - 400m) / 1000m; } else if (item.Length >= 1000m && item.Length < 2000m) { swModel.Parameter("D1@LocalLPattern2").SystemValue = 3; swModel.Parameter("D3@LocalLPattern2").SystemValue = (item.Length - 400m) / 2000m; } else { swModel.Parameter("D1@LocalLPattern2").SystemValue = 4; swModel.Parameter("D3@LocalLPattern2").SystemValue = (item.Length - 400m) / 3000m; } //----------侧板---------- switch (item.SidePanel) { case "LEFT": case "DPBACKL": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0003-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-10")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0004-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-11")); swComp.SetSuppression2(2); //2解压缩,0压缩. break; case "RIGHT": case "DPBACKR": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0003-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-10")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0004-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-11")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; case "MIDDLE": swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0003-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-10")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0004-2")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-11")); swComp.SetSuppression2(2); //2解压缩,0压缩. break; default: swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0003-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-10")); swComp.SetSuppression2(0); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0004-2")); swComp.SetSuppression2(2); //2解压缩,0压缩. swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0005-11")); swComp.SetSuppression2(0); //2解压缩,0压缩. break; } //----------背板---------- swComp = swAssy.GetComponentByName(CommonFunc.AddSuffix(suffix, "FNCS0002-2")); swPart = swComp.GetModelDoc2();//打开零件 swPart.Parameter("D3@Skizze1").SystemValue = item.Length / 1000m; swFeat = swComp.FeatureByName("DPB-LEFT"); if (item.SidePanel == "DPBACKL" || item.SidePanel == "DPBACKB") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("DPB-RIGHT"); if (item.SidePanel == "DPBACKR" || item.SidePanel == "DPBACKB") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //----------NOCJ腔主体---------- //重命名装配体内部 compReName = "FNCS0001[DP330-" + tree.Module + "]{" + (int)item.Length + "}"; status = swModelDocExt.SelectByID2(CommonFunc.AddSuffix(suffix, "FNCS0001-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@Skizze1").SystemValue = item.Length / 1000m; if (item.Outlet == "LEFT") { swFeat = swComp.FeatureByName("OUTLET-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("OUTLET-RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } else if (item.Outlet == "RIGHT") { swFeat = swComp.FeatureByName("OUTLET-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("OUTLET-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat = swComp.FeatureByName("OUTLET-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("OUTLET-RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("DPB-LEFT"); if (item.SidePanel == "DPBACKL" || item.SidePanel == "DPBACKB") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } swFeat = swComp.FeatureByName("DPB-RIGHT"); if (item.SidePanel == "DPBACKR" || item.SidePanel == "DPBACKB") { swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 } else { swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //DP if (item.DPSide == "LEFT" || item.DPSide == "BOTH") { swFeat = swComp.FeatureByName("DP-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D14@Sketch42").SystemValue = (item.LeftDis + 1m) / 1000m; leftSBDis = leftSBDis + 90m; swFeat = swComp.FeatureByName("CUT-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch56").SystemValue = 105m / 1000m; } else { swFeat = swComp.FeatureByName("DP-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("CUT-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } if (item.DPSide == "RIGHT" || item.DPSide == "BOTH") { swFeat = swComp.FeatureByName("DP-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D14@Sketch43").SystemValue = (item.RightDis + 1m) / 1000m; rightSBDis = rightSBDis + 90m; swFeat = swComp.FeatureByName("CUT-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch58").SystemValue = 105m / 1000m; } else { swFeat = swComp.FeatureByName("DP-RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("CUT-RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //BCJ if (item.BackCJSide == "LEFT" || item.BackCJSide == "BOTH") { swFeat = swComp.FeatureByName("BCJ-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D8@Sketch19").SystemValue = (item.LeftDis + 11m) / 1000m; leftSBDis = leftSBDis + 90m; } else { swFeat = swComp.FeatureByName("BCJ-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } if (item.BackCJSide == "RIGHT" || item.BackCJSide == "BOTH") { swFeat = swComp.FeatureByName("BCJ-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D1@Sketch20").SystemValue = (item.RightDis + 11m) / 1000m; rightSBDis = rightSBDis + 90m; } else { swFeat = swComp.FeatureByName("BCJ-RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //----------左---------- ////左类型排风腔KCJDB800 //if (item.LeftBeamType == "KCJDB800" || item.LeftBeamType == "UCJDB800") //{ // swFeat = swComp.FeatureByName("BCJ-LEFT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 // swFeat = swComp.FeatureByName("KCJDB800-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D59@Sketch46").SystemValue = (item.LeftBeamDis + 1m) / 1000m; // if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D6@Sketch48").SystemValue = (item.Length - item.LeftBeamDis + 1m) / 1000m; // } //} //else //{ // swFeat = swComp.FeatureByName("KCJDB800-LEFT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} //左类型排风腔KCWDB800 if (item.LeftBeamType == "KCWDB800" || item.LeftBeamType == "UCWDB800") { swFeat = swComp.FeatureByName("BCJ-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("DP-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("KCWDB800-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D30@Sketch50").SystemValue = (item.LeftBeamDis + 1m) / 1000m; if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") { swFeat = swComp.FeatureByName("GUTTER-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch53").SystemValue = (item.GutterWidth - 2m) / 1000m; swPart.Parameter("D5@Sketch53").SystemValue = (item.GutterWidth - 62m) / 1000m; swPart.Parameter("D7@Sketch53").SystemValue = (item.Length - item.LeftBeamDis + 1m) / 1000m; } } else { swFeat = swComp.FeatureByName("KCWDB800-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } ////左类型排风腔KCJSB535 //if (item.LeftBeamType == "KCJSB535" || item.LeftBeamType == "UCJSB535") //{ // swFeat = swComp.FeatureByName("KCJSB535-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D46@Sketch35").SystemValue = (leftSBDis + 1m) / 1000m; // if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 535m + 1m) / 1000m; // } //} //else //{ // swFeat = swComp.FeatureByName("KCJSB535-LEFT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} //左类型排风腔KCWSB535 if (item.LeftBeamType == "KCWSB535" || item.LeftBeamType == "UCWSB535") { swFeat = swComp.FeatureByName("KCWSB535-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D25@Sketch48").SystemValue = (leftSBDis + 1m) / 1000m; if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") { swFeat = swComp.FeatureByName("GUTTER-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch53").SystemValue = (item.GutterWidth - 2m) / 1000m; swPart.Parameter("D5@Sketch53").SystemValue = (item.GutterWidth - 62m) / 1000m; swPart.Parameter("D7@Sketch53").SystemValue = (leftSBDis + 535m + 1m) / 1000m; } } else { swFeat = swComp.FeatureByName("KCWSB535-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } ////左类型排风腔UCJSB385 //if (item.LeftBeamType == "UCJSB385") //{ // swFeat = swComp.FeatureByName("UCJSB385-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D16@Sketch43").SystemValue = (leftSBDis + 1m) / 1000m; // if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 385m + 1m) / 1000m; // } //} //else //{ // swFeat = swComp.FeatureByName("UCJSB385-LEFT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} ////左类型排风腔KCJSB290 //if (item.LeftBeamType == "KCJSB290") //{ // swFeat = swComp.FeatureByName("KCJSB290-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D14@Sketch41").SystemValue = (leftSBDis + 1m) / 1000m; // if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 290m + 1m) / 1000m; // } //} //else //{ // swFeat = swComp.FeatureByName("KCJSB290-LEFT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} ////左类型排风腔KCJSB265 //if (item.LeftBeamType == "KCJSB265") //{ // swFeat = swComp.FeatureByName("KCJSB265-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D23@Sketch28").SystemValue = (leftSBDis + 1m) / 1000m; // if (item.LKSide == "LEFT" || item.LKSide == "BOTH") // { // swFeat = swComp.FeatureByName("LKS270-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D24@Sketch51").SystemValue = (leftSBDis + 265m + 1m) / 1000m; // if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 270m + 265m + 1m) / 1000m; // } // } // else // { // if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-LEFT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch48").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch48").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D6@Sketch48").SystemValue = (leftSBDis + 265m + 1m) / 1000m; // } // } //} //else //{ // swFeat = swComp.FeatureByName("KCJSB265-LEFT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} //左类型排风腔KCWSB265 if (item.LeftBeamType == "KCWSB265") { swFeat = swComp.FeatureByName("KCWSB265-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D15@Sketch46").SystemValue = (leftSBDis + 1m) / 1000m; if (item.LKSide == "LEFT" || item.LKSide == "BOTH") { swFeat = swComp.FeatureByName("LKS270-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D24@Sketch52").SystemValue = (leftSBDis + 265m + 1m) / 1000m; if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") { swFeat = swComp.FeatureByName("GUTTER-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch53").SystemValue = (item.GutterWidth - 2m) / 1000m; swPart.Parameter("D5@Sketch53").SystemValue = (item.GutterWidth - 62m) / 1000m; swPart.Parameter("D7@Sketch53").SystemValue = (leftSBDis + 270m + 265m + 1m) / 1000m; } } else { if (item.GutterSide == "LEFT" || item.GutterSide == "BOTH") { swFeat = swComp.FeatureByName("GUTTER-LEFT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch53").SystemValue = (item.GutterWidth - 2m) / 1000m; swPart.Parameter("D5@Sketch53").SystemValue = (item.GutterWidth - 62m) / 1000m; swPart.Parameter("D7@Sketch53").SystemValue = (leftSBDis + 265m + 1m) / 1000m; } } } else { swFeat = swComp.FeatureByName("KCWSB265-LEFT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } //----------右---------- ////右类型排风腔KCJDB800 //if (item.RightBeamType == "KCJDB800" || item.RightBeamType == "UCJDB800") //{ // swFeat = swComp.FeatureByName("BCJ-RIGHT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 // swFeat = swComp.FeatureByName("KCJDB800-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D59@Sketch47").SystemValue = (item.RightBeamDis + 1m) / 1000m; // if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D7@Sketch50").SystemValue = (item.Length - item.RightBeamDis + 1m) / 1000m; // } //} //else //{ // swFeat = swComp.FeatureByName("KCJDB800-RIGHT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} //右类型排风腔KCWDB800 if (item.RightBeamType == "KCWDB800" || item.RightBeamType == "UCWDB800") { swFeat = swComp.FeatureByName("BCJ-RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("DP-RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 swFeat = swComp.FeatureByName("KCWDB800-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D31@Sketch51").SystemValue = (item.RightBeamDis + 1m) / 1000m; if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") { swFeat = swComp.FeatureByName("GUTTER-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch55").SystemValue = (item.GutterWidth - 2m) / 1000m; swPart.Parameter("D5@Sketch55").SystemValue = (item.GutterWidth - 62m) / 1000m; swPart.Parameter("D7@Sketch55").SystemValue = (item.Length - item.RightBeamDis + 1m) / 1000m; } } else { swFeat = swComp.FeatureByName("KCWDB800-RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } ////右类型排风腔KCJSB535 //if (item.RightBeamType == "KCJSB535" || item.RightBeamType == "UCJSB535") //{ // swFeat = swComp.FeatureByName("KCJSB535-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D46@Sketch37").SystemValue = (rightSBDis + 1m) / 1000m; // if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 535m + 1m) / 1000m; // } //} //else //{ // swFeat = swComp.FeatureByName("KCJSB535-RIGHT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} //右类型排风腔KCWSB535 if (item.RightBeamType == "KCWSB535" || item.RightBeamType == "UCWSB535") { swFeat = swComp.FeatureByName("KCWSB535-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D24@Sketch49").SystemValue = (rightSBDis + 1m) / 1000m; if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") { swFeat = swComp.FeatureByName("GUTTER-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch55").SystemValue = (item.GutterWidth - 2m) / 1000m; swPart.Parameter("D5@Sketch55").SystemValue = (item.GutterWidth - 62m) / 1000m; swPart.Parameter("D7@Sketch55").SystemValue = (rightSBDis + 535m + 1m) / 1000m; } } else { swFeat = swComp.FeatureByName("KCWSB535-RIGHT"); swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 } ////右类型排风腔UCJSB385 //if (item.RightBeamType == "UCJSB385") //{ // swFeat = swComp.FeatureByName("UCJSB385-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D16@Sketch44").SystemValue = (rightSBDis + 1m) / 1000m; // if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 385m + 1m) / 1000m; // } //} //else //{ // swFeat = swComp.FeatureByName("UCJSB385-RIGHT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} ////右类型排风腔KCJSB290 //if (item.RightBeamType == "KCJSB290") //{ // swFeat = swComp.FeatureByName("KCJSB290-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D14@Sketch42").SystemValue = (rightSBDis + 1m) / 1000m; // if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 290m + 1m) / 1000m; // } //} //else //{ // swFeat = swComp.FeatureByName("KCJSB290-RIGHT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} ////右类型排风腔KCJSB265 //if (item.RightBeamType == "KCJSB265") //{ // swFeat = swComp.FeatureByName("KCJSB265-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D1@Sketch55").SystemValue = (rightSBDis + 1m) / 1000m; // if (item.LKSide == "RIGHT" || item.LKSide == "BOTH") // { // swFeat = swComp.FeatureByName("LKS270-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D24@Sketch53").SystemValue = (rightSBDis + 265m + 1m) / 1000m; // if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 270m + 265m + 1m) / 1000m; // } // } // else // { // if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") // { // swFeat = swComp.FeatureByName("GUTTER-RIGHT"); // swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 // swPart.Parameter("D4@Sketch50").SystemValue = (item.GutterWidth - 2m) / 1000m; // swPart.Parameter("D5@Sketch50").SystemValue = (item.GutterWidth - 62m) / 1000m; // swPart.Parameter("D7@Sketch50").SystemValue = (rightSBDis + 265m + 1m) / 1000m; // } // } //} //else //{ // swFeat = swComp.FeatureByName("KCJSB265-RIGHT"); // swFeat.SetSuppression2(0, 2, configNames); //参数1:1解压,0压缩 //} //右类型排风腔KCWSB265 if (item.RightBeamType == "KCWSB265") { swFeat = swComp.FeatureByName("KCWSB265-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D15@Sketch47").SystemValue = (rightSBDis + 1m) / 1000m; if (item.LKSide == "RIGHT" || item.LKSide == "BOTH") { swFeat = swComp.FeatureByName("LKS270-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D24@Sketch54").SystemValue = (rightSBDis + 265m + 1m) / 1000m; if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") { swFeat = swComp.FeatureByName("GUTTER-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch55").SystemValue = (item.GutterWidth - 2m) / 1000m; swPart.Parameter("D5@Sketch55").SystemValue = (item.GutterWidth - 62m) / 1000m; swPart.Parameter("D7@Sketch55").SystemValue = (rightSBDis + 270m + 265m + 1m) / 1000m; } } else { if (item.GutterSide == "RIGHT" || item.GutterSide == "BOTH") { swFeat = swComp.FeatureByName("GUTTER-RIGHT"); swFeat.SetSuppression2(1, 2, configNames); //参数1:1解压,0压缩 swPart.Parameter("D4@Sketch55").SystemValue = (item.GutterWidth - 2m) / 1000m; swPart.Parameter("D5@Sketch55").SystemValue = (item.GutterWidth - 62m) / 1000m; swPart.Parameter("D7@Sketch55").SystemValue = (rightSBDis + 265m + 1m) / 1000m; } } } else { swFeat = swComp.FeatureByName("KCWSB265-RIGHT"); 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的使用 } }
/// <summary> /// 天花子装配导出DXF图纸 /// </summary> /// <param name="swApp"></param> /// <param name="tree"></param> /// <param name="dxfPath"></param> /// <param name="userId"></param> public void CeilingAssyToDxf(SldWorks swApp, SubAssy subAssy, string dxfPath, int userId) { swApp.CommandInProgress = true; List <CeilingCutList> celingCutLists = new List <CeilingCutList>(); string assyPath = subAssy.SubAssyPath; if (assyPath.Length == 0) { return; } try { //打开模型 ModelDoc2 swModel = swApp.OpenDoc6(assyPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; if (swModel == null) { MessageBox.Show("模型不存在,请认真检查", "模型不存在"); return; } string modulePath = dxfPath + @"\" + subAssy.SubAssyName; if (!Directory.Exists(modulePath)) { Directory.CreateDirectory(modulePath); } swModel.ForceRebuild3(true); AssemblyDoc swAssy = swModel as AssemblyDoc; //获取所有零部件集合 var compList = swAssy.GetComponents(false); //遍历集合中的所有零部件对象 foreach (var swComp in compList) { //判断零件是否被压缩,不显示,封套,零件名称不是以sldprt或SLDPRT结尾 if (swComp.Visible == 1 && !swComp.IsEnvelope() && !swComp.IsSuppressed() && (swComp.GetPathName().EndsWith(".sldprt") || swComp.GetPathName().EndsWith(".SLDPRT"))) { Component2 swParentComp = swComp.GetParent(); //总装没有父装配体 if (swParentComp == null) { ConfigurationManager swConfigMgr = swModel.ConfigurationManager; Configuration swConfig2 = swConfigMgr.ActiveConfiguration; swParentComp = swConfig2.GetRootComponent3(true); } //判断父装配体是否可视,并且不封套 if (swParentComp.Visible == 1 && !swParentComp.IsEnvelope() && !swComp.IsSuppressed()) { PartDoc swPart = swComp.GetModelDoc2(); //获取文档中的额Body对象集合 var bodyList = swPart.GetBodies2(0, false); //遍历集合中的所有Body对象,判断是否为钣金 foreach (var swBody in bodyList) { //如果是钣金则将零件地址添加到列表中 if (swBody.IsSheetMetal()) { if (sheetMetaDic.ContainsKey(swComp.GetPathName())) { sheetMetaDic[swComp.GetPathName()] += 1; } else { sheetMetaDic.Add(swComp.GetPathName(), 1); } } } } } } //关闭装配体零件 swApp.CloseDoc(assyPath); //遍历钣金零件 foreach (var sheetMeta in sheetMetaDic) { //打开模型 ModelDoc2 swPart = swApp.OpenDoc6(sheetMeta.Key, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings) as ModelDoc2; Feature swFeat = (Feature)swPart.FirstFeature(); CeilingCutList cutRecord = new CeilingCutList() { SubAssyId = subAssy.SubAssyId, Quantity = sheetMeta.Value, UserId = userId }; while (swFeat != null) { var suppStatus = swFeat.IsSuppressed2((int)swInConfigurationOpts_e.swThisConfiguration, null); if (suppStatus[0] == false && swFeat.GetTypeName() == "SolidBodyFolder") { BodyFolder swBodyFolder = (BodyFolder)swFeat.GetSpecificFeature2(); swBodyFolder.SetAutomaticCutList(true); swBodyFolder.SetAutomaticUpdate(true); Feature SubFeat = swFeat.GetFirstSubFeature(); if (SubFeat != null) { Feature ownerFeature = SubFeat.GetOwnerFeature(); BodyFolder swSubBodyFolder = ownerFeature.GetSpecificFeature2(); swSubBodyFolder.UpdateCutList(); string val = string.Empty; string valout = string.Empty; bool wasResolved = false; bool linkToProp = false; SubFeat.CustomPropertyManager.Get4("Bounding Box Length", false, out val, out valout); cutRecord.Length = Convert.ToDecimal(valout); SubFeat.CustomPropertyManager.Get4("Bounding Box Width", false, out val, out valout); cutRecord.Width = Convert.ToDecimal(valout); SubFeat.CustomPropertyManager.Get4("Sheet Metal Thickness", false, out val, out valout); cutRecord.Thickness = Convert.ToDecimal(valout); SubFeat.CustomPropertyManager.Get4("Material", false, out val, out valout); cutRecord.Materials = valout; swPart.GetActiveConfiguration().CustomPropertyManager.Get6("Description", false, out valout, out val, out wasResolved, out linkToProp); cutRecord.PartDescription = valout; cutRecord.PartNo = swPart.GetTitle().Substring(0, swPart.GetTitle().Length - 7); celingCutLists.Add(cutRecord);//将信息添加到集合中 } } swFeat = swFeat.GetNextFeature(); } PartToDxf(swApp, swPart, modulePath); //关闭零件 swApp.CloseDoc(sheetMeta.Key); } } catch (Exception ex) { throw new Exception(assyPath + "导图过程发生异常,详细:" + ex.Message); } finally { sheetMetaDic.Clear(); swApp.CloseDoc(assyPath); //关闭,很快 swApp.CommandInProgress = false; //及时关闭外部命令调用,否则影响SolidWorks的使用 } //基于事务ceilingCutLists提交SQLServer if (celingCutLists.Count == 0) { return; } try { if (objCeilingCutListService.ImportCutList(celingCutLists)) { celingCutLists.Clear(); } } catch (Exception ex) { throw new Exception("Cutlist导入数据库失败" + ex.Message); } }
/// <summary> /// Opens and saves models referenced in the open drawing. /// </summary> /// <returns>Returns a <see cref="System.Boolean"/>, should you need one.</returns> public Boolean ExportEDrawings() { ModelDoc2 currentDoc = swModel; string docName = currentDoc.GetPathName(); String sourceName = Path.GetFileNameWithoutExtension(docName); String altPath = Path.GetDirectoryName(docName).Substring(3); ModelDocExtension swModExt = swModel.Extension; String Rev = GetRev(swModExt); String fFormat = String.Empty; List <string> ml = get_list_of_open_docs(); List <String> EdrwTarget = new List <string>(); List <String> STEPTarget = new List <string>(); Boolean measurable = true; Int32 options = 0; Int32 errors = 0; switch (modelType) { case swDocumentTypes_e.swDocASSEMBLY: fFormat = ".EASM"; break; case swDocumentTypes_e.swDocPART: fFormat = ".EPRT"; break; default: ExportPDFException e = new ExportPDFException("Document type error."); //e.Data.Add("who", System.Environment.UserName); //e.Data.Add("when", DateTime.Now); throw e; } swApp.ActivateDoc3(sourcePath, true, options, ref errors); swModel = (ModelDoc2)swApp.ActiveDoc; Configuration swConfig = (Configuration)swModel.GetActiveConfiguration(); swFrame.SetStatusBarText("Positioning model."); swModel.ShowNamedView2("*Dimetric", 9); swModel.ViewZoomtofit2(); if (!swApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEDrawingsOkayToMeasure)) { swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEDrawingsOkayToMeasure, true); measurable = false; } else { measurable = true; } EdrwTarget.Add(String.Format("{0}{1}\\{2}{3}", APathSet.KPath, altPath, sourceName, fFormat)); EdrwTarget.Add(String.Format("{0}{1}\\{2}{3}{4}", APathSet.GPath, altPath, sourceName, Rev, fFormat)); if (APathSet.ExportSTEP) { STEPTarget.Add(String.Format("{0}{1}\\{2}{3}", APathSet.KPath, altPath, sourceName, @".STEP")); STEPTarget.Add(String.Format("{0}{1}\\{2}{3}{4}", APathSet.GPath, altPath, sourceName, Rev, @".STEP")); } Boolean success = SaveSTEPorEDrw(EdrwTarget); if (STEPTarget.Count > 0) { success = SaveSTEPorEDrw(STEPTarget); } if (!measurable) { swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEDrawingsOkayToMeasure, false); } if (!ml.Contains(swModel.GetPathName())) { swFrame.SetStatusBarText("Closing model."); swApp.CloseDoc(sourcePath); } else if (APathSet.SaveFirst) { swModel.SaveSilent(); } int err = 0; swApp.ActivateDoc3(currentDoc.GetTitle(), true, (int)swRebuildOnActivation_e.swDontRebuildActiveDoc, ref err); return(success); }
/// <summary> /// Units the S50. /// </summary> /// <param name="size">The size.</param> /// <param name="type">The type.</param> /// <param name="side">The side.</param> /// <param name="widthS">The width s.</param> /// <param name="heightS">The lenght s.</param> /// <param name="lenghtS">The lenght s.</param> /// <param name="montageFrame">The montage frame.</param> /// <param name="typeOfFrame">The type of frame.</param> /// <param name="frameOffset">The frame offset.</param> /// <param name="typeOfPanel">The type of panel.</param> /// <param name="materialP1">The material p1.</param> /// <param name="materialP2">The material p2.</param> /// <param name="roofType">Type of the roof.</param> /// <param name="dumper">The dumper.</param> /// <param name="spigot">The spigot.</param> /// <param name="p1">The p1.</param> /// <param name="p2">The p2.</param> /// <param name="p3">The p3.</param> /// <param name="p4">The p4.</param> /// <param name="widthVb">The width vb.</param> /// <param name="filter">The filter.</param> /// <param name="heater">The heater.</param> /// <param name="cooler">The cooler.</param> /// <param name="ventil">The ventil.</param> public void UnitS50(string size, string type, string side, string widthS, string heightS, string lenghtS, string montageFrame, string typeOfFrame, string frameOffset, string typeOfPanel, string[] materialP1, string[] materialP2, string roofType, string dumper, string spigot, string p1, string p2, string p3, string p4, string widthVb, string filter, string heater, string cooler, string ventil) { Логгер.Информация($"Начало генерации установки {$"{size}-{type}"}", "", null, "UnitS50"); try { try { _swApp = (SldWorks) Marshal.GetActiveObject("SldWorks.Application"); } catch (Exception) { _swApp = new SldWorks {Visible = true}; } if (_swApp == null) { return; } _swApp.CloseDoc(dumper.Replace("ASM", "DRW")); _swApp.CloseDoc(spigot.Replace("ASM", "DRW")); _swApp.CloseDoc(p1); _swApp.CloseDoc(p2); _swApp.CloseDoc(p3); _swApp.CloseDoc(p4); UnitS50Str(size, type, side, widthS, heightS, lenghtS, montageFrame, typeOfFrame, frameOffset, typeOfPanel, materialP1, materialP2, roofType, dumper, spigot, p1, p2, p3, p4, widthVb, filter, heater, cooler, ventil); foreach (var coponent in NewComponents) { MessageBox.Show($"Компоненты, осзданные во время генерации {$"{coponent.Name}"}"); Логгер.Информация($"Компоненты, осзданные во время генерации {$"{coponent.Name}"}", "", null, "UnitS50"); } } catch (Exception e) { Логгер.Ошибка($"Ошибка во время генерации блока {$"{size}-{type}-{lenghtS}"}, время - {e.Message}", e.StackTrace, null, "UnitS50"); } }