/*****************************************************************************
**
** Tool_Assemble_External.cpp
**
** Description:
** Main file for the application.
**
*****************************************************************************/
/* Include files */
#include <stdarg.h>
#include <strstream>
#include <iostream>
using std::ostrstream;
using std::endl;
using std::ends;
using std::cerr;
#include <uf.h>
#include <uf_ui.h>
#include <uf_modl.h>
#include <uf_part.h>
#include <uf_cfi.h>
#include <uf_assem.h>
static void ECHO(char *format, ...)
{
char msg[UF_UI_MAX_STRING_NCHARS+1];
va_list args;
va_start(args, format);
vsnprintf_s(msg, sizeof(msg), UF_UI_MAX_STRING_NCHARS, format, args);
va_end(args);
printf(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);
}
/* Main routine */
extern void main( char argc, char *argv[] )
{
/* Initialize the API environment */
if( UF_CALL(UF_initialize()) )
{
/* Failed to initialize */
return;
}
/* TODO: Add your application code here */
//新建一个一个prt文件
tag_t PartTAG = NULL_TAG;
UF_CALL(UF_PART_new("D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\Temp\\Newpart.prt", UF_PART_METRIC, &PartTAG));
printf("第一步,新建一个prt部件!\n");
//导入刀柄
UF_import_part_modes_t modes;
modes.layer_mode = 0;
modes.group_mode = 0;
modes.view_mode = 0;
modes.cam_mode = false;
double dest_csys0 [ 6 ] = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0};
//由三个坐标值确定的X方向和Y方向,笛卡尔坐标系,确定两个就能确定第三个坐标方向
double dest_point0 [ 3 ] = {0.0, 0.0, 0.0,}; //导入的原点
double scale0 = 1.0; //缩放比例
tag_t group0 = NULL_TAG;
UF_CALL(UF_PART_import("D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\刀柄库\\BT40-ER32-100.prt", &modes, dest_csys0, dest_point0, scale0, &group0));
printf("第二步,导入刀柄\n");
//导入夹套
UF_import_part_modes_t modes1;
modes1.layer_mode = 0;
modes1.group_mode = 0;
modes1.view_mode = 0;
modes1.cam_mode = false;
double dest_csys1 [ 6 ] = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0};
//由三个坐标值确定的X方向和Y方向,笛卡尔坐标系,确定两个就能确定第三个坐标方向
double dest_point1 [ 3 ] = {0.0, 0.0, 0.0,}; //导入的原点
double scale1 = 1.0; //缩放比例
tag_t group1 = NULL_TAG;
UF_CALL(UF_PART_import("D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\夹套库\\ER32-10.prt", &modes1, dest_csys1, dest_point1, scale1, &group1));
printf("第三步,导入夹套!");
//导入刀杆
UF_import_part_modes_t modes2;
modes2.layer_mode = 0;
modes2.group_mode = 0;
modes2.view_mode = 0;
modes2.cam_mode = false;
double dest_csys2 [ 6 ] = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0};
//由三个坐标值确定的X方向和Y方向,笛卡尔坐标系,确定两个就能确定第三个坐标方向
double dest_point2 [ 3 ] = {0.0, -50.0, 0.0,}; //导入的原点
double scale2 = 1.0; //缩放比例
tag_t group2 = NULL_TAG;
UF_CALL(UF_PART_import("D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\刀杆库\\266RKF-D10.prt", &modes2, dest_csys2, dest_point2, scale2, &group2));
printf("第四步,导入刀杆!");
UF_CALL(UF_PART_save_as("D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\Temp\\ToolNum.prt"));
UF_CALL(UF_PART_close(PartTAG, 0, 1));
printf("保存文件!");
/* Terminate the API environment */
UF_CALL(UF_terminate());
}
/*****************************************************************************
** Utilities
*****************************************************************************/
ps: 因为我写的小程序是UG二次开发的程序,需要在UG的环境下才能运行,所以各位鱼友如果直接帮我调试的话会不成功,所以如果可以的话,请大家直接教我一个把exe改成dll的样板,谢谢!