NX/UG二次开发—UI—内部UI的使用

我们经常使用blockUI控件进行开发,但是有些控件在UG自身的工具很常见,但是在blockUI样式编辑器中并没有提供。参照网上一些大神的帖子和思路,发现是可以通过配置软件安装目录下..\Siemens\NX\UGII\menus\styler_blocks_simpl_chinese.pax(注意不同语言的UG修改对应不同的pax文件)可以实现一些UG一些内部UI。

以下以常见的宽枚举控件为例,如下图所示:

1、先打开含有你需要控件的工具,比如艺术样条对话框

2、然后选择UIFW侦查

3、查看你需要控件的类名,本例子中需要查看的是宽枚举控件,在UIFW侦查中发现第一个即为所需要的:UGS::UIFW_types_block

4、打开UG安装目录..\Siemens\NX\UGII\menus\styler_blocks_simpl_chinese.pax,在里面添加如下:

5、重新进入UI样式编辑器,发现多了一个新的控件添加即可

6、其他的比如还有制图的字符输入控件:

7、字体颜色大小控件

对于有些控件,不能简单的设置和获取,需要配合NXBIN文件下的某些dll中导出函数一起使用。

比如下界面:

1、含有带手柄控件的约束选择控件,手柄默认橘黄色球状,通过内部函数可以设置方块或者箭头形状也可以修改颜色。

2、和UG官方一样的预览控件。

 

  • 10
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
好的,以下是我给出的C++代码,用于UG/NX二次开发环境下,在ug8.5和vs2010的环境下,编写一个用UIBlock的线性尺寸改变实体的长宽高。 ```cpp #include <NXOpen/BlockStyler_UIBlock.hxx> #include <NXOpen/BlockStyler.hxx> #include <NXOpen/Callback.hxx> #include <NXOpen/DisplayableObject.hxx> #include <NXOpen/DisplayableObjectCollection.hxx> #include <NXOpen/DisplayPart.hxx> #include <NXOpen/Part.hxx> #include <NXOpen/PartCollection.hxx> #include <NXOpen/Point.hxx> #include <NXOpen/Selection.hxx> #include <NXOpen/SelectionIntentRule.hxx> #include <NXOpen/SessionFactory.hxx> #include <NXOpen/Session.hxx> #include <NXOpen/SimpleDimension.hxx> #include <NXOpen/TaggedObject.hxx> #include <NXOpen/Unit.hxx> #include <NXOpen/UnitCollection.hxx> #include <NXOpen/Update.hxx> #include <NXOpen/Updater.hxx> #include <NXOpen/View.hxx> #include <NXOpen/ViewCollection.hxx> #include <NXOpen/WorkPart.hxx> #include <iostream> using namespace NXOpen; using namespace NXOpen::BlockStyler; // Callback object to handle events in the UI block class LinearDimensionCallback : public NXOpen::Callback { public: LinearDimensionCallback(UIBlock* block, Part* part, SimpleDimension* dimensionX, SimpleDimension* dimensionY, SimpleDimension* dimensionZ) : m_block(block), m_part(part), m_dimensionX(dimensionX), m_dimensionY(dimensionY), m_dimensionZ(dimensionZ) {} virtual ~LinearDimensionCallback() {} virtual void Notify(NXOpen::CallbackType type, NXOpen::TaggedObject* obj) { if (type == NXOpen::CallbackType_Create) { // Subscribe to the block's value change event m_block->AddValueChangeListener(this); } else if (type == NXOpen::CallbackType_ValueChanged) { // Get the current values of the UI block double xValue, yValue, zValue; m_block->GetDouble("XValue", xValue); m_block->GetDouble("YValue", yValue); m_block->GetDouble("ZValue", zValue); // Create a unit object to represent millimeters Unit* unit = m_part->UnitCollection()->FindObject("MilliMeter"); // Update the dimensions of the entity m_dimensionX->SetDimension(xValue, unit); m_dimensionY->SetDimension(yValue, unit); m_dimensionZ->SetDimension(zValue, unit); // Update the part display to show the changes m_part->UpdateManager()->DoUpdate(); } } private: UIBlock* m_block; Part* m_part; SimpleDimension* m_dimensionX; SimpleDimension* m_dimensionY; SimpleDimension* m_dimensionZ; }; // Function to create a block with three double values for the X, Y, and Z dimensions UIBlock* CreateDimensionBlock(UIBlock* parent, const char* name, double initialValue) { UIBlock* block = parent->AddBlock(name); block->SetProperty(UIBlock::PROP_LABEL, name); block->SetProperty(UIBlock::PROP_TYPE, UIBlock::TYPE_DOUBLE); block->SetDouble(initialValue); block->SetProperty(UIBlock::PROP_WIDTH_WEIGHT, 1); block->SetProperty(UIBlock::PROP_HEIGHT_WEIGHT, 1); block->SetProperty(UIBlock::PROP_DISPLAY_UNITS, "MilliMeter"); return block; } // Function to create a linear dimension entity with three dimensions void CreateLinearDimension(Part* part, const char* name, TaggedObject* entity, const char* xName, const char* yName, const char* zName) { // Create a unit object to represent millimeters Unit* unit = part->UnitCollection()->FindObject("MilliMeter"); // Create the dimensions for the X, Y, and Z axes SimpleDimension* dimensionX = part->Dimensions()->CreateLinearDimension(entity, NXOpen::Annotations::DimensionOrientation_X_Axis, NULL, unit, 0); SimpleDimension* dimensionY = part->Dimensions()->CreateLinearDimension(entity, NXOpen::Annotations::DimensionOrientation_Y_Axis, NULL, unit, 0); SimpleDimension* dimensionZ = part->Dimensions()->CreateLinearDimension(entity, NXOpen::Annotations::DimensionOrientation_Z_Axis, NULL, unit, 0); // Set the names of the dimensions dimensionX->SetDimensionName(xName); dimensionY->SetDimensionName(yName); dimensionZ->SetDimensionName(zName); // Create a displayable object for the entity DisplayableObject* displayObject = part->DisplayManager()->CreateDisplayableObject(entity); DisplayableObjectCollection displayObjects(part->DisplayManager()); displayObjects.Add(displayObject); // Create a view for the entity View* view = part->ViewCollection()->Create("Linear Dimension View"); view->SetVisibility(displayObjects, true); view->SetVisibilityOfSketchCurves(false); // Set the orientation of the view Point* origin = part->Points()->CreatePoint(0, 0, 0); view->SetOrientation(origin, NXOpen::View::Orientation_Top, NXOpen::View::Orientation_Inferred); // Update the part display to show the new entity part->UpdateManager()->DoUpdate(); // Create a dialog block to allow the user to change the dimensions BlockDialog* dialog = BlockDialog::AskBlockingDialog("Change Dimensions"); UIBlock* xBlock = CreateDimensionBlock(dialog->TopBlock(), xName, dimensionX->Value()); UIBlock* yBlock = CreateDimensionBlock(dialog->TopBlock(), yName, dimensionY->Value()); UIBlock* zBlock = CreateDimensionBlock(dialog->TopBlock(), zName, dimensionZ->Value()); LinearDimensionCallback* callback = new LinearDimensionCallback(dialog->TopBlock(), part, dimensionX, dimensionY, dimensionZ); dialog->SetApplyCallback(callback); dialog->SetCloseCallback(callback); dialog->SetModal(true); dialog->Show(); // Clean up memory delete callback; delete zBlock; delete yBlock; delete xBlock; delete view; delete origin; delete displayObject; } // Main entry point of the program extern "C" DllExport void ufusr(char* param, int* returnCode, int paramLen) { try { // Initialize the NXOpen session Session* session = SessionFactory::GetSession(); session->Parts()->Work(); // Get the current selection, which should be an entity Selection* selection = session->SelectionManager()->GetSelection(); std::vector<TaggedObject*> selectedObjects = selection->GetSelectedObjects(); if (selectedObjects.empty()) { std::cerr << "No entity selected" << std::endl; *returnCode = 1; return; } TaggedObject* entity = selectedObjects[0]; // Create a linear dimension for the entity Part* part = session->Parts()->Work(); CreateLinearDimension(part, "Linear Dimension", entity, "Length", "Width", "Height"); // Clean up memory and exit the program delete selection; *returnCode = 0; } catch (const NXOpen::NXException& ex) { std::cerr << "NXOpen exception: " << ex.Message() << std::endl; *returnCode = 1; } catch (const std::exception& ex) { std::cerr << "Exception: " << ex.what() << std::endl; *returnCode = 1; } } ``` 这个程序会创建一个UIBlock对话框,其中包含三个用于输入实体长度、宽度和高度的文本框。当用户更改这些值时,程序将更新实体的线性尺寸,并在屏幕上显示更改。请注意,这个程序是作为NXOpen插件编写的,需要将它编译为DLL,并在NX中加载它。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

恩·艾克斯·红

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值