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();
                }







            }
        }
    }
}
相关推荐
苍狼唤36 分钟前
WinForm练习知识补充(多线程)
c#
2zcode1 小时前
基于MATLAB图像处理的饮料瓶灌装液位检测系统设计与实现
开发语言·图像处理·matlab
必须得开心呀2 小时前
QT解决中文乱码问题
开发语言·qt
这不小天嘛3 小时前
JAVA八股——redis篇
java·开发语言·redis
逝水无殇4 小时前
C# 字符串(String)详解
开发语言·后端·c#
精明的身影4 小时前
C++自学之路1:Hello world
开发语言·c++
leo__5205 小时前
基于导航数据的扩展卡尔曼滤波(EKF)MATLAB 实现
开发语言·matlab
gugucoding5 小时前
25. 【C语言】二进制文件与随机读写
c语言·开发语言
北极星日淘5 小时前
中古货品品相评级算法实战|Java权重计分实现标准化五级品相体系
开发语言·python
小巧的砖头5 小时前
C#会重蹈覆辙吗?系列之2:反射及元数据的性能问题
开发语言·前端·c#