/*****************************************************************************
**
** NXOpen_Wizard19.c
**
** Description:
** Contains Unigraphics entry points for the application.
**
*****************************************************************************/
/* Include files */
#include <stdarg.h>
#include <stdio.h>
#include <uf.h>
#include <uf_ui_types.h>
#include <uf_ui.h>
#include <uf_assem.h>
#include <uf_ncgroup.h>
#include <uf_setup.h>
#include <uf_ui_ont.h>
#include <uf_obj.h>
#include <uf_oper.h>
static void ECHO(char *format, ...)
{
char msg[UF_UI_MAX_STRING_BUFSIZE];
va_list args;
va_start(args, format);
vsnprintf_s(msg, sizeof(msg), _TRUNCATE, format, args);
va_end(args);
UF_UI_open_listing_window();
UF_UI_write_listing_window(msg);
UF_print_syslog(msg, FALSE);
}
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
static int report_error( char *file, int line, char *call, int irc)
{
if (irc)
{
char err[133];
UF_get_fail_message(irc, err);
ECHO("*** ERROR code %d at line %d in %s:\n",
irc, line, file);
ECHO("+++ %s\n", err);
ECHO("%s;\n", call);
}
return(irc);
}
/*****************************************************************************
** Activation Methods
*****************************************************************************/
/* Explicit Activation
** This entry point is used to activate the application explicitly, as in
** "File->Execute UG/Open->User Function..." */
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
/* Initialize the API environment */
if( UF_CALL(UF_initialize()) )
{
/* Failed to initialize */
return;
}
/* TODO: Add your application code here */
//创建加工设置
UF_SETUP_create(UF_ASSEM_ask_work_part(), "mill_planar");
//获取当前NX的加工设置TAG
tag_t setup_tag = NULL_TAG;
UF_SETUP_ask_setup(&setup_tag);
if (setup_tag == NULL_TAG)
{
uc1601("提示:请先初始化加工环境!", 1);
return;
}
//获取几何视图的根节点
tag_t geom_group = NULL_TAG;
UF_SETUP_ask_geom_root(setup_tag, &geom_group);
//创建加工坐标系
tag_t mcsTag = NULL_TAG;
UF_NCGEOM_create("mill_planar", "MCS", &mcsTag);
//添加成员
UF_NCGROUP_accept_member(geom_group, mcsTag);
//修改加工坐标系的名称
UF_OBJ_set_name(mcsTag, "MyMCS");
//创建几何体
tag_t workpieceTag = NULL_TAG;
UF_NCGEOM_create("mill_planar", "WORKPIECE", &workpieceTag);
//添加workpiece到加工坐标系下
UF_NCGROUP_accept_member(mcsTag, workpieceTag);
//修改workpiece的名称
UF_OBJ_set_name(workpieceTag, "MyWorkPiece");
//获取程序视图的根节点
tag_t prog_group = NULL_TAG;
UF_SETUP_ask_program_root(setup_tag, &prog_group);
//创建操作
tag_t operTag = NULL_TAG;
UF_OPER_create("mill_contour", "CAVITY_MILL", &operTag);
//添加成员
UF_NCGROUP_accept_member(prog_group, operTag);
//修改加工坐标系的名称
UF_OBJ_set_name(operTag, "Myoper");
//刷新加工导航器
UF_UI_ONT_refresh();
/* Terminate the API environment */
UF_CALL(UF_terminate());
}
/*****************************************************************************
** Utilities
*****************************************************************************/
/* Unload Handler
** This function specifies when to unload your application from Unigraphics.
** If your application registers a callback (from a MenuScript item or a
** User Defined Object for example), this function MUST return
** "UF_UNLOAD_UG_TERMINATE". */
extern int ufusr_ask_unload( void )
{
return( UF_UNLOAD_IMMEDIATELY );
}