说明:通过SelectTaggedObject,通过SelectTaggedObject,选择一个UG对象并输出对象的类型
对象的类型分为:(Type)大类和子类(SubType),UG中大部分公共对象都是在头文件uf_object_type.h中定义。
测试代码:选择一个对象并输出对象的类型和子类型
//通过SelectTaggedObject选择对象并输出tag标签
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
# include
# include
using std::ostrstream;
using std::endl;
using std::ends;
using std::cerr;
#else
# include
# include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace NXOpen;
using namespace std;
#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);
UF_print_syslog(msg, FALSE);
UF_print_syslog(err, FALSE);
UF_print_syslog("\n", FALSE);
UF_print_syslog(call, FALSE);
UF_print_syslog(";\n", FALSE);
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()) )
{
return;
}
/* TODO: Add your application code here */
Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
UI *theUI = UI::GetUI();
TaggedObject *object;
Point3d cursor;
//提示 标题 选择范围 是否包含特征 是否保持高亮 被选择的对象 光标位置坐标
Selection::Response res;
res=theUI->SelectionManager()->SelectTaggedObject("提示","这里是标题",Selection::SelectionScopeWorkPart,true,false,&object,&cursor);
//SelectionScopeUseDefault 整个装配 在工作部件和组件内 仅在工作部件内
//SelectionScopeWorkPart 仅在工作部件内
//SelectionScopeWorkPartAndOccurrence 在工作部件和组件内
if (res == Selection::ResponseObjectSelected)//如果选中了 = 5
{
tag_t tagTag=NULL_TAG;
tagTag=object->GetTag();
int iType=0;
int iSubType=0;
UF_OBJ_ask_type_and_subtype(tagTag,&iType,&iSubType); //获取对象的类型
char cType[256]="";
char cSubType[256]="";
sprintf(cType,"Type=%d",iType); //大类
sprintf(cSubType,"SubType=%d",iSubType);//子类
theSession->ListingWindow()->Open(); //打开信息窗
theSession->ListingWindow()->WriteLine(cType); //输出对象标签
theSession->ListingWindow()->WriteLine(cSubType); //输出对象标签
}
/* Terminate the API environment */
UF_CALL(UF_terminate());
}
extern int ufusr_ask_unload( void )
{
return (UF_UNLOAD_IMMEDIATELY);
}
效果演示: