//==============================================================================
// WARNING!! This file is overwritten by the Block UI Styler while generating
// the automation code. Any modifications to this file will be lost after
// generating the code again.
//
// Filename: D:\Tool\Application\dzbk.cpp
//
// This file was generated by the NX Block UI Styler
// Created by: liugang0213
// Version: NX 8.5
// Date: 06-13-2025 (Format: mm-dd-yyyy)
// Time: 09:46 (Format: hh-mm)
//
//==============================================================================
//==============================================================================
// Purpose: This TEMPLATE file contains C++ source to guide you in the
// construction of your Block application dialog. The generation of your
// dialog file (.dlx extension) is the first step towards dialog construction
// within NX. You must now create a NX Open application that
// utilizes this file (.dlx).
//
// The information in this file provides you with the following:
//
// 1. Help on how to load and display your Block UI Styler dialog in NX
// using APIs provided in NXOpen.BlockStyler namespace
// 2. The empty callback methods (stubs) associated with your dialog items
// have also been placed in this file. These empty methods have been
// created simply to start you along with your coding requirements.
// The method name, argument list and possible return values have already
// been provided for you.
//==============================================================================
//------------------------------------------------------------------------------
//These includes are needed for the following template code
//------------------------------------------------------------------------------
#include "dzbk.hpp"
using namespace NXOpen;
using namespace NXOpen::BlockStyler;
//------------------------------------------------------------------------------
// Initialize static variables
//------------------------------------------------------------------------------
Session *(dzbk::theSession) = NULL;
UI *(dzbk::theUI) = NULL;
//------------------------------------------------------------------------------
// Constructor for NX Styler class
//------------------------------------------------------------------------------
dzbk::dzbk()
{
try
{
// Initialize the NX Open C++ API environment
dzbk::theSession = NXOpen::Session::GetSession();
dzbk::theUI = UI::GetUI();
theDlxFileName = "dzbk.dlx";
theDialog = dzbk::theUI->CreateDialog(theDlxFileName);
// Registration of callback functions
theDialog->AddApplyHandler(make_callback(this, &dzbk::apply_cb));
theDialog->AddOkHandler(make_callback(this, &dzbk::ok_cb));
theDialog->AddUpdateHandler(make_callback(this, &dzbk::update_cb));
theDialog->AddInitializeHandler(make_callback(this, &dzbk::initialize_cb));
theDialog->AddDialogShownHandler(make_callback(this, &dzbk::dialogShown_cb));
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
throw;
}
}
//------------------------------------------------------------------------------
// Destructor for NX Styler class
//------------------------------------------------------------------------------
dzbk::~dzbk()
{
if (theDialog != NULL)
{
delete theDialog;
theDialog = NULL;
}
}
//------------------------------- DIALOG LAUNCHING ---------------------------------
//
// Before invoking this application one needs to open any part/empty part in NX
// because of the behavior of the blocks.
//
// Make sure the dlx file is in one of the following locations:
// 1.) From where NX session is launched
// 2.) $UGII_USER_DIR/application
// 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
// recommended. This variable is set to a full directory path to a file
// containing a list of root directories for all custom applications.
// e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_ROOT_DIR\menus\custom_dirs.dat
//
// You can create the dialog using one of the following way:
//
// 1. USER EXIT
//
// 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
// 2) Invoke the Shared Library through File->Execute->NX Open menu.
//
//------------------------------------------------------------------------------
extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
{
UF_initialize();
dzbk *thedzbk = NULL;
try
{
thedzbk = new dzbk();
// The following method shows the dialog immediately
thedzbk->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
dzbk::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
if(thedzbk != NULL)
{
delete thedzbk;
thedzbk = NULL;
}
}
//------------------------------------------------------------------------------
// This method specifies how a shared image is unloaded from memory
// within NX. This method gives you the capability to unload an
// internal NX Open application or user exit from NX. Specify any
// one of the three constants as a return value to determine the type
// of unload to perform:
//
//
// Immediately : unload the library as soon as the automation program has completed
// Explicitly : unload the library from the "Unload Shared Image" dialog
// AtTermination : unload the library when the NX session terminates
//
//
// NOTE: A program which associates NX Open applications with the menubar
// MUST NOT use this option since it will UNLOAD your NX Open application image
// from the menubar.
//------------------------------------------------------------------------------
extern "C" DllExport int ufusr_ask_unload()
{
//return (int)Session::LibraryUnloadOptionExplicitly;
return (int)Session::LibraryUnloadOptionImmediately;
//return (int)Session::LibraryUnloadOptionAtTermination;
}
//------------------------------------------------------------------------------
// Following method cleanup any housekeeping chores that may be needed.
// This method is automatically called by NX.
//------------------------------------------------------------------------------
extern "C" DllExport void ufusr_cleanup(void)
{
try
{
//---- Enter your callback code here -----
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
dzbk::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
int dzbk::Show()
{
try
{
theDialog->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
dzbk::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
//------------------------------------------------------------------------------
//---------------------Block UI Styler Callback Functions--------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//Callback Name: initialize_cb
//------------------------------------------------------------------------------
void dzbk::initialize_cb()
{
try
{
qiucha = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("qiucha"));
mubiao = dynamic_cast<NXOpen::BlockStyler::BodyCollector*>(theDialog->TopBlock()->FindBlock("mubiao"));
group = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("group"));
gongju = dynamic_cast<NXOpen::BlockStyler::BodyCollector*>(theDialog->TopBlock()->FindBlock("gongju"));
separator0 = dynamic_cast<NXOpen::BlockStyler::Separator*>(theDialog->TopBlock()->FindBlock("separator0"));
separator01 = dynamic_cast<NXOpen::BlockStyler::Separator*>(theDialog->TopBlock()->FindBlock("separator01"));
juli = dynamic_cast<NXOpen::BlockStyler::DoubleBlock*>(theDialog->TopBlock()->FindBlock("juli"));
vector<NXOpen::TaggedObject *> mbt = mubiao->GetSelectedObjects();
for(int a = 0; a < mbt.size(); a++)
{
tag_t mbttag = mbt[a]->Tag();
UF_DISP_set_highlight(mbttag,1);
}
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
dzbk::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
//------------------------------------------------------------------------------
//Callback Name: dialogShown_cb
//This callback is executed just before the dialog launch. Thus any value set
//here will take precedence and dialog will be launched showing that value.
//------------------------------------------------------------------------------
void dzbk::dialogShown_cb()
{
try
{
//---- Enter your callback code here -----
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
dzbk::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
//------------------------------------------------------------------------------
//Callback Name: apply_cb
//------------------------------------------------------------------------------
int dzbk::apply_cb()
{
int errorCode = 0;
try
{
double pyl = juli->Value(); // 圆柱面偏置量(用户输入)
double chamferOffset = -0.03; // 沉头平面固定偏置-0.03
vector<NXOpen::TaggedObject *> gjt = gongju->GetSelectedObjects();
vector<NXOpen::TaggedObject *> mbt = mubiao->GetSelectedObjects();
// 存储原始目标体的所有面(求差前的面)
std::set<tag_t> originalFaces;
for(int a = 0; a < mbt.size(); a++)
{
tag_t mbttag = mbt[a]->Tag();
UF_DISP_set_highlight(mbttag,1);
uf_list_p_t originalFaceList = NULL;
UF_MODL_ask_body_faces(mbttag, &originalFaceList);
int originalCount = 0;
UF_MODL_ask_list_count(originalFaceList, &originalCount);
for(int i = 0; i < originalCount; i++)
{
tag_t faceTag = NULL_TAG;
UF_MODL_ask_list_item(originalFaceList, i, &faceTag);
originalFaces.insert(faceTag);
}
UF_MODL_delete_list(&originalFaceList);
}
// 存储已经偏置过的面(避免重复偏置)
std::set<tag_t> offsetFaces;
for(int g = 0; g < gjt.size(); g++)
{
tag_t gjtTag = gjt[g]->Tag();
for(int a = 0; a < mbt.size(); a++)
{
tag_t mbttag = mbt[a]->Tag();
tag_t frec_eid = NULL_TAG;
UF_MODL_subtract_bodies_with_retained_options(mbttag, gjtTag, 0, 1, &frec_eid); // 求差,保留工具体
UF_DISP_set_highlight(mbttag,0);
// 获取求差后的面
uf_list_p_t faceList = NULL;
UF_MODL_ask_body_faces(mbttag, &faceList);
int listCount = 0;
UF_MODL_ask_list_count(faceList, &listCount);
for (int i = 0; i < listCount; i++)
{
tag_t faceTag = NULL_TAG;
UF_MODL_ask_list_item(faceList, i, &faceTag);
// 如果面是原始面或已经偏置过,则跳过
if(originalFaces.find(faceTag)!=originalFaces.end()||offsetFaces.find(faceTag)!=offsetFaces.end())
{
continue;
}
int faceSubtype = 0;
UF_MODL_ask_face_type(faceTag, &faceSubtype);
// (1) 如果是圆柱面,按输入值偏置
if (faceSubtype == 16) // 16=圆柱面
{
char offsetStr[32];
sprintf(offsetStr, "%f", pyl);
uf_list_p_t faces = NULL;
UF_MODL_create_list(&faces);
UF_MODL_put_list_item(faces, faceTag);
tag_t feature_obj_id = NULL_TAG;
UF_MODL_create_face_offset(offsetStr, faces, &feature_obj_id);
UF_MODL_delete_list(&faces);
offsetFaces.insert(faceTag); // 标记为已偏置
}
// (2) 如果是平面(沉头面),额外偏置-0.03
else if (faceSubtype == 22) // 22=平面
{
char offsetStr[32];
sprintf(offsetStr, "%f", chamferOffset);
uf_list_p_t faces = NULL;
UF_MODL_create_list(&faces);
UF_MODL_put_list_item(faces, faceTag);
tag_t feature_obj_id = NULL_TAG;
UF_MODL_create_face_offset(offsetStr, faces, &feature_obj_id);
UF_MODL_delete_list(&faces);
offsetFaces.insert(faceTag); // 标记为已偏置
}
}
UF_MODL_delete_list(&faceList);
}
}
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
dzbk::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Callback Name: update_cb
//------------------------------------------------------------------------------
int dzbk::update_cb(NXOpen::BlockStyler::UIBlock* block)
{
try
{
if(block == mubiao)
{
//---------Enter your code here-----------
}
else if(block == gongju)
{
//---------Enter your code here-----------
}
else if(block == separator0)
{
//---------Enter your code here-----------
}
else if(block == separator01)
{
//---------Enter your code here-----------
}
else if(block == juli)
{
//---------Enter your code here-----------
}
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
dzbk::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
//------------------------------------------------------------------------------
//Callback Name: ok_cb
//------------------------------------------------------------------------------
int dzbk::ok_cb()
{
int errorCode = 0;
try
{
errorCode = apply_cb();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
dzbk::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
UF_terminate();
}
//------------------------------------------------------------------------------
//Function Name: GetBlockProperties
//Description: Returns the propertylist of the specified BlockID
//------------------------------------------------------------------------------
PropertyList* dzbk::GetBlockProperties(const char *blockID)
{
return theDialog->GetBlockProperties(blockID);
}
这是我的程序 将这个功能加进去
最新发布