本节主要讲如何创建直线的平行关联直线,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的录制功能编写的创建的平行关联直线