//CESHI_ARC
// Mandatory UF Includes
#include "C:\all_uf.h"
#include <uf.h>
#include <uf_modl.h>
#include <uf_disp.h>
#include<vector>
// Internal Includes
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/UI.hxx>
// Internal+External Includes
#include <NXOpen/Annotations.hxx>
#include <NXOpen/Assemblies_Component.hxx>
#include <NXOpen/Assemblies_ComponentAssembly.hxx>
#include <NXOpen/Body.hxx>
#include <NXOpen/BodyCollection.hxx>
#include <NXOpen/Face.hxx>
#include <NXOpen/Line.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Session.hxx>
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/ModelingView.hxx>
#include <NXOpen/ModelingViewCollection.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/selection.hxx>
#include <NXOpen/Features_Feature.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/NXObjectManager.hxx>
// Std C++ Includes
#include <iostream>
#include <sstream>
using namespace NXOpen;
using std::string;
using std::exception;
using std::stringstream;
using std::endl;
using std::cout;
using std::cerr;
//------------------------------------------------------------------------------
// NXOpen c++ test class
//------------------------------------------------------------------------------
class C_ARC
{
// class members
public:
static Session *theSession;
static UI *theUI;
C_ARC();
~C_ARC();
void do_it();
void print(const NXString &);
void print(const string &);
void print(const char*);
private:
Part *workPart, *displayPart;
NXMessageBox *mb;
ListingWindow *lw;
};
//------------------------------------------------------------------------------
// Initialize static variables
//------------------------------------------------------------------------------
Session *(C_ARC::theSession) = NULL;
UI *(C_ARC::theUI) = NULL;
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
C_ARC::C_ARC()
{
// Initialize the NX Open C++ API environment
C_ARC::theSession = NXOpen::Session::GetSession();
C_ARC::theUI = UI::GetUI();
mb = theUI->NXMessageBox();
lw = theSession->ListingWindow();
workPart = theSession->Parts()->Work();
displayPart = theSession->Parts()->Display();
}
//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
C_ARC::~C_ARC()
{
}
//------------------------------------------------------------------------------
// Print string to listing window or stdout
//------------------------------------------------------------------------------
void C_ARC::print(const NXString &msg)
{
if(! lw->IsOpen() ) lw->Open();
lw->WriteLine(msg);
}
void C_ARC::print(const string &msg)
{
if(! lw->IsOpen() ) lw->Open();
lw->WriteLine(msg);
}
void C_ARC::print(const char * msg)
{
if(! lw->IsOpen() ) lw->Open();
lw->WriteLine(msg);
}
//预选高亮
static int select_filter_proc_fn(tag_t object, int type[3], void* user_data, UF_UI_selection_p_t select)
{
if (object == NULL)
{
return UF_UI_SEL_REJECT;
}
else
{
return UF_UI_SEL_ACCEPT;
}
}
static int init_proc(UF_UI_selection_p_t select, void* user_data)
{
int num_triples = 2;//可选类型的数量
UF_UI_mask_t mask_triples[] = { UF_solid_type,UF_solid_edge_subtype,3,
UF_circle_type, UF_circle_open_subtype ,0};;//可选对象类型
UF_UI_set_sel_mask(select, UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, num_triples, mask_triples);
if ((UF_UI_set_sel_procs(select, select_filter_proc_fn, NULL, user_data)) == 0)
{
return UF_UI_SEL_SUCCESS;
}
else
{
return UF_UI_SEL_FAILURE;
}
}
//------------------------------------------------------------------------------
// Do something
//------------------------------------------------------------------------------
void C_ARC::do_it()
{
// TODO: add your code here
UF_initialize();
//单对象选择对话框
char sCue[] = "单对象选择对话框";
char sTitle[] = "单对象选择对话框";
int iScope = UF_UI_SEL_SCOPE_NO_CHANGE;
int iResponse;
tag_t tObject;
tag_t tView;
double adCursor[3];
L01:
UF_UI_select_with_single_dialog(sCue, sTitle, iScope, init_proc, NULL, &iResponse, &tObject, adCursor, &tView);
UF_CURVE_arc_t Obj_data;
UF_CURVE_ask_arc_data(tObject, &Obj_data);
char aa[256];
if (tObject > 0)
{
double Sp = Obj_data.start_angle / PI * 180.0;
double Ep = Obj_data.end_angle / PI * 180.0;
double rad = Obj_data.radius * 2;
sprintf(aa, "开始角度:%fn结束角度:%fn直径:%f", Sp, Ep, rad);
uc1601(aa, 1);
}
UF_DISP_set_highlight(tObject, 0);
if (iResponse == UF_UI_CANCEL)
{
return;
}
else
{
goto L01;
}
UF_terminate();
}
//------------------------------------------------------------------------------
// Entry point(s) for unmanaged internal NXOpen C/C++ programs
//------------------------------------------------------------------------------
// Explicit Execution
extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
try
{
// Create NXOpen C++ class instance
C_ARC *theC_ARC;
theC_ARC = new C_ARC();
theC_ARC->do_it();
delete theC_ARC;
}
catch (const NXException& e1)
{
UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
}
catch (const exception& e2)
{
UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
}
catch (...)
{
UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
}
}
//------------------------------------------------------------------------------
// Unload Handler
//------------------------------------------------------------------------------
extern "C" DllExport int ufusr_ask_unload()
{
return (int)NXOpen::Session::LibraryUnloadOptionImmediately;
}
部分代码转自https://www.cnblogs.com/nxopen2018/p/10957188.html卢尚宇
原文链接: https://www.cnblogs.com/liuxiaoqing1/p/12209071.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/192074
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!