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







            }
        }
    }
}
相关推荐
勿忘,瞬间1 天前
多线程之进阶修炼
java·开发语言
hoiii1871 天前
CSTR反应器模型的Simulink-PID仿真(MATLAB实现)
开发语言·matlab
炘爚1 天前
C++ 右值引用与程序优化
开发语言·c++
si莉亚1 天前
ROS2安装EVO工具包
linux·开发语言·c++·开源
清心歌1 天前
CopyOnWriteArrayList 实现原理
java·开发语言
良木生香1 天前
【C++初阶】C++入门相关知识(2):输入输出 & 缺省参数 & 函数重载
开发语言·c++
忘梓.1 天前
墨色规则与血色节点:C++红黑树设计与实现探秘
java·开发语言·c++
hhh3u3u3u1 天前
Visual C++ 6.0中文版安装包下载教程及win11安装教程
java·c语言·开发语言·c++·python·c#·vc-1
星河耀银海1 天前
C++ 模板进阶:特化、萃取与可变参数模板
java·开发语言·c++
cccccc语言我来了1 天前
【C++---unordered_set/map底层封装】个不拘一格的集合。它不似有序集合那般循规蹈矩,而是以一种洒脱不羁的方式,将元素们随意地散落其中。每一个元素都是独一无二的。
开发语言·c++·哈希算法