购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008 QQ号:85585969
//选择视图里圆弧,创建坐标原点
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
# include <strstream>
# include <iostream>
using std::ostrstream;
using std::endl;
using std::ends;
using std::cerr;
#else
# include <strstream.h>
# include <iostream.h>
#endif
#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include <stdio.h>
#include <string.h>
#include <uf_defs.h>
#include <uf_drf.h>
#include <uf_curve.h>
#include <uf_csys.h>
#include <uf_obj.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include <uf_drf.h>
#include <uf_obj.h>
#include <uf_curve.h>
#include <uf_csys.h>
#include <uf_modl.h>
#include <uf_modl.h>
#include <UF_VIEW.h>
//设置选择的实体类型
static int init_proc( UF_UI_selection_p_t select, void *user_data )
{
int errorCode = 0;
//选择实体边缘
int num_triples = 1; //选择数量
UF_UI_mask_t mask_triples[] = {UF_solid_type,UF_solid_edge_subtype,3};
errorCode = UF_UI_set_sel_mask(select,
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,//
num_triples, mask_triples);
if( errorCode == 0)
{
return UF_UI_SEL_SUCCESS;
}
else
{
return UF_UI_SEL_FAILURE;
}
}
#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],
msg[133];
sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
irc, line, file);
UF_get_fail_message(irc, err);

●●●请先
登陆 或
注册 后查看●●●
if (!UF_UI_open_listing_window())
{
UF_UI_write_listing_window(msg);
UF_UI_write_listing_window(err);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(call);
UF_UI_write_listing_window(";\n");
}
}
return(irc);
}
extern DllExport void ufsta( char *param, int *returnCode, int rlen )
{
/* Initialize the API environment */
if( UF_CALL(UF_initialize()) )
{
/* Failed to initialize */
return;
}
/* TODO: Add your application code here */
//坐标标注
char *message="UGapi提示!请选择视图里的对象";
char *title="UGapi-UGapi";
int scope=UF_UI_SEL_SCOPE_WORK_PART;//选取范围
int response;
tag_t object_tag;
double cursor[3]={0.0};
tag_t view=NULL_TAG;
//加锁
//UF_UI_lock_ug_access (UF_UI_FROM_CUSTOM);
UF_UI_set_cursor_view(0);//0 = Any view,1 = Work view (0可以选择“图纸上视图”里的对象)
UF_UI_select_with_single_dialog(message,title,scope,init_proc,NULL,&response,&object_tag,cursor,&view); //选择框
UF_UI_set_cursor_view(1);//0 = Any view,1 = Work view (0可以选择“图纸上视图”里的对象)
UF_DISP_set_highlight(object_tag,0); //1高亮显示 0不高亮显示
//UF_OBJ_set_color(object_tag,20); //改颜色
//解锁
//UF_UI_unlock_ug_access (UF_UI_FROM_CUSTOM);
// 返回值response;
//UF_UI_BACK 后退
//UF_UI_CANCEL 取消
//UF_UI_OK 确定
//UF_UI_OBJECT_SELECTED 选择的对象
//UF_UI_OBJECT_SELECTED_BY_NAME 所选对象的名字
if (response==UF_UI_OBJECT_SELECTED)
{
char view_name[132]="";
UF_OBJ_ask_name(view, view_name); //获得视图名称
int status;
UF_MODL_ask_feat_body (object_tag,&object_tag);//★
/* 创建并显示一个坐标原点。 */
tag_t origin_tag=NULL_TAG;
char user_text[133]="原点";
UF_DRF_object_t object; /* 初始化对象的结构 */
UF_DRF_init_object_structure(&object);
object.object_tag = object_tag;
object.object_view_tag = view;
object.object_assoc_type = UF_DRF_arc_center;
object.object_assoc_modifier = 0;
UF_DRF_create_ordorigin(
&object, //【输入】关联对象的标识
1, //【输入】1 =右上;2 =左上;3 =右下;4 =左下;5 =所有象限
1, //【输入】箭头与尺寸线显示;1 =无;2 =是的
1, //【输入】1 =显示原点名称;2 =不显示
user_text, //【输入】原点名称
&origin_tag//【输出】原点标识
);
}
UF_CALL(UF_terminate());
}
extern int ufusr_ask_unload( void )
{
return (UF_UNLOAD_IMMEDIATELY);
}