ug/nx 二次开发(c#) 创建线到平面的投影曲线ufun_marcopro的博客-爱代码爱编程
上篇讲了NXOPEN获取投影曲线,这篇主要讲一下通过ufun来获取线到面的投影曲线,
UG/NX 二次开发(C#) 创建边到平面的投影曲线
先上源码:
public static void Main(string[] args)
{
try
{
theSession = Session.GetSession();
displayPart = theSession.Parts.Display;
theUFSession = UFSession.GetUFSession();
workPart = theSession.Parts.Work;
Body bodyYZHU = (Body)workPart.Bodies.FindObject("BLOCK(1)");
Body bodyYZUI = (Body)workPart.Bodies.FindObject("CONE(2)");
Auto_Init.BodyInit init = new Auto_Init.BodyInit(bodyYZHU);
BodyModel model = init.ProcBody();
Face topface = (Face)NXOpen.Utilities.NXObjectManager.GetObjectFromUInt(uint.Parse(model.faceFlag.faceTop));
Face face3 = (Face)NXOpen.Utilities.NXObjectManager.GetObjectFromUInt(uint.Parse(model.faceFlag.face3));
Tag LineTag = Tag.Null;
theUFSession.Obj.CycleByName("LINE", ref LineTag);
Tag[] cures_refs;
theUFSession.Modl.CreateList(out cures_refs);
theUFSession.Modl.PutListItem(ref cures_refs, LineTag);
Tag[] face_refs;
theUFSession.Modl.CreateList(out face_refs);
theUFSession.Modl.PutListItem(ref face_refs, topface.Tag);
theUFSession.Modl.PutListItem(ref face_refs, face3.Tag);
int along_face = 0; //0=使用投影矢量,1 =使用面法线
double[] proj_vector = new double[3] { 0.0, 0.0, -1.0 }; //投影矢量
Tag projTag;
theUFSession.Modl.CreateProjCurves(cures_refs, face_refs, along_face, proj_vector, out projTag);
}
catch (NXOpen.NXException ex)
{
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
}
这里需要注意的是:
1、ufun获取的是线到面的投影曲线,目前发现圆锥的低边投影会报错
2、当线的投影无法直接落在面上的时候,会报错如下:
NXOPEN这种情况不会报错,会投影到面的外面
运行结果如下: