UG NX二次开发(C#)-同步建模-删除倒圆(圆角)

Posted GimiGimmy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UG NX二次开发(C#)-同步建模-删除倒圆(圆角)相关的知识,希望对你有一定的参考价值。

删除UG NX模型的圆角代码如下:

public static void ClearBlend(Face []edgeBlendFaces)
    
        NXOpen.Session theSession = NXOpen.Session.GetSession();
        NXOpen.Part workPart = theSession.Parts.Work;
        NXOpen.Part displayPart = theSession.Parts.Display;
        // ----------------------------------------------
        //   菜单:插入(S)->同步建模(Y)->删除面(A)...
        // ----------------------------------------------
        NXOpen.Session.UndoMarkId markId1;
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "起点");

        NXOpen.Features.Feature nullNXOpen_Features_Feature = null;
        NXOpen.Features.DeleteFaceBuilder deleteFaceBuilder1;
        deleteFaceBuilder1 = workPart.Features.CreateDeleteFaceBuilder(nullNXOpen_Features_Feature);

        NXOpen.Point3d origin1 = new NXOpen.Point3d(0.0, 0.0, 0.0);
        NXOpen.Vector3d normal1 = new NXOpen.Vector3d(0.0, 0.0, 1.0);
        NXOpen.Plane plane1;
        plane1 = workPart.Planes.CreatePlane(origin1, normal1, NXOpen.SmartObject.UpdateOption.WithinModeling);

        deleteFaceBuilder1.CapPlane = plane1;

        NXOpen.Unit unit1;
        unit1 = deleteFaceBuilder1.MaxHoleDiameter.Units;

        NXOpen.Expression expression1;
        expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        NXOpen.Expression expression2;
        expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1);

        deleteFaceBuilder1.Type = NXOpen.Features.DeleteFaceBuilder.SelectTypes.FaceEdgeBlend;

        deleteFaceBuilder1.MaxHoleDiameter.SetFormula("5");

        deleteFaceBuilder1.MaxBlendRadius.SetFormula("5");

        deleteFaceBuilder1.DeletePartialBlend = true;

        deleteFaceBuilder1.FaceEdgeBlendPreference = NXOpen.Features.DeleteFaceBuilder.FaceEdgeBlendPreferenceOptions.Cliff;

        deleteFaceBuilder1.Type = NXOpen.Features.DeleteFaceBuilder.SelectTypes.Hole;

        NXOpen.Plane nullNXOpen_Plane = null;
        deleteFaceBuilder1.CapPlane = nullNXOpen_Plane;

        theSession.SetUndoMarkName(markId1, "删除面 对话框");

        NXOpen.SelectionIntentRuleOptions selectionIntentRuleOptions1;
        selectionIntentRuleOptions1 = workPart.ScRuleFactory.CreateRuleOptions();

        selectionIntentRuleOptions1.SetSelectedFromInactive(false);

        //NXOpen.Face[] faces1 = new NXOpen.Face[1];
        //NXOpen.Features.EdgeBlend edgeBlend1 = ((NXOpen.Features.EdgeBlend)workPart.Features.FindObject("BLEND(7)"));
        //NXOpen.Face face1 = ((NXOpen.Face)edgeBlend1.FindObject("FACE 1 (798.5355339059328,452.5,998.5355339059328) BLOCK(6)"));
        //faces1[0] = face1;
        NXOpen.FaceDumbRule faceDumbRule1;
        faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(edgeBlendFaces, selectionIntentRuleOptions1);

        selectionIntentRuleOptions1.Dispose();
        NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1];
        rules1[0] = faceDumbRule1;
        deleteFaceBuilder1.FaceCollector.ReplaceRules(rules1, false);

        deleteFaceBuilder1.DeletePartialBlend = false;

        NXOpen.Session.UndoMarkId markId2;
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "删除面");

        theSession.DeleteUndoMark(markId2, null);

        NXOpen.Session.UndoMarkId markId3;
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "删除面");

        deleteFaceBuilder1.Type = NXOpen.Features.DeleteFaceBuilder.SelectTypes.FaceEdgeBlend;

        NXOpen.NXObject nXObject1;
        nXObject1 = deleteFaceBuilder1.Commit();

        theSession.DeleteUndoMark(markId3, null);

        theSession.SetUndoMarkName(markId1, "删除面");

        deleteFaceBuilder1.Destroy();

        try
        
            // 表达式仍然在使用中。
            workPart.Expressions.Delete(expression2);
        
        catch (NXException ex)
        
            ex.AssertErrorCode(1050029);
        

        try
        
            // 表达式仍然在使用中。
            workPart.Expressions.Delete(expression1);
        
        catch (NXException ex)
        
            ex.AssertErrorCode(1050029);
        

        plane1.DestroyPlane();

        // ----------------------------------------------
        //   菜单:工具(T)->操作记录(J)->停止录制(S)
        // ----------------------------------------------
    

在调用这个函数时,要注意,圆角删除时要一个体一个体的删除,所以调用的代码如下:

  Part workPart = theSession.Parts.Work;
                Body[] bodies = workPart.Bodies.ToArray();
                foreach(var bd in bodies)
                
                    List<Face> blendFaceList = new List<Face>();
                    Feature[] features = bd.GetFeatures();
                    foreach (var fe in features)
                    
                        System.Windows.Forms.MessageBox.Show(fe.FeatureType);
                        if (fe.FeatureType.ToUpper().Contains("BLEND"))
                        
                            Face[] faces = fe.GetFaces();
                            foreach (var fc in faces)
                            
                                blendFaceList.Add(fc);
                            
                        
                                        
                    ClearBlend(blendFaceList.ToArray());
                    

示例如下:

以上是关于UG NX二次开发(C#)-同步建模-删除倒圆(圆角)的主要内容,如果未能解决你的问题,请参考以下文章

UG NX二次开发(C#)--建模--识别曲面类型(圆柱面)

UG NX二次开发(C#)-建模-删除面

UG NX二次开发(C#)-建模-获得NX当前打开的所有part文件

UG NX二次开发(C#)-建模-分割曲线

UG NX二次开发(C#)-建模-分割曲线

UG NX二次开发(C#)-建模-获得点所在的圆弧曲线