现象描述:
选择对象控件,选择组件中的对象(片体、实体、小平面体等等)时,焦点不位于选择对象控件上时,无法通过常用方法清空选择对象控件,即使在代码中设置Focus,也无法正常清空。 备注:1.选择组件或其他非组件内对象时,则可以正常清空。 2.焦点在另一个选择对象控件上,则可以正常清空。 尝试解决: 1.使用不同版本制作DLX。 2.调用update_cb(selection0),来清空。 3.封装清空函数,来调用清空。 4.使用空的选择对象控件对当前选择对象控件进行置空。 5.临时容器保存后,设置到当前选择对象控件中。 6.确认平台集是2015。 解决方案:暂无根本解决此问题的方案。上述方法都失败了,皆是对选择对象控件SetSelectedObjects设置时不成功(不报错),只能从逻辑和设置上规避该问题出现。 规避问题: 1.如果选择对象控件本身就是只选组件的控件,则设置过滤器为组件类型。 2.如果选择的对象就是组件中具体某个类型,最好将其单独抽出为一个组件,修改代码,将其进行导入,然后控件设置过滤器为组件类型(代价大)。 结论: 主要就是将选择对象过滤器设为组件类型,围绕着修改代码及逻辑进行处理,将焦点设置到选择对象过滤器上(设置后立马清空也不行,要借助过滤回调),借助过滤回调,在焦点处于选择对象上时,将控件容器进行设置。尽量避免选择对象控件选择的是组件内对象(片体、实体、小平面体等等)。
现象操作步骤:
1.选择对象是组件内的体(过滤器为:片体、实体、小平面体等等)。
2.当焦点不位于选择对象控件上时。用代码置空,不成功。(设置FOCUS也不行,只能手动选择控件改变焦点才有效果)
3.当焦点位于当前选择对象控件上,或者另外一个选择对象控件上时,点击清空。才能成功置空(设置FOCUS也不行,只能手动选择控件改变焦点才有效果)
4.NX 12.0.2.9版本出现该问题,VS2022 采用 2015平台集编译。
5.hpp文件
#ifndef MOVE12TEST_H_INCLUDED
#define MOVE12TEST_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_SelectObject.hxx>
#include <NXOpen/BlockStyler_Button.hxx>
#include <NXOpen/BlockStyler_SpecifyPoint.hxx>
#include <uf_ui.h>
#include <uf_modl.h>
#include <NXOpen/Selection.hxx>
#include <atlbase.h>
#undef CreateDialog
//------------------------------------------------------------------------------
// Namespaces needed for following template
//------------------------------------------------------------------------------
using namespace std;
using namespace NXOpen;
using namespace NXOpen::BlockStyler;
class DllExport MOVE12TEST
{
// class members
public:
static Session *theSession;
static UI *theUI;
MOVE12TEST();
~MOVE12TEST();
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 MOVE12TEST.cpp file.
// You are REQUIRED to write the implementation for these functions.
//------------------------------------------------------------------------------
void initialize_cb();
void dialogShown_cb();
int apply_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* group0;// Block type: Group
NXOpen::BlockStyler::SelectObject* selection0;// Block type: Selection
NXOpen::BlockStyler::Button* button0;// Block type: Button
NXOpen::BlockStyler::SpecifyPoint* point0;// Block type: Specify Point
};
#endif //MOVE12TEST_H_INCLUDED
6.cpp文件
#include "MOVE12TEST.hpp"
using namespace NXOpen;
using namespace NXOpen::BlockStyler;
//------------------------------------------------------------------------------
// Initialize static variables
//------------------------------------------------------------------------------
Session *(MOVE12TEST::theSession) = NULL;
UI *(MOVE12TEST::theUI) = NULL;
//------------------------------------------------------------------------------
// Constructor for NX Styler class
//------------------------------------------------------------------------------
/*获取dll完整路径*/
string GetProgramPath()
{
char filePath[MAX_PATH];
GetModuleFileNameA(_AtlBaseModule.GetModuleInstance(), filePath, MAX_PATH);
std::string strDllPath(filePath);
strDllPath = strDllPath.substr(0, strDllPath.find_last_of("\\") + 1);
return strDllPath;
}
MOVE12TEST::MOVE12TEST()
{
try
{
// Initialize the NX Open C++ API environment
MOVE12TEST::theSession = NXOpen::Session::GetSession();
MOVE12TEST::theUI = UI::GetUI();
string dllPath = GetProgramPath();
//拼接好dlx的绝对路径
theDlxFileName = dllPath.append("MOVE12TEST.dlx").c_str();
theDialog = MOVE12TEST::theUI->CreateDialog(theDlxFileName);
// Registration of callback functions
theDialog->AddApplyHandler(make_callback(this, &MOVE12TEST::apply_cb));
theDialog->AddOkHandler(make_callback(this, &MOVE12TEST::ok_cb));
theDialog->AddUpdateHandler(make_callback(this, &MOVE12TEST::update_cb));
theDialog->AddInitializeHandler(make_callback(this, &MOVE12TEST::initialize_cb));
theDialog->AddDialogShownHandler(make_callback(this, &MOVE12TEST::dialogShown_cb));
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
throw;
}
}
//------------------------------------------------------------------------------
// Destructor for NX Styler class
//------------------------------------------------------------------------------
MOVE12TEST::~MOVE12TEST()
{
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_BASE_DIR\ugii\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)
{
MOVE12TEST *theMOVE12TEST = NULL;
try
{
theMOVE12TEST = new MOVE12TEST();
// The following method shows the dialog immediately
theMOVE12TEST->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
MOVE12TEST::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
if(theMOVE12TEST != NULL)
{
delete theMOVE12TEST;
theMOVE12TEST = 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 -----
MOVE12TEST::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
int MOVE12TEST::Show()
{
try
{
theDialog->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
MOVE12TEST::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
//------------------------------------------------------------------------------
//---------------------Block UI Styler Callback Functions--------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//Callback Name: initialize_cb
//------------------------------------------------------------------------------
void MOVE12TEST::initialize_cb()
{
try
{
group0 = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("group0"));
selection0 = dynamic_cast<NXOpen::BlockStyler::SelectObject*>(theDialog->TopBlock()->FindBlock("selection0"));
button0 = dynamic_cast<NXOpen::BlockStyler::Button*>(theDialog->TopBlock()->FindBlock("button0"));
point0 = dynamic_cast<NXOpen::BlockStyler::SpecifyPoint*>(theDialog->TopBlock()->FindBlock("point0"));
/* Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;
Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
vector<Selection::MaskTriple> maskArray(1);
maskArray[0] = Selection::MaskTriple(UF_component_type, 0, 0);
selection0->GetProperties()->SetSelectionFilter("SelectionFilter", action, maskArray);*/
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
MOVE12TEST::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 MOVE12TEST::dialogShown_cb()
{
try
{
//---- Enter your callback code here -----
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
MOVE12TEST::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
//------------------------------------------------------------------------------
//Callback Name: apply_cb
//------------------------------------------------------------------------------
int MOVE12TEST::apply_cb()
{
int errorCode = 0;
try
{
//---- Enter your callback code here -----
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
MOVE12TEST::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Callback Name: update_cb
//------------------------------------------------------------------------------
int MOVE12TEST::update_cb(NXOpen::BlockStyler::UIBlock* block)
{
try
{
if(block == selection0)
{
//---------Enter your code here-----------
}
else if(block == button0)
{
selection0->Focus();
if (0)
{
std::vector<NXOpen::TaggedObject*> GetSel111 = this->selection0->GetSelectedObjects();
GetSel111.clear();
this->selection0->SetSelectedObjects(GetSel111);
}
if (1)
{
std::vector<NXOpen::TaggedObject*> GetSel;
GetSel.clear();
this->selection0->SetSelectedObjects(GetSel);
}
selection0->Focus();
}
else if(block == point0)
{
//---------Enter your code here-----------
}
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
MOVE12TEST::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
//------------------------------------------------------------------------------
//Callback Name: ok_cb
//------------------------------------------------------------------------------
int MOVE12TEST::ok_cb()
{
int errorCode = 0;
try
{
errorCode = apply_cb();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
MOVE12TEST::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Function Name: GetBlockProperties
//Description: Returns the propertylist of the specified BlockID
//------------------------------------------------------------------------------
PropertyList* MOVE12TEST::GetBlockProperties(const char *blockID)
{
return theDialog->GetBlockProperties(blockID);
}