NX二开ufun函数UF_MODL_ask_bounding_box(获取边界坐标)

这个函数用来返回线框和实体类型对象的边界框。
线框对象包括直线,圆弧,样条曲线和圆锥曲线。实体类型对象包括实体 ,面和边。

返回结果如下图,分别返回了曲线和一个block的边界信息:

1、函数结构: 

int UF_MODL_ask_bounding_box (tag_t obj_tag,double bounding_box [6])

2、概述

返回线框和实体类型对象的边界框。 
线框对象包括直线,圆弧,样条曲线和圆锥曲线。实体类型对象包括实体 ,面和边。
根据零件文件中对象的位置,以绝对坐标值返回 边界框值 。

3、实例源码

1)C# 实例源码

using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Features;

public class Program
{
    // class members
    public static Session theSession;
    public static NXOpen.UF.UFSession theUFSession;
    private static UI theUI = null;
    public static Part workPart;
    public static int Main(string[] args)
    {
        theSession = Session.GetSession();
        theUFSession = UFSession.GetUFSession();
        theUI = UI.GetUI();
        workPart = theSession.Parts.Work;
        int retValue = 0;
        try
        {
            Tag arc, wcs;
            UFCurve.Arc arc_coords = new UFCurve.Arc();
            arc_coords.start_angle = 0.0;
            arc_coords.end_angle = 3.0;
            arc_coords.arc_center = new double[3];
            arc_coords.arc_center[0] = 0.0;
            arc_coords.arc_center[1] = 0.0;
            arc_coords.arc_center[2] = 1.0;
            arc_coords.radius = 2.0;
            theUFSession.Csys.AskWcs(out wcs);
            theUFSession.Csys.AskMatrixOfObject(wcs, out arc_coords.matrix_tag);
            theUFSession.Curve.CreateArc(ref arc_coords, out arc);

            FeatureSigns sign = 0;
            double[] corner = new double[3]{0.0, 0.0, 0.0};
            string[] edgeLen = new string[3] {"100","80","50"};
            Tag blockTag = Tag.Null;
            theUFSession.Modl.CreateBlock1(sign, corner, edgeLen, out blockTag);
            Tag blockBodyTag = Tag.Null;
            theUFSession.Modl.AskFeatBody(blockTag, out blockBodyTag);

            double[] boxArc = new double[6];
            theUFSession.Modl.AskBoundingBox(arc, boxArc);

            double[] boxBlock = new double[6];
            theUFSession.Modl.AskBoundingBox(blockBodyTag, boxBlock);
        }
        catch (NXOpen.NXException ex)
        {
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
        }
        return retValue;
    }
}

2)C++实例源码

#include <stdio.h>
#include <uf.h>
#include <uf_part.h>
#include <uf_curve.h>
#include <uf_modl.h>
#include <uf_csys.h>
#include <uf_defs.h>
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
static int report( char *file, int line, char *call, int irc)
{
  if (irc)
  {
     char    messg[133];
     printf("%s, line %d:  %s\n", file, line, call);
     (UF_get_fail_message(irc, messg)) ?
       printf("    returned a %d\n", irc) :
       printf("    returned error %d:  %s\n", irc, messg);
  }
  return(irc);
}
static void do_ugopen_api(void)
{
  char *part_name = "bound";
  tag_t part, arc_id, wcs_tag;
  double box[6];
  UF_CURVE_arc_t arc_coords;

  /* Fill out the data structure */
  arc_coords.start_angle = 0.0;
  arc_coords.end_angle = 270.0 * DEGRA;
  arc_coords.arc_center[0] = 0.0;
  arc_coords.arc_center[1] = 0.0;
  arc_coords.arc_center[2] = 1.0;
  arc_coords.radius = 2.0;
  UF_PART_new(part_name, UF_PART_ENGLISH, &part);
  UF_CSYS_ask_wcs( &wcs_tag );
  UF_CSYS_ask_matrix_of_object( wcs_tag,&arc_coords.matrix_tag );

  /* Create arc */

  UF_CURVE_create_arc(&arc_coords,&arc_id);

  /* Ask bounding box of arc */

  UF_MODL_ask_bounding_box(arc_id,box);
  /* Print bounding box values */
  printf("\nMinimum x value: %f\n", box[0]);
  printf("Maximum x value: %f\n", box[3]);
  printf("Minimum y value: %f\n", box[1]);
  printf("Maximum y value: %f\n", box[4]);
  printf("Minimum z value: %f\n", box[2]);
  printf("Maximum z value: %f\n", box[5]);
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int param_len)
{
  if (!UF_CALL(UF_initialize()))
  {
    do_ugopen_api();
    UF_CALL(UF_terminate());
  }
}
int ufusr_ask_unload(void)
{
  return (UF_UNLOAD_IMMEDIATELY);
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

MarcoPro

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

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

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

打赏作者

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

抵扣说明:

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

余额充值