UG二次开发 创建圆柱和简单孔UF_MODL_create_simple_hole

本实例主要实现了通过ufun创建圆柱和简单孔,主要使用了一下几个ufun函数:

theUFSession.Modl.CreateCyl1  创建圆柱

theUFSession.Modl.AskFeatFaces  获取面列表

theUFSession.Modl.CreateSimpleHole  创建简单孔

最终实现效果图如下:

 一、主程序

先看实现简单孔的主程序如下:

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

public class Program
{
    private static Session theSession;
    private static UFSession theUFSession;
    public static Program theProgram;
    private static UI theUI = null;
    public static int Main(string[] args)
    {
        theUI = UI.GetUI();
        int retValue = 0;
        try
        {
            #region 简单孔
            double[] origin = new double[3] { 0.0, 0.0, 0.0 };
            double[] direction = new double[3] { 0.0, 0.0, 1.0 };
            string height = "10";
            string diam = "50";
            Tag cylTag = ModlHelper.CreateCylinder(origin, height, diam, direction);

            double[] location = new double[3]{0, 0, 20};
            double[] direction1 = new double[3] { 0.0, 0.0, -1.0 };
            diam = "20";
            string depth = "100";
            string angle = "0";

            theUFSession = UFSession.GetUFSession();
            Tag[] face_list;
            int count;
            theUFSession.Modl.AskFeatFaces(cylTag, out face_list);
            theUFSession.Modl.AskListCount(face_list, out count);
            for (int i = 0; i < count; i++)
            {
                Tag faceTag;
                theUFSession.Modl.AskListItem(face_list, i ,out faceTag);
                theUFSession.Obj.SetName(faceTag,"face"+i);
            }
            Tag placement_face, thru_face;
            theUFSession.Modl.AskListItem(face_list, 0, out placement_face);
            theUFSession.Modl.AskListItem(face_list, 2, out thru_face);
            ModlHelper.CreateSimpleHole(location, direction1, diam, depth, angle, placement_face, thru_face);
            #endregion
        }
        catch (NXOpen.NXException ex)
        {
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
        }
        return retValue;
    }
}

根据主程序的思路,简单孔的实现分一下几步:

1、先创建一个圆柱

2、获取圆柱的上、下两个面,用来打孔

     这里获取圆柱的上下面有一个技巧,使用了theUFSession.Obj.SetName给圆柱的每一个面做了name标记,所以才把face_list编号0和2的面赋值给placement_face、thru_face。 如果这两个面弄错了是无法正常打孔的。

3、初始化打孔需要的参数:孔位置、方向向量、直径、孔深、尖角角度、孔开始面、孔结束面  

二、创建圆柱方法

/// <summary>
/// 创建圆柱体
/// </summary>
/// <param name="origin">原点</param>
/// <param name="height">高度</param>
/// <param name="diam">直径</param>
/// <param name="direction">方向向量</param>
/// <returns></returns>
public static Tag CreateCylinder(double[] origin, string height, string diam, double[] direction)
{
    theUFSession = UFSession.GetUFSession();
    FeatureSigns signs = FeatureSigns.Nullsign;
    Tag cylTag;
    theUFSession.Modl.CreateCyl1(signs, origin, height, diam, direction, out cylTag);
    return cylTag;
}

创建圆柱使用了ufun函数:theUFSession.Modl.CreateCyl1

有原点、圆柱的高度、直径、方向向量即可创建 

三、创建简单孔的方法

/// <summary>
/// 创建简单孔
/// </summary>
/// <param name="location">孔位置</param>
/// <param name="direction">方向向量</param>
/// <param name="diame">直径</param>
/// <param name="depth">孔深</param>
/// <param name="angle">尖角角度</param>
/// <param name="face_li">孔开始面(尾)</param>
/// <param name="face_t1">孔结束面(头)</param>
/// <returns></returns>
public static Tag CreateSimpleHole(double[] location, double[] direction, string diame, string depth, string angle, Tag face_li, Tag face_t1)
{
    theUFSession = UFSession.GetUFSession();
    Tag holeTag;
    theUFSession.Modl.CreateSimpleHole(location, direction, diame, depth, angle, face_li, face_t1, out holeTag);
    return holeTag;
}

创建简单孔使用了ufun函数:theUFSession.Modl.CreateSimpleHole

主要使用参数有:孔位置、方向向量、直径、孔深、尖角角度、孔开始面、孔结束面  

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

MarcoPro

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

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

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

打赏作者

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

抵扣说明:

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

余额充值