zoukankan      html  css  js  c++  java
  • NX二次开发-NXOPEN C#UF布尔求交theUfSession.Modl.IntersectBodies

    NX9+VS2012
    
    using System;
    using NXOpen;
    using NXOpen.UF;
    using NXOpenUI;
    using NXOpen.Utilities;
    
    
    
    //获取WCS
    Tag WcsId = Tag.Null;
    theUfSession.Csys.AskWcs(out WcsId);
    
    //获取WCS的矩阵和原点
    Tag MatrixId = Tag.Null;
    double[] CsysOrigin = new Double[3];
    theUfSession.Csys.AskCsysInfo(WcsId, out MatrixId, CsysOrigin);
    
    //画两个整圆
    UFCurve.Arc HoleArcCoords1 = new UFCurve.Arc();
    HoleArcCoords1.matrix_tag = MatrixId;
    HoleArcCoords1.start_angle = 0 * UFConstants.DEGRA;
    HoleArcCoords1.end_angle = 360 * UFConstants.DEGRA;
    HoleArcCoords1.arc_center = new Double[3];
    HoleArcCoords1.arc_center[0] = 0.0;
    HoleArcCoords1.arc_center[1] = 0.0;
    HoleArcCoords1.arc_center[2] = 0.0;
    HoleArcCoords1.radius = 100;
    Tag HoleArcTag1 = Tag.Null;
    theUfSession.Curve.CreateArc(ref HoleArcCoords1, out HoleArcTag1);
    
    UFCurve.Arc HoleArcCoords2 = new UFCurve.Arc();
    HoleArcCoords2.matrix_tag = MatrixId;
    HoleArcCoords2.start_angle = 0 * UFConstants.DEGRA;
    HoleArcCoords2.end_angle = 360 * UFConstants.DEGRA;
    HoleArcCoords2.arc_center = new Double[3];
    HoleArcCoords2.arc_center[0] = 0.0;
    HoleArcCoords2.arc_center[1] = 0.0;
    HoleArcCoords2.arc_center[2] = 0.0;
    HoleArcCoords2.radius = 120;
    Tag HoleArcTag2 = Tag.Null;
    theUfSession.Curve.CreateArc(ref HoleArcCoords2, out HoleArcTag2);
    
    //创建链表
    Tag[] ArcList = new Tag[2];
    theUfSession.Modl.CreateList(out ArcList);
    
    //插入对象到链表
    theUfSession.Modl.PutListItem(ref ArcList, HoleArcTag1);
    theUfSession.Modl.PutListItem(ref ArcList, HoleArcTag2);
    
    //创建拉伸
    string[] HoleLimit = { "0.0", "50.0" };
    double[] HolePoint = { 0.0, 0.0, 0.0 };
    double[] HoleDirection = { 0.0, 0.0, 1.0 };
    Tag[] HoleExtrudedTag = new Tag[1];
    theUfSession.Modl.CreateExtruded(ArcList, "0", HoleLimit, HolePoint, HoleDirection, FeatureSigns.Nullsign, out HoleExtrudedTag);
    
    //特征找体
    Tag HoleBodyTag = Tag.Null;
    theUfSession.Modl.AskFeatBody(HoleExtrudedTag[0], out HoleBodyTag);
    
    //创建颜色
    theUfSession.Obj.SetColor(HoleBodyTag, 186);
    
    //设置透明度
    theUfSession.Obj.SetTranslucency(HoleBodyTag, 60);
    
    //画一个整圆
    UFCurve.Arc ToolMoveArcCoords1 = new UFCurve.Arc();
    ToolMoveArcCoords1.matrix_tag = MatrixId;
    ToolMoveArcCoords1.start_angle = 0 * UFConstants.DEGRA;
    ToolMoveArcCoords1.end_angle = 360 * UFConstants.DEGRA;
    ToolMoveArcCoords1.arc_center = new Double[3];
    ToolMoveArcCoords1.arc_center[0] = 120;
    ToolMoveArcCoords1.arc_center[1] = 0.0;
    ToolMoveArcCoords1.arc_center[2] = 0.0;
    ToolMoveArcCoords1.radius = 60;
    Tag ToolMoveArcTag1 = Tag.Null;
    theUfSession.Curve.CreateArc(ref ToolMoveArcCoords1, out ToolMoveArcTag1);
    
    //创建链表
    Tag[] ToolMoveArcList;
    theUfSession.Modl.CreateList(out ToolMoveArcList);
    
    //插入对象到链表
    theUfSession.Modl.PutListItem(ref ToolMoveArcList, ToolMoveArcTag1);
    
    //创建拉伸
    string[] ToolMoveLimit = { "0.0", "50.0" };
    double[] ToolMovePoint = { 0.0, 0.0, 0.0 };
    double[] ToolMoveDirection = { 0.0, 0.0, 1.0 };
    Tag[] ToolMoveExtrudedTag;
    theUfSession.Modl.CreateExtruded(ToolMoveArcList, "0", ToolMoveLimit, ToolMovePoint, ToolMoveDirection, FeatureSigns.Nullsign, out ToolMoveExtrudedTag);
    
    //特征找体
    Tag ToolMoveBodyTag = Tag.Null;
    theUfSession.Modl.AskFeatBody(ToolMoveExtrudedTag[0], out ToolMoveBodyTag);
    
    //创建颜色
    theUfSession.Obj.SetColor(ToolMoveBodyTag, 211);
    
    //布尔求交
    int NumResult = 0;
    Tag[] ResultingBodies;
    theUfSession.Modl.IntersectBodies(ToolMoveBodyTag, HoleBodyTag, out NumResult, out ResultingBodies);
    
    
    //获得两个圆曲线的两个交点
    int num_intersections = 0;
    double[] data;
    theUfSession.Modl.IntersectCurveToCurve(HoleArcTag1, ToolMoveArcTag1, out num_intersections, out data);
    
    //创建起点
    double[] FirstPoint = { data[0], data[1], data[2] };
    
    //创建中点
    double[] SecondPoint = { 100, 0, 0 };
    
    //创建终点
    double[] ThirdPoint = { data[5], data[6], data[7] };
    
    //三点创建圆弧
    Tag Thru3ArcTag = Tag.Null;
    theUfSession.Curve.CreateArcThru3pts(1, FirstPoint, SecondPoint, ThirdPoint, out Thru3ArcTag);
    
    //获得圆弧的长度
    NXOpen.Arc arc1 = (NXOpen.Arc)NXObjectManager.Get(Thru3ArcTag);
    double ArcLength = arc1.GetLength();
    
    Caesar卢尚宇
    2020年6月27日

  • 相关阅读:
    c 开发调试汇总
    中级 makefile
    flex
    asp.net的一个重要发现(Page_Load()的执行次序先控件的事件函数)。
    Google App Engine(GAE)入门教程翻译
    类QQ右下角弹出消息对话框(jQuery插件)
    c#过滤HTML代码
    python源码分析2
    asp.net(C#) 编码解码(HtmlEncode与HtmlEncode)
    js操作html的table,包括添加行,添加列,删除行,删除列,合并单元格(未实现)
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/13199887.html
Copyright © 2011-2022 走看看