c# solidworks 折弯系数检查

https://blog.csdn.net/njsgcs/article/details/159347936

csharp 复制代码
namespace tools;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Diagnostics;

public class checkk_factor
{
   

    public static void Process_CustomBendAllowance(string modelname, CustomBendAllowance swCustBend,double BendRadius,string FeatureName,double thickness,double angle)
    {
        var debuct_factor = Math.Round(swCustBend.BendDeduction* 1000.0 / thickness,2);
        var a2d= Math.Round((2*thickness-swCustBend.BendAllowance*1000.0)  / thickness,2);
        var k2d =Math.Round(( 2 * thickness - Math.PI / 2 * (BendRadius + swCustBend.KFactor * thickness) + 2 * BendRadius)/ thickness,2);
      
        if (BendRadius >= 2 & (swCustBend.Type != 2 || swCustBend.Type == 2 & swCustBend.KFactor != 0.5))

          Console.WriteLine($"k因子错误,{modelname}+{FeatureName},k因子:{swCustBend.KFactor }");
          
        

        else if (swCustBend.Type==4&& (debuct_factor < 1.6 || debuct_factor > 1.8))
        
   
          
             Console.WriteLine($"k因子错误,{modelname}+{FeatureName},扣除倍数:{debuct_factor}");
       
 
          else if (swCustBend.Type==3&& (a2d < 1.6 || a2d > 1.8))  
              Console.WriteLine($"k因子错误,{modelname}+{FeatureName},补偿换扣除:{a2d}");
        else if (BendRadius <2 &swCustBend.Type==2&& (k2d < 1.6 || k2d > 1.8))  
              Console.WriteLine($"k因子错误,{modelname}+{FeatureName}, k因子换扣除:{k2d}");
        else if(Math.Abs(angle-90)>0.5)
            Console.WriteLine($"非90度折弯,{modelname}+{FeatureName}");
        else
        {
            Debug.Print("      扣除倍数      = " + debuct_factor);
            Debug.Print("      补偿换扣除 = " + a2d);
            Debug.Print("      k因子换扣除 = " + k2d);
            return;
        }
        Debug.Print("      BendAllowance    = " + swCustBend.BendAllowance * 1000.0 + " mm");
        Debug.Print("      BendDeduction    = " + swCustBend.BendDeduction * 1000.0 + " mm");
        Debug.Print("      BendTableFile    = " + swCustBend.BendTableFile);
        Debug.Print("      KFactor          = " + swCustBend.KFactor);
        Debug.Print("      Type             = " + swCustBend.Type);
        Debug.Print("      thickness            = " + thickness);
        Debug.Print("      Radius = " + BendRadius + " mm");

    }
  
    public static void Process_OneBend(SldWorks swApp, ModelDoc2 swModel, Feature swFeat,double  thickness)
    {
        Debug.Print("    +" + swFeat.Name + " [" + swFeat.GetTypeName() + "]");

        OneBendFeatureData swOneBend = default(OneBendFeatureData);
        CustomBendAllowance swCustBend = default(CustomBendAllowance);

        swOneBend = (OneBendFeatureData)swFeat.GetDefinition();
        swCustBend = swOneBend.GetCustomBendAllowance(); 
        var angle=Math.Round(swOneBend.BendAngle* 180.0 / Math.PI,2);
        


        Process_CustomBendAllowance( swModel.GetTitle(),swCustBend, swOneBend.BendRadius*1000.0,swFeat.Name ,thickness,angle);

    }


    static public void run(SldWorks swApp, ModelDoc2 swModel)
    {
        var partdoc = (PartDoc)swModel;
        var bodys = (object[])partdoc.GetBodies2((int)swBodyType_e.swSolidBody, false);

        foreach (var objbody in bodys)
        {
            var body = (Body2)objbody;

            double thickness = 0;
            object[] features = (object[])body.GetFeatures();
            foreach (object objFeature in features)
            {
 
                Feature swFeature = (Feature)objFeature;
                switch (swFeature.GetTypeName())
                {
                    case "SheetMetal":
                        SheetMetalFeatureData swSheetMetalData = (SheetMetalFeatureData)swFeature.GetDefinition();
                        thickness = swSheetMetalData.Thickness * 1000;
                        break;
                }
                var swSubFeat = (Feature)swFeature.GetFirstSubFeature();
 
                while ((swSubFeat != null))
                {
                    switch (swSubFeat.GetTypeName())
                    {
                      
                            
                         
                        case "OneBend":
                            Process_OneBend(swApp, swModel, swSubFeat, thickness);

                            break;

                    }

                    swSubFeat = (Feature)swSubFeat.GetNextSubFeature();
                }







            }
        }
    }
}
相关推荐
xushichao19894 小时前
C++中的工厂模式高级应用
开发语言·c++·算法
SuperEugene4 小时前
Vue3 + Element Plus 表格实战:批量操作、行内编辑、跨页选中逻辑统一|表单与表格规范篇
开发语言·前端·javascript
2501_924952694 小时前
C++模块化编程指南
开发语言·c++·算法
2401_831920744 小时前
基于C++的爬虫框架
开发语言·c++·算法
1104.北光c°4 小时前
深入浅出 Elasticsearch:从搜索框到精准排序的架构实战
java·开发语言·elasticsearch·缓存·架构·全文检索·es
weixin_421922694 小时前
模板元编程性能分析
开发语言·c++·算法
2401_851272994 小时前
C++中的类型擦除技术
开发语言·c++·算法
左左右右左右摇晃4 小时前
Java并发——并发编程底层原理
java·开发语言
Liu628884 小时前
C++命名空间使用规范
开发语言·c++·算法