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







            }
        }
    }
}
相关推荐
qq_366086229 分钟前
关于接口路径中中文值解码问题
java·开发语言·数据库
麻瓜老宋12 分钟前
AI开发C语言应用按步走,表达式计算器calc的第二十步,魔法数修复、测试分隔符、位运算截断检查、进制溢出检查
c语言·开发语言·atomcode
向夏威夷 梦断明暄22 分钟前
从 Bun 的 Rust 重写,看 C# 如何重建 AI 基础设施层
人工智能·rust·c#
冻柠檬飞冰走茶29 分钟前
PTA基础编程题目集 7-11 分段计算居民水费(C语言实现)
c语言·开发语言·算法
An_s31 分钟前
Java Spring Boot+vue3文件管理系统
java·开发语言
名字还没想好☜40 分钟前
Go for-range 循环变量陷阱:goroutine 里全打印同一个值(Go 1.22 前后差异)
开发语言·后端·golang·go
倒流时光三十年1 小时前
第一阶段 05 · Java 客户端查询类详解(Query / SearchCriteria / Response 与复杂拼接)
java·开发语言·python
心平气和量大福大1 小时前
C#-WPF-控件-LiveChart图表-线性2(LineSeries)-数据绑定
开发语言·c#·wpf
lingran__1 小时前
C++_stack和queue和priority_queue(容器适配器)
开发语言·c++
::呵呵哒::1 小时前
java中SseEmitter
java·开发语言