/// <summary> /// 得到特征分析数据 /// </summary> /// <param name="costingoutput">成本输出对象</param> private double getCostingFeatures(ref HZ_CostingOutput costingoutput) { double superCost = 0; List <HZ_FeatCost> FeatCostList = new List <HZ_FeatCost>(); CostFeature swCostingFeat = (CostFeature)m_swCostingAnalysis.GetFirstCostFeature(); // 得到特征数据 while ((swCostingFeat != null)) { HZ_FeatCost FeatCost = new HZ_FeatCost { feature = swCostingFeat.Name, type = swCostingFeat.GetType(), description = swCostingFeat.Description, combinedCost = m_Tools.specNum(swCostingFeat.CombinedCost), combinedTime = m_Tools.getTimeCost(swCostingFeat.CombinedTime) }; // 得到子特征数据 CostFeature swCostingSubFeat = swCostingFeat.GetFirstSubFeature(); while ((swCostingSubFeat != null)) { //孔超标数据,标准 > 5 直接剔除,并+2 元 if (swCostingFeat.GetType() == (int)swcCostFeatureType_e.swcMachiningHoleOperationsFolderType && m_Tools.specNum(swCostingSubFeat.CombinedCost) > 5) { costingoutput.totalManufacturingCost -= swCostingSubFeat.CombinedCost; costingoutput.totalCostrueToManufacture -= swCostingSubFeat.CombinedCost; costingoutput.totalCostrueToCharge -= swCostingSubFeat.CombinedCost; costingoutput.totalManufacturingCost += 2; costingoutput.totalCostrueToManufacture += 2; costingoutput.totalCostrueToCharge += 2; } HZ_SubFeatCost SubFeatCost = new HZ_SubFeatCost { SubFeature = swCostingSubFeat.Name, type = swCostingSubFeat.GetType(), description = swCostingSubFeat.Description, combinedCost = m_Tools.specNum(swCostingSubFeat.CombinedCost), combinedTime = m_Tools.getTimeCost(swCostingSubFeat.CombinedTime) }; FeatCost.subFeatCostList.Add(SubFeatCost); CostFeature swCostingNextSubFeat = (CostFeature)swCostingSubFeat.GetNextFeature(); swCostingSubFeat = null; swCostingSubFeat = (CostFeature)swCostingNextSubFeat; swCostingNextSubFeat = null; } CostFeature swCostingNextFeat = swCostingFeat.GetNextFeature(); swCostingFeat = null; swCostingFeat = (CostFeature)swCostingNextFeat; swCostingNextFeat = null; FeatCostList.Add(FeatCost); } // 成本输出文件赋值 costingoutput.featCostList = FeatCostList; return(superCost); }
/// <summary> /// 得到机加工属性数据数据 /// </summary> /// <param name="costingoutput">成本输出对象</param> private void getMachiningCostingAnalysisData(HZ_CostingOutput costingoutput, ref HZ_MassProperty massOutput, HZ_StockType stockType, string materialClass, string materialName) { // 得到机加工属性 CostAnalysisMachining swCostingMachining = (CostAnalysisMachining)m_swCostingAnalysis.GetSpecificAnalysis(); if (swCostingMachining != null) { swCostingMachining.CurrentMaterialClass = materialClass; swCostingMachining.CurrentMaterial = materialName; swCostingMachining.CurrentStockType = (int)stockType; costingoutput.stockType = swCostingMachining.CurrentStockType; costingoutput.currentMaterial = swCostingMachining.CurrentMaterial; costingoutput.currentMaterialClass = swCostingMachining.CurrentMaterialClass; //costingoutput.currentPlateThickness = swCostingMachining.CurrentPlateThickness; } }
/// <summary> /// 得到通用成本分析数据 /// </summary> /// <param name="costingoutput">成本输出对象</param> private void getCommonCostingAnalysisData(HZ_CostingOutput costingoutput, int totalNum, int lotSize) { //设置零件总个数和批量大小 //m_swCostingAnalysis.TotalQuantity = totalNum; //m_swCostingAnalysis.LotSize = lotSize; // 得到 common Costing analysis 数据 // 成本输出对象赋值 costingoutput.templateName = m_swCostingAnalysis.CostingTemplateName; costingoutput.currencyCode = m_swCostingAnalysis.CurrencyCode; costingoutput.currencyName = m_swCostingAnalysis.CurrencyName; costingoutput.currencySeparator = m_swCostingAnalysis.CurrencySeparator; costingoutput.totalManufacturingCost = m_swCostingAnalysis.GetManufacturingCost(); costingoutput.materialCosts = m_swCostingAnalysis.GetMaterialCost(); costingoutput.totalNum = m_swCostingAnalysis.TotalQuantity; costingoutput.lotSize = m_swCostingAnalysis.LotSize; costingoutput.totalCostrueToCharge = m_swCostingAnalysis.GetTotalCostToCharge(); costingoutput.totalCostrueToManufacture = m_swCostingAnalysis.GetTotalCostToManufacture(); }
private void button3_Click(object sender, EventArgs e) { HZ_EnumType type = HZ_EnumType.hz_SimpleTurning; //工艺 int lotSize = 100; //批量大小 int totalNum = 100; //零件总个数 string materialClass = ""; //材料类型 string materialName = ""; //材料名称 HZ_StockType stocktype = HZ_StockType.Block; //配料类型 //Solidworks程序对象 m_SwApp = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")); //打开文件 m_ModelDoc = openModle(partfilepath); //生成缩略图 // ModelView LoMyModelView; //生成缩略图 //LoMyModelView = m_ModelDoc.ActiveView; //LoMyModelView.FrameState = (int)swWindowState_e.swWindowMaximized; ////m_ModelDoc.ShowNamedView2("*Isometric", 7); //m_ModelDoc.ViewZoomtofit2(); //m_ModelDoc.SaveAs(Application.StartupPath + "\\test.jpg"); //m_ModelDoc.SaveAs(Application.StartupPath + "\\test.stl"); //仅支持零部件 if (m_ModelDoc.GetType() != (int)swDocumentTypes_e.swDocPART) { MessageBox.Show("仅支持零部件!"); return; } bool isSheetMetal = false; bool isSolidBody = false; bool isBlank = false; string strError = string.Empty; //仅支持单实体零部件 if (isMutiBodyOrSheetMetal(ref isBlank, ref isSheetMetal, ref isSolidBody, ref strError)) { MessageBox.Show("仅支持单体零部件!"); return; } //空白图纸 if (isBlank) { MessageBox.Show("空白图纸!"); return; } //不支持钣金件 if (isSheetMetal) { MessageBox.Show("不支持钣金件!"); return; } //是否为实体零件 if (!isSolidBody) { MessageBox.Show("非实体零部件!"); return; } //获取SolidWorks扩展器 ModelDocExtension swModelDocExt = m_ModelDoc.Extension; // 初始化成本输出对象 HZ_CostingOutput CostingOutput = new HZ_CostingOutput(); //详细输出对象 HZ_MassProperty massOutput = new HZ_MassProperty(); // 得到质量属性 Part Mass getMass("", ref massOutput); // 得到外形尺寸属性 getBox(ref massOutput); swCosting = (CostManager)swModelDocExt.GetCostingManager(); swCosting.WaitForUIUpdate(); // 得到 Costing part object swCostingModel = (object)swCosting.CostingModel; swCostingPart = (CostPart)swCostingModel; //设置默认模块参数 //模板,批量大小,零件总个数,材料类型,材料名称,计算方式,配料类型 swcCostingDefaults = (CostingDefaults)swCosting.CostingDefaults; swcCostingDefaults.SetTemplateName((int)swcCostingType_e.swcCostingType_Machining, selectCostingTemp(type)); //单体零件 swcCostingDefaults.LotSizeForSingleBody = lotSize; swcCostingDefaults.TotalNumberOfPartsForSingleBody = totalNum; //多实体文件 swcCostingDefaults.LotSizeForMultibody = lotSize; swcCostingDefaults.TotalNumberOfPartsForMultibody = totalNum; //设置材料以及材料处理方式 swcCostingDefaults.SetMaterialClass((int)swcMethodType_e.swcMethodType_Machining, materialClass); swcCostingDefaults.SetMaterialName((int)swcMethodType_e.swcMethodType_Machining, materialName); swcCostingDefaults.SetManufacturingMethod((int)swcBodyType_e.swcBodyType_Machined, (int)swcBodyType_e.swcBodyType_Machined); swcCostingDefaults.MachiningStockBodyType = (int)stocktype; //获取Cost Body swCostingBody = swCostingPart.SetCostingMethod("", (int)swcMethodType_e.swcMethodType_Machining); if (swCostingBody == null) { MessageBox.Show("制造成本计算失败"); return; } // 创建 common Costing analysis m_swCostingAnalysis = swCostingBody.CreateCostAnalysis(selectCostingTemp(type)); m_swCostingAnalysis = swCostingBody.GetCostAnalysis(); m_swCostingAnalysis.TotalQuantity = totalNum; m_swCostingAnalysis.LotSize = lotSize; CostFeature swCostingFeat = default(CostFeature); CostFeature swCostingNextFeat = default(CostFeature); CostFeature swCostingSubFeat = default(CostFeature); CostFeature swCostingNextSubFeat = default(CostFeature); swCostingFeat = (CostFeature)m_swCostingAnalysis.GetFirstCostFeature(); while ((swCostingFeat != null)) { // swcCostFeatureType_e. Debug.Print(" Feature: " + swCostingFeat.Name); Debug.Print(" Type: " + swCostingFeat.GetType()); Debug.Print(" Setup related: " + swCostingFeat.IsSetup); Debug.Print(" Overridden: " + swCostingFeat.IsOverridden); Debug.Print(" Combined cost: " + swCostingFeat.CombinedCost); Debug.Print(" Combined time: " + swCostingFeat.CombinedTime); swCostingSubFeat = swCostingFeat.GetFirstSubFeature(); while ((swCostingSubFeat != null)) { Debug.Print(" Subfeature: " + swCostingSubFeat.Name); Debug.Print(" Type: " + swCostingSubFeat.GetType()); Debug.Print(" Setup related: " + swCostingSubFeat.IsSetup); Debug.Print(" Overridden: " + swCostingSubFeat.IsOverridden); Debug.Print(" Combined cost: " + swCostingSubFeat.CombinedCost); Debug.Print(" Combined time: " + swCostingSubFeat.CombinedTime); swCostingNextSubFeat = (CostFeature)swCostingSubFeat.GetNextFeature(); swCostingSubFeat = null; swCostingSubFeat = (CostFeature)swCostingNextSubFeat; swCostingNextSubFeat = null; } swCostingNextFeat = swCostingFeat.GetNextFeature(); swCostingFeat = null; swCostingFeat = (CostFeature)swCostingNextFeat; swCostingNextFeat = null; } }
private void button1_Click(object sender, EventArgs e) { DateTime dt1 = DateTime.Now; HZ_EnumType type = HZ_EnumType.hz_SimpleTurning; //工艺 int lotSize = 100; //批量大小 int totalNum = 100; //零件总个数 string materialClass = ""; //材料类型 string materialName = ""; //材料名称 HZ_StockType stocktype = HZ_StockType.Block; //配料类型 //Solidworks程序对象 m_SwApp = (SldWorks)Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")); //打开文件 m_ModelDoc = openModle(partfilepath); //生成缩略图 // ModelView LoMyModelView; //生成缩略图 //LoMyModelView = m_ModelDoc.ActiveView; //LoMyModelView.FrameState = (int)swWindowState_e.swWindowMaximized; ////m_ModelDoc.ShowNamedView2("*Isometric", 7); //m_ModelDoc.ViewZoomtofit2(); //m_ModelDoc.SaveAs(Application.StartupPath + "\\test.jpg"); //m_ModelDoc.SaveAs(Application.StartupPath + "\\test.stl"); //仅支持零部件 if (m_ModelDoc.GetType() != (int)swDocumentTypes_e.swDocPART) { MessageBox.Show("仅支持零部件!"); return; } bool isSheetMetal = false; bool isSolidBody = false; bool isBlank = false; string strError = string.Empty; //仅支持单实体零部件 if (isMutiBodyOrSheetMetal(ref isBlank, ref isSheetMetal, ref isSolidBody, ref strError)) { MessageBox.Show("仅支持单体零部件!"); return; } //空白图纸 if (isBlank) { MessageBox.Show("空白图纸!"); return; } //不支持钣金件 if (isSheetMetal) { MessageBox.Show("不支持钣金件!"); return; } //是否为实体零件 if (!isSolidBody) { MessageBox.Show("非实体零部件!"); return; } //获取SolidWorks扩展器 ModelDocExtension swModelDocExt = m_ModelDoc.Extension; // 初始化成本输出对象 HZ_CostingOutput CostingOutput = new HZ_CostingOutput(); //详细输出对象 HZ_MassProperty massOutput = new HZ_MassProperty(); // 得到质量属性 Part Mass getMass("", ref massOutput); // 得到外形尺寸属性 getBox(ref massOutput); swCosting = (CostManager)swModelDocExt.GetCostingManager(); swCosting.WaitForUIUpdate(); // 得到 Costing part object swCostingModel = (object)swCosting.CostingModel; swCostingPart = (CostPart)swCostingModel; //设置默认模块参数 //模板,批量大小,零件总个数,材料类型,材料名称,计算方式,配料类型 swcCostingDefaults = (CostingDefaults)swCosting.CostingDefaults; swcCostingDefaults.SetTemplateName((int)swcCostingType_e.swcCostingType_Machining, selectCostingTemp(type)); //单体零件 swcCostingDefaults.LotSizeForSingleBody = lotSize; swcCostingDefaults.TotalNumberOfPartsForSingleBody = totalNum; //多实体文件 swcCostingDefaults.LotSizeForMultibody = lotSize; swcCostingDefaults.TotalNumberOfPartsForMultibody = totalNum; //设置材料以及材料处理方式 swcCostingDefaults.SetMaterialClass((int)swcMethodType_e.swcMethodType_Machining, materialClass); swcCostingDefaults.SetMaterialName((int)swcMethodType_e.swcMethodType_Machining, materialName); swcCostingDefaults.SetManufacturingMethod((int)swcBodyType_e.swcBodyType_Machined, (int)swcBodyType_e.swcBodyType_Machined); swcCostingDefaults.MachiningStockBodyType = (int)stocktype; //获取Cost Body swCostingBody = swCostingPart.SetCostingMethod("", (int)swcMethodType_e.swcMethodType_Machining); if (swCostingBody == null) { MessageBox.Show("制造成本计算失败"); return; } // 创建 common Costing analysis m_swCostingAnalysis = swCostingBody.CreateCostAnalysis(selectCostingTemp(type)); m_swCostingAnalysis = swCostingBody.GetCostAnalysis(); m_swCostingAnalysis.TotalQuantity = totalNum; m_swCostingAnalysis.LotSize = lotSize; // 得到 Costing bodies int nbrCostingBodies = swCostingPart.GetBodyCount(); if (hasBody(nbrCostingBodies, swCostingPart, type)) { // 得到 machining Costing Analysis 数据 getMachiningCostingAnalysisData(CostingOutput, ref massOutput, stocktype, materialClass, materialName); //得到返回的质量属性 CostingOutput.massProperty = massOutput; // 得到 common Costing analysis 数据 getCommonCostingAnalysisData(CostingOutput, totalNum, lotSize); //孔超标数据,标准 > 5 直接剔除,并+2 元,处理倒角导致成本超高的问题 getCostingFeatures(ref CostingOutput); } DateTime dt2 = DateTime.Now; TimeSpan dt3 = dt2 - dt1; int goTime = dt3.Seconds; MessageBox.Show(goTime.ToString() + "秒"); }