本实例非博主原创,是从大神的视频课程中学习的。
- 版本:
NX9+VS2012
- 演示:
- 源代码:
//==============================================================================
// WARNING!! This file is overwritten by the Block Styler while generating
// the automation code. Any modifications to this file will be lost after
// generating the code again.
//
// Filename: D:CaesarToolkitapplicationSetBodyLayer.hpp
//
// This file was generated by the NX Block Styler
// Created by: Administrator
// Version: NX 9
// Date: 02-18-2021 (Format: mm-dd-yyyy)
// Time: 20:38
//
//==============================================================================
#ifndef SETBODYLAYER_H_INCLUDED
#define SETBODYLAYER_H_INCLUDED
//------------------------------------------------------------------------------
//These includes are needed for the following template code
//------------------------------------------------------------------------------
#include <uf_defs.h>
#include <uf_ui_types.h>
#include <iostream>
#include <NXOpen/Session.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/Callback.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/BlockStyler_UIBlock.hxx>
#include <NXOpen/BlockStyler_BlockDialog.hxx>
#include <NXOpen/BlockStyler_PropertyList.hxx>
#include <NXOpen/BlockStyler_Group.hxx>
#include <NXOpen/BlockStyler_BodyCollector.hxx>
#include <NXOpen/BlockStyler_IntegerBlock.hxx>
//头文件
#include <uf.h>
#include <uf_layer.h>
#include <uf_obj.h>
//------------------------------------------------------------------------------
//Bit Option for Property: EntityType
//------------------------------------------------------------------------------
#define EntityType_AllowBodies (1 << 6);
//------------------------------------------------------------------------------
//Bit Option for Property: BodyRules
//------------------------------------------------------------------------------
#define BodyRules_SingleBody (1 << 0);
#define BodyRules_FeatureBodies (1 << 1);
#define BodyRules_BodiesinGroup (1 << 2);
//------------------------------------------------------------------------------
// Namespaces needed for following template
//------------------------------------------------------------------------------
using namespace std;
using namespace NXOpen;
using namespace NXOpen::BlockStyler;
class DllExport SetBodyLayer
{
// class members
public:
static Session *theSession;
static UI *theUI;
SetBodyLayer();
~SetBodyLayer();
int Show();
//----------------------- BlockStyler Callback Prototypes ---------------------
// The following member function prototypes define the callbacks
// specified in your BlockStyler dialog. The empty implementation
// of these prototypes is provided in the SetBodyLayer.cpp file.
// You are REQUIRED to write the implementation for these functions.
//------------------------------------------------------------------------------
void initialize_cb();
void dialogShown_cb();
int ok_cb();
int update_cb(NXOpen::BlockStyler::UIBlock* block);
PropertyList* GetBlockProperties(const char *blockID);
private:
const char* theDlxFileName;
NXOpen::BlockStyler::BlockDialog* theDialog;
NXOpen::BlockStyler::Group* group1;// Block type: Group
NXOpen::BlockStyler::BodyCollector* bodySelect0;// Block type: Body Collector
NXOpen::BlockStyler::Group* group2;// Block type: Group
NXOpen::BlockStyler::IntegerBlock* integer0;// Block type: Integer
};
#endif //SETBODYLAYER_H_INCLUDED
//==============================================================================
// 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:CaesarToolkitapplicationSetBodyLayer.cpp
//
// This file was generated by the NX Block UI Styler
// Created by: Administrator
// Version: NX 9
// Date: 02-18-2021 (Format: mm-dd-yyyy)
// Time: 20:38 (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 "SetBodyLayer.hpp"
using namespace NXOpen;
using namespace NXOpen::BlockStyler;
//------------------------------------------------------------------------------
// Initialize static variables
//------------------------------------------------------------------------------
Session *(SetBodyLayer::theSession) = NULL;
UI *(SetBodyLayer::theUI) = NULL;
//------------------------------------------------------------------------------
// Constructor for NX Styler class
//------------------------------------------------------------------------------
SetBodyLayer::SetBodyLayer()
{
try
{
// Initialize the NX Open C++ API environment
SetBodyLayer::theSession = NXOpen::Session::GetSession();
SetBodyLayer::theUI = UI::GetUI();
theDlxFileName = "SetBodyLayer.dlx";
theDialog = SetBodyLayer::theUI->CreateDialog(theDlxFileName);
// Registration of callback functions
theDialog->AddOkHandler(make_callback(this, &SetBodyLayer::ok_cb));
theDialog->AddUpdateHandler(make_callback(this, &SetBodyLayer::update_cb));
theDialog->AddInitializeHandler(make_callback(this, &SetBodyLayer::initialize_cb));
theDialog->AddDialogShownHandler(make_callback(this, &SetBodyLayer::dialogShown_cb));
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
throw;
}
}
//------------------------------------------------------------------------------
// Destructor for NX Styler class
//------------------------------------------------------------------------------
SetBodyLayer::~SetBodyLayer()
{
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_DIRmenuscustom_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();//初始化
SetBodyLayer *theSetBodyLayer = NULL;
try
{
theSetBodyLayer = new SetBodyLayer();
// The following method shows the dialog immediately
theSetBodyLayer->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
SetBodyLayer::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
if(theSetBodyLayer != NULL)
{
delete theSetBodyLayer;
theSetBodyLayer = NULL;
}
UF_terminate();//终止
}
//------------------------------------------------------------------------------
// 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;
}
//------------------------------------------------------------------------------