Exemplo n.º 1
0
        /// <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;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 得到质量属性
        /// <param name="trademark">材料牌号</param>
        /// <param name="costingoutput">成本输出对象</param>
        /// </summary>
        private void getMass(string trademark, ref HZ_MassProperty costingoutput)
        {
            if (m_ModelDoc != null)
            {
                MassProperty mp = m_ModelDoc.Extension.CreateMassProperty();
                mp.UseSystemUnits = true;

                // 获取名称
                costingoutput.name = m_ModelDoc.GetTitle();
                // 获取材料牌号-没什么用
                costingoutput.material = trademark;
                // 获取重量
                costingoutput.mass = mp.Mass.ToString();
                // 获取密度
                costingoutput.density = mp.Density.ToString();
                // 获取表面积
                costingoutput.surface = mp.SurfaceArea.ToString();
                // 获取体积
                costingoutput.volume = mp.Volume.ToString();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 得到尺寸属性
 /// </summary>
 /// <param name="costingoutput">成本输出对象</param>
 private void getBox(ref HZ_MassProperty costingoutput)
 {
     if (m_ModelDoc != null)
     {
         object  boxobj    = new object();
         PartDoc swPartDoc = (PartDoc)m_ModelDoc;
         if (swPartDoc != null)
         {
             boxobj = swPartDoc.GetPartBox(true);
             if (boxobj != null)
             {
                 double[] BoxFaceDblArray = new double[7];
                 BoxFaceDblArray = (double[])boxobj;
                 // 成本输出对象赋值
                 costingoutput.x   = (BoxFaceDblArray[3] - BoxFaceDblArray[0]).ToString();
                 costingoutput.y   = (BoxFaceDblArray[4] - BoxFaceDblArray[1]).ToString();
                 costingoutput.z   = (BoxFaceDblArray[5] - BoxFaceDblArray[2]).ToString();
                 costingoutput.box = (BoxFaceDblArray[5] - BoxFaceDblArray[2]).ToString();
             }
         }
     }
 }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        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() + "秒");
        }