UG二次开发 创建平行关联直线

本节主要讲如何创建直线的平行关联直线,UG命令:插入 —> 曲线 —> 直线和圆弧(关联)—>直线(点-平行)。

先看最终效果图:

一、程序逻辑整理

1、创建直线

2、创建直线的平行关联线

二、主程序

using System;
using NXOpen;
using NXOpen.UF;
using NxLibrary;

public class Program
{
    private static Session theSession;
    private static UFSession theUfSession;
    public static Program theProgram;
    public static bool isDisposeCalled;

    public static int Main(string[] args)
    {
        int retValue = 0;
        try
        {
            double[] start = { 0, 0, 0 };
            double[] end = { 1, 1, 1 };
            Tag line1 =  ModlHelper.CreateLine(start,end);
            Point3d startPoint =new Point3d(5, 0.0, 0.0);
            ModlHelper.CerateLinePointParallel(startPoint, line1);
        }
        catch (NXOpen.NXException ex)
        {

        }
        return retValue;
    }
}

1、通过start、end两个指定点创建直线,Tag line1 =  ModlHelper.CreateLine(start,end);

2、通过指定点startPoint =new Point3d(5, 0.0, 0.0),和指定的直线line1,创建平行直线ModlHelper.CerateLinePointParallel(startPoint, line1); 

 三、两点创建直线方法

        /// <summary>
        /// 两点创建一条直线
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        public static Tag CreateLine(double[] start, double[] end)
        {
            theUFSession = UFSession.GetUFSession();
            UFCurve.Line line_coords = new UFCurve.Line();
            line_coords.start_point = start;
            line_coords.end_point = end;
            Tag line = Tag.Null;
            theUFSession.Curve.CreateLine(ref line_coords, out line);
            return line;
        }

 通过ufun函数theUFSession.Curve.CreateLine(ref line_coords, out line),实现两点创建直线

四、创建直线的平行关联直线 

        /// <summary>
        /// 创建直线的平行关联直线
        /// </summary>
        /// <param name="start">起始点</param>
        /// <param name="line">参考直线</param>
        /// <returns></returns>
        public static Tag CerateLinePointParallel(Point3d start,Tag line)
        {
            theSession = Session.GetSession();
            workPart = theSession.Parts.Work;
            NXOpen.Features.AssociativeLine nullFeatures_AssociativeLine = null;
            NXOpen.Features.AssociativeLineBuilder associativeLineBuilder1;
            associativeLineBuilder1 = workPart.BaseFeatures.CreateAssociativeLineBuilder(nullFeatures_AssociativeLine);
            associativeLineBuilder1.Limits.StartLimit.Distance.RightHandSide = "0";
            associativeLineBuilder1.StartPointOptions = NXOpen.Features.AssociativeLineBuilder.StartOption.Point;
            associativeLineBuilder1.EndPointOptions = NXOpen.Features.AssociativeLineBuilder.EndOption.AtAngle;
            associativeLineBuilder1.StartPointOptions = NXOpen.Features.AssociativeLineBuilder.StartOption.Inferred;
            associativeLineBuilder1.EndPointOptions = NXOpen.Features.AssociativeLineBuilder.EndOption.Inferred;
            associativeLineBuilder1.Limits.StartLimit.LimitOption = NXOpen.GeometricUtilities.CurveExtendData.LimitOptions.AtPoint;
            associativeLineBuilder1.Limits.StartLimit.Distance.RightHandSide = "0";
            associativeLineBuilder1.Limits.EndLimit.LimitOption = NXOpen.GeometricUtilities.CurveExtendData.LimitOptions.AtPoint;
            associativeLineBuilder1.Limits.EndLimit.Distance.RightHandSide = "0";
            associativeLineBuilder1.StartPointOptions = NXOpen.Features.AssociativeLineBuilder.StartOption.Point;
            associativeLineBuilder1.Limits.FullCircle = false;
            Point point1;
            //Point3d point = new Point3d(5, 0.0, 0.0);
            point1 = workPart.Points.CreatePoint(start);
            associativeLineBuilder1.StartPoint.Value = point1;
            associativeLineBuilder1.EndPointOptions = NXOpen.Features.AssociativeLineBuilder.EndOption.AtAngle;
            associativeLineBuilder1.Limits.EndLimit.LimitOption = NXOpen.GeometricUtilities.CurveExtendData.LimitOptions.Value;
            associativeLineBuilder1.Limits.FullCircle = false;
            associativeLineBuilder1.Limits.StartLimit.Distance.RightHandSide = "0";
            //Line line1 = (Line)workPart.Lines.FindObject("ENTITY 3 1 1");
            Line line1 = (Line)NXOpen.Utilities.NXObjectManager.Get(line);
            associativeLineBuilder1.AtAngle.Value = line1;
            associativeLineBuilder1.Limits.FullCircle = false;
            associativeLineBuilder1.Limits.StartLimit.Distance.RightHandSide = "0";
            associativeLineBuilder1.Limits.EndLimit.Distance.RightHandSide = "2.5";
            associativeLineBuilder1.Associative = true;
            NXObject nXObject1;
            nXObject1 = associativeLineBuilder1.Commit();
            associativeLineBuilder1.Destroy();
            return nXObject1.Tag;
        }

这里是使用Nxopen的方法通过ug的录制功能编写的创建的平行关联直线

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MarcoPro

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值