NX二次开发UF_add_callback_function 函数介绍

文章作者:里海
来源网站:https://blog.csdn.net/WangPaiFeiXingYuan


UF_add_callback_function

Defined in: uf.h 
int UF_add_callback_function(UF_callback_reason_e_t reason, UF_callback_fn_t fn, void * user_data, UF_registered_fn_p_t * function_id )

overview 概述

Registers the callback to be called whenever the reason specified
occurs within NX.
Please note the following:
Once a routine is registered as a callback, the shared library it
resides in should not be unloaded until it is deregistered.
The callback function must call UF_initialize and UF_terminate, if
it makes any Open C function calls
The callback function receives three arguments:
argument 1 - The reason the callback has been called
argument 2 - A pointer to the part tag that caused the callback.
argument 3 - A user supplied pointer. Typically this will be a
structure pointer of data that the callback function
will need.
The callback will be called towards the end of the processing for that
particular reason. For example, the callback registered against
UF_create_part_reason will be called when a new part is created, after
almost all the process of creating this new part is completed.
The only exception to the above is UF_close_part_reason, for which
the callback will be called at the beginning of closing the part.
NOTE: For the new and open part reasons the callback is run at a time
when the newly created or opened part has not been set as the work part.
Also operations such as create part, open part, save part or change display part
should not be called from callbacks fired by any of these same operations.

每当 NX 中出现指定的原因时,注册要调用的回调。请注意: 一旦某个例程被注册为回调函数,它所在的共享库在注销之前不应卸载。回调函数必须调用 UF _ initialize 和 UF _ finally,如果它调用任何 Open C 函数的话。回调函数接收三个参数: 参数1-回调函数被调用的原因参数2-一个指向引起回调的 part 标记的指针。参数3-用户提供的指针。通常,这将是回调函数需要的数据的结构指针。由于这个特殊原因,回调将在处理结束时调用。例如,根据 UF _ create _ part _ reason 注册的回调将在创建新部件时调用,此时创建新部件的所有过程几乎都已完成。唯一的例外是 UF _ close _ part _ reason,它的回调将在关闭该部分的开始时调用。注意: 由于新创建和打开的部分的原因,回调在新创建或打开的部分尚未设置为工作部分时运行。此外,诸如创建部分、打开部分、保存部分或更改显示部分之类的操作不应该从由这些相同操作中的任何一个触发的回调中调用。

UFUN例子

欢迎订阅《里海NX二次开发3000例专栏》https://blog.csdn.net/wangpaifeixingyuan/category_8840986.html,点击链接扫码即可订阅(持续更新中)。已经有几百人订阅,订阅是永久的,无限期阅读,如需帮助请私信

parameters 参数

UF_callback_reason_e_treasonInputReason to call callback
调用回调的原因
UF_callback_fn_tfnInputFunction to call. Note this function must call UF_initialize if it makes any Open C function calls. It should also call UF_terminate.
要调用的函数。注意,如果这个函数调用任何 Open C 函数,它必须调用 UF _ initialize。它还应该调用 UF _ finally。
void *user_dataInputUser data. This pointer will be passed to your callback function as the third argument. It will typically be a structure pointer with information that your callback function will require.
用户资料。此指针将作为第三个参数传递给回调函数。它通常是一个结构指针,其中包含回调函数所需的信息。
UF_registered_fn_p_t *function_idOutputIdentifier to use to remove callback
用于移除回调的标识符

>>> 返回目录

分割

C++语言在UG二次开发中的应用及综合分析

  1. C++ 是C语言的扩展,它既可以执行C语言的过程化程序设计,也可以进行以抽象数据类型为特点的基于对象的设计,以及面向对象的程序设计。C++ 在处理问题规模上具有很大的适应性。
  2. C++不仅具有计算机高效运行的实用性特征,并且致力于提升大规模程序的编程质量以及程序设计语言的问题描述能力。

在UG二次开发中,C++语言具有以下特点

  1. C++语言支持多种程序设计风格
  2. C++的许多特性以库的形式存在,保证了语言的简洁和开发运行的效率
  3. 与C语言相比,C++引入了面向对象的概念,使得UG二次开发的人机交互界面更加简洁
  4. 通过借助UG自带的2000多种API函数,结合高级语言C++以及编程软件Visual Studio,可以对UG进行二次开发
  5. 需要注意的是,市场上的Visual Studio和UG版本众多,并非所有版本都能兼容

程序设计过程通常包括以下步骤:

  1. 问题分析:对要解决的问题进行深入的分析,理解问题的具体需求和限制。
  2. 需求定义:明确程序的目标和功能,包括用户需求、系统需求等。
  3. 设计:根据需求进行设计,包括算法设计、数据结构设计、界面设计等。
  4. 编码:根据设计的结果,使用一种编程语言将程序代码实现出来。
  5. 测试:通过各种测试方法来确保程序的正确性,包括单元测试、集成测试、系统测试等。
  6. 维护:对程序进行修改和完善,以解决可能出现的问题或满足新的需求。
  7. 文档编写:编写程序文档,描述程序的功能、操作方法、注意事项等。

以下是一个创建体素特征(块、柱、锥、球)的二次开发例子

#include <stdio.h>
#include <stdarg.h>
#include <uf_modl_primitives.h>
#include <uf_ui_ugopen.h>
#include <uf.h>
#include <uf_defs.h>
//封装打印函数,用于将信息打印到信息窗口
//QQ3123197280
int ECHO(const char* szFormat, ...)
{
	char szMsg[5000] = "";
	va_list arg_ptr;
	va_start(arg_ptr, szFormat);
	vsprintf_s(szMsg, szFormat, arg_ptr);
	va_end(arg_ptr);
	UF_UI_open_listing_window();
	
	UF_UI_write_listing_window(szMsg);
	return 0;
}
extern DllExport void ufusr(char* param, int* returnCode, int rlen)
{
	UF_initialize();
	//创建块
	UF_FEATURE_SIGN sign = UF_NULLSIGN;
	//块起点相对于ABS
	double block_orig[3] = { 0.0,0.0,0.0 };
	//方向相对于WCS
	char* block_len[3] = { "10", "30", "10" };
	tag_t blk_obj;//体特征
	UF_MODL_create_block1(sign, block_orig, block_len, &blk_obj);
	int iEdit = 0;  
	char* size[3];
	UF_MODL_ask_block_parms(blk_obj, iEdit, size);
	ECHO("%s,%s,%s\n", size[0], size[1], size[2]);//输出: p6=10,p7=30,p8=10
	//创建圆柱
	UF_FEATURE_SIGN sign1 = UF_NULLSIGN;
	double origin[3] = { 10.0,0.0,10.0 };
	char  height[] = "20";
	char  diam[] = "10";
	double direction[3] = { 0,0,1 };//方向
	tag_t  cyl_obj_id;
	UF_MODL_create_cyl1(sign1, origin, height, diam, direction, &cyl_obj_id);
	int iEdit2 = 0;  
	char* cDiameter;
	char* cHeight;
	UF_MODL_ask_cylinder_parms(cyl_obj_id, iEdit2, &cDiameter, &cHeight);
	ECHO("%s,%s\n", cDiameter, cHeight);//输出:p9=10,p10=20
	UF_free(cDiameter);
	UF_free(cHeight);
	//创建圆锥
	UF_FEATURE_SIGN sign2 = UF_NULLSIGN;
	double origin2[3] = { 0.0,0.0,10.0 };
	char  height2[] = "20";
	char* diam2[2] = { "10" ,"5" };
	double direction2[3] = { 0,0,1 };//方向
	tag_t  cone_obj_id;
	UF_MODL_create_cone1(sign2, origin2, height2, diam2, direction2, &cone_obj_id);
	int iEdit3 = 0;  
	char* cD1;
	char* cD2;
	char* cH;
	char* cAngle;
	UF_MODL_ask_cone_parms(cone_obj_id, iEdit3, &cD1, &cD2, &cH, &cAngle);
	ECHO("%s,%s,%s,%s\n", cD1, cD2, cH, cAngle);//输出:p11=10,p12=5,p13=20,p14=7.1250163489018
	UF_free(cD1);
	UF_free(cD2);
	UF_free(cH);
	UF_free(cAngle);
	//创建球
	UF_FEATURE_SIGN sign3 = UF_NULLSIGN;
	double douCenter2[3] = { 0.0,0.0,30.0 };
	char  cDiam[] = "8";
	tag_t  sphere_obj_id;
	UF_MODL_create_sphere1(sign3, douCenter2, cDiam, &sphere_obj_id);
	int iEdit4 = 0;  
	char* cDiam_parm;
	UF_MODL_ask_sphere_parms(sphere_obj_id, iEdit4, &cDiam_parm);
	ECHO("%s\n", cDiam_parm);//输出:p15=8
	UF_free(cDiam_parm);
	UF_terminate();
}
extern int ufusr_ask_unload(void)
{
	return (UF_UNLOAD_IMMEDIATELY);
}

效果:
效果

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

王牌飞行员_里海

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

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

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

打赏作者

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

抵扣说明:

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

余额充值