NX二次开发(C#)-建模-通过起始点终止点圆弧半径创建圆弧

Posted NX二次开发专注者

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NX二次开发(C#)-建模-通过起始点终止点圆弧半径创建圆弧相关的知识,希望对你有一定的参考价值。

然NX二次开发创建的函数有很多个,为了能正确获得圆弧的起始终止角度,本文根据起始点、终止点和圆弧半径创建圆弧。其方法实现如下:

AssociativeArcBuilder1是创建关联圆弧的类;

首先:创建一个 associativeArcBuilder1实例,当然前期是空的,是属于BaseFeatures空间的一个类实例。

  NXOpen.Features.AssociativeArc nullNXOpen_Features_AssociativeArc = null;

            NXOpen.Features.AssociativeArcBuilder associativeArcBuilder1;
            associativeArcBuilder1 = workPart.BaseFeatures.CreateAssociativeArcBuilder(nullNXOpen_Features_AssociativeArc);

然后:创建圆弧所在的平面Plane1。这个平面包括了点和平面法矢。注意:点是属于圆弧平面的。

NXOpen.Plane plane1;

            plane1 = workPart.Planes.CreatePlane(origionPoint3D, planVector3D, NXOpen.SmartObject.UpdateOption.WithinModeling);

            plane1.RemoveOffsetData();

            plane1.Evaluate();

 再者:将AssociativeArcBuilder1包含的部分属性附上,如起始点约束类型、终止点约束类型,半径约束、圆弧角度约束等。

这些都要设置的,不然出来的圆弧可能很诡异。

NXOpen.Unit unit1;
            unit1 = associativeArcBuilder1.Radius.Units;

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

            associativeArcBuilder1.Limits.StartLimit.LimitOption = NXOpen.GeometricUtilities.CurveExtendData.LimitOptions.AtPoint;
    
            associativeArcBuilder1.Limits.EndLimit.LimitOption = NXOpen.GeometricUtilities.CurveExtendData.LimitOptions.AtPoint;

            plane1.SetMethod(NXOpen.PlaneTypes.MethodType.PointDir);

            Point point2 = workPart.Points.CreatePoint(startPoint3D);

            associativeArcBuilder1.StartPoint.Value = point2;

            associativeArcBuilder1.StartPointOptions = NXOpen.Features.AssociativeArcBuilder.StartOption.Point;


            Point point4 = workPart.Points.CreatePoint(endPoint3D);

            associativeArcBuilder1.EndPoint.Value = point4;

            associativeArcBuilder1.EndPointOptions = NXOpen.Features.AssociativeArcBuilder.EndOption.Point;

            associativeArcBuilder1.Radius.RightHandSide = radius.ToString();

            associativeArcBuilder1.Diameter.RightHandSide = (radius * 2).ToString();

            associativeArcBuilder1.MidPointOptions = NXOpen.Features.AssociativeArcBuilder.MidOption.Radius;

            associativeArcBuilder1.Limits.StartLimit.Distance.RightHandSide = "0";

            associativeArcBuilder1.Limits.EndLimit.Distance.RightHandSide = angle.ToString();         

            associativeArcBuilder1.SupportPlaneData.SupportPlane = plane1;

            associativeArcBuilder1.Limits.StartLimit.Distance.RightHandSide = "0";

            associativeArcBuilder1.Limits.EndLimit.Distance.RightHandSide = angle.ToString();
            
            associativeArcBuilder1.ZonePoint = helpPoint3D;

最后,实现 AssociativeArcBuilder1的创建,即:

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

当然想读取出圆弧的特征,采用下面的方法实现:

AssociativeArc associativeArc = (AssociativeArc)nXObject1;
            arc = (Arc)associativeArc.GetEntities()[0];      

 

下面是完整的方法实现代码:

   public static void CreateArc(Point3d origionPoint3D, Vector3d planVector3D, Point3d startPoint3D, Point3d endPoint3D, NXOpen.Point3d helpPoint3D, double radius, double angle, out Arc arc)
        {
            NXOpen.Features.AssociativeArc nullNXOpen_Features_AssociativeArc = null;

            NXOpen.Features.AssociativeArcBuilder associativeArcBuilder1;
            associativeArcBuilder1 = workPart.BaseFeatures.CreateAssociativeArcBuilder(nullNXOpen_Features_AssociativeArc);
    
            NXOpen.Plane plane1;

            plane1 = workPart.Planes.CreatePlane(origionPoint3D, planVector3D, NXOpen.SmartObject.UpdateOption.WithinModeling);

            plane1.RemoveOffsetData();

            plane1.Evaluate();

            NXOpen.Unit unit1;
            unit1 = associativeArcBuilder1.Radius.Units;

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

            associativeArcBuilder1.Limits.StartLimit.LimitOption = NXOpen.GeometricUtilities.CurveExtendData.LimitOptions.AtPoint;
    
            associativeArcBuilder1.Limits.EndLimit.LimitOption = NXOpen.GeometricUtilities.CurveExtendData.LimitOptions.AtPoint;

            plane1.SetMethod(NXOpen.PlaneTypes.MethodType.PointDir);

            Point point2 = workPart.Points.CreatePoint(startPoint3D);

            associativeArcBuilder1.StartPoint.Value = point2;

            associativeArcBuilder1.StartPointOptions = NXOpen.Features.AssociativeArcBuilder.StartOption.Point;


            Point point4 = workPart.Points.CreatePoint(endPoint3D);

            associativeArcBuilder1.EndPoint.Value = point4;

            associativeArcBuilder1.EndPointOptions = NXOpen.Features.AssociativeArcBuilder.EndOption.Point;

            associativeArcBuilder1.Radius.RightHandSide = radius.ToString();

            associativeArcBuilder1.Diameter.RightHandSide = (radius * 2).ToString();

            associativeArcBuilder1.MidPointOptions = NXOpen.Features.AssociativeArcBuilder.MidOption.Radius;

            associativeArcBuilder1.Limits.StartLimit.Distance.RightHandSide = "0";

            associativeArcBuilder1.Limits.EndLimit.Distance.RightHandSide = angle.ToString();         

            associativeArcBuilder1.SupportPlaneData.SupportPlane = plane1;

            associativeArcBuilder1.Limits.StartLimit.Distance.RightHandSide = "0";

            associativeArcBuilder1.Limits.EndLimit.Distance.RightHandSide = angle.ToString();
            
            associativeArcBuilder1.ZonePoint = helpPoint3D;

            NXOpen.NXObject nXObject1;
            nXObject1 = associativeArcBuilder1.Commit();
            AssociativeArc associativeArc = (AssociativeArc)nXObject1;
            arc = (Arc)associativeArc.GetEntities()[0];         

            NXOpen.Expression expression24 = associativeArcBuilder1.Radius;
            associativeArcBuilder1.Destroy();           
        }

下面是一个圆弧的设置:

  #region  创建圆弧
                    Point3d origionPoint3D = new Point3d(0, 0, 0);
                    Point3d startPoint3D1 = new Point3d(0, 1000, 0);
                    Point3d endPoint3D = new Point3d(1000, 0, 0);
                    Point3d helpPoint3D = new Point3d(292.893218813, 292.893218813, 0);
                    Vector3d planeVector3D = new Vector3d(0, 0, 1);

                    double radius1 = 1000;
                    double angle = 90;
                    Arc arc = null;
                    CreateArc(origionPoint3D, planeVector3D, startPoint3D1, endPoint3D, helpPoint3D, radius1, angle, out arc);
                    #endregion

实现的效果如下:

 

以上是关于NX二次开发(C#)-建模-通过起始点终止点圆弧半径创建圆弧的主要内容,如果未能解决你的问题,请参考以下文章

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

NX二次开发(C#)-建模-圆弧边对象转化为圆弧对象

UG NX二次开发(C#)-建模-创建填充曲面(CreateFillHoleBuilder)

NX二次开发-UFUN三点创建圆弧UF_CURVE_create_arc_thru_3pts

NX二次开发(C#)-建模-参数化模型自动修改

UG NX二次开发(C#)-UI Styler-批量选择点