列文章目录

UG/NX二次开发Siemens官方NXOPEN实例解析—1.1 BlockStyler/ColoredBlock
UG/NX二次开发Siemens官方NXOPEN实例解析—1.2 BlockStyler/EditExpression
UG/NX二次开发Siemens官方NXOPEN实例解析—1.3 BlockStyler/ExtrudewithPreview
UG/NX二次开发Siemens官方NXOPEN实例解析—1.4 BlockStyler/HoleCoordinates
UG/NX二次开发Siemens官方NXOPEN实例解析—1.5 BlockStyler/MatrixOperations
UG/NX二次开发Siemens官方NXOPEN实例解析—1.6 BlockStyler/SelectionExample
UG/NX二次开发Siemens官方NXOPEN实例解析—1.7 BlockStyler/TreeListDemo
UG/NX二次开发Siemens官方NXOPEN实例解析—1.8 BlockStyler/UDB_CreateCylinder
UG/NX二次开发Siemens官方NXOPEN实例解析—1.9 BlockStyler/UpdateExample

文章目录

列文章目录

文章目录

前言

一、UI样式文件分析

1. 样式文件目录

2. 样式文件导入预览

3. 样式文件解析

二、源码文件解析

1. 主程序分析

2. 处理模块分析

3. 运行结果截图

总结


前言

随着工业智能化的不断发展,UG二次开发的需求越来越多,也吸引了大批的二开从业人员,本人作为一名资深IT从业者(10年+)也毅然加入二次开发大军。

然而,和流行IT行业(互联网、金融、医疗等)相比,工业智能化的门槛显得更高一点,专业的工业软件,相对封闭的开发理念和更小的开发圈子,让刚进入二开的从业者有点举步维艰。边学边整理,希望通过这系列文章的整理能给二开的生态增添一叶绿。


一、UI样式文件分析

1. 样式文件目录

目录位置:

UGOPEN\SampleNXOpenApplications\C++\BlockStyler\UDB_CreateCylinder\CreateCylinder_UsingUDB.dlx

UGOPEN\SampleNXOpenApplications\C++\BlockStyler\UDB_CreateCylinder\DimensionUDB.dlx

UGOPEN\SampleNXOpenApplications\C++\BlockStyler\UDB_CreateCylinder\DimensionUDB.udx

2. 样式文件导入预览

3. 样式文件解析

本实例主要用到的控件如下 : 指定点、指定矢量、UDB控件

如上图,DimensionUDB.dlx文件生成UDB控件只需要在文件生成类型选择用户定义UI块,然后生成的DimensionUDB.udx文件需要放到开发目录  {UGII_USER_DIR}/application

二、源码文件解析

1. 主程序分析

1.1 加载模块

extern "C" DllExport void  ufusr(char *param, int *retcod, int param_len)
{CreateCylinder_UsingUDB *theCreateCylinder_UsingUDB = NULL;try{theCreateCylinder_UsingUDB = new CreateCylinder_UsingUDB();// The following method shows the dialog immediatelytheCreateCylinder_UsingUDB->Show();}catch(exception& ex){//---- Enter your exception handling code here -----CreateCylinder_UsingUDB::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());}if(theCreateCylinder_UsingUDB != NULL){delete theCreateCylinder_UsingUDB;theCreateCylinder_UsingUDB = NULL;}
}CreateCylinder_UsingUDB::CreateCylinder_UsingUDB()
{try{// Initialize the NX Open C++ API environmentCreateCylinder_UsingUDB::theSession = NXOpen::Session::GetSession();CreateCylinder_UsingUDB::theUI = UI::GetUI();theDlxFileName = "CreateCylinder_UsingUDB.dlx";theDialog = CreateCylinder_UsingUDB::theUI->CreateDialog(theDlxFileName);// Registration of callback functionstheDialog->AddApplyHandler(make_callback(this, &CreateCylinder_UsingUDB::apply_cb));theDialog->AddOkHandler(make_callback(this, &CreateCylinder_UsingUDB::ok_cb));theDialog->AddUpdateHandler(make_callback(this, &CreateCylinder_UsingUDB::update_cb));theDialog->AddInitializeHandler(make_callback(this, &CreateCylinder_UsingUDB::initialize_cb));theDialog->AddDialogShownHandler(make_callback(this, &CreateCylinder_UsingUDB::dialogShown_cb));diameter = DimensionUDB::RegisterUserDefinedUIBlock(theDialog, "diameter");height = DimensionUDB::RegisterUserDefinedUIBlock(theDialog, "height");}catch(exception& ex){//---- Enter your exception handling code here -----throw;}
}

用户定义控件的使用方法和通用控件有些许差别:

diameter = DimensionUDB::RegisterUserDefinedUIBlock(theDialog, "diameter");
height = DimensionUDB::RegisterUserDefinedUIBlock(theDialog, "height");

设置用户定义控件的方法如下,此方法需要自己写:

diameter->SetLabel("Diameter");
diameter->SetValue(200);

height->SetLabel("Height");
height->SetValue( 500);

1.2 提交模块

int CreateCylinder_UsingUDB::apply_cb()
{int errorCode = 0;try{//---- Enter your callback code here -----CreateCylinder();}catch(exception& ex){//---- Enter your exception handling code here -----errorCode = 1;CreateCylinder_UsingUDB::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());}return errorCode;
}void CreateCylinder_UsingUDB::CreateCylinder()
{Part* workPart(theSession->Parts()->Work());Features::CylinderBuilder* cylinderBuilder1 = NULL;cylinderBuilder1 = workPart->Features()->CreateCylinderBuilder(NULL);//Get the pointPropertyList* pointPropertyList = point0->GetProperties();Point3d originPoint = pointPropertyList->GetPoint("Point");delete pointPropertyList;pointPropertyList = NULL;//Get the directionPropertyList* vectorPropertyList = vector0->GetProperties();Vector3d direction = vectorPropertyList->GetVector("Vector");delete vectorPropertyList;vectorPropertyList = NULL;Direction* direction1  = NULL;direction1 = workPart->Directions()->CreateDirection(originPoint, direction, SmartObject::UpdateOptionWithinModeling);//Set diameter and heightstd::stringstream diameterValue;diameterValue << diameter->GetValue();std::stringstream heightValue;heightValue << height->GetValue();cylinderBuilder1->Diameter()->SetRightHandSide(diameterValue.str());cylinderBuilder1->Height()->SetRightHandSide(heightValue.str());//Set the axisAxis* axis1 = NULL;axis1 = cylinderBuilder1->Axis();axis1->Point()->SetCoordinates(originPoint);axis1->SetDirection(direction1);//CommitcylinderBuilder1->Commit();cylinderBuilder1->Destroy();cylinderBuilder1 = NULL;
}

这里通过CylinderBuilder类实现了生成圆柱体方法,需要关注获取圆柱直径和高度的方法,用户控件的方法都需要在用户控件里面定义和实现

std::stringstream diameterValue;
diameterValue << diameter->GetValue();
std::stringstream heightValue;
heightValue << height->GetValue();

2. UDB分析

//Sets the label on the double block
void DimensionUDB::SetLabel(const char* label)
{PropertyList* prop = Dimension->GetProperties();prop->SetString("Label", label);delete prop;prop = NULL;
}//Sets the value of the double block
void DimensionUDB::SetValue(const double value)
{PropertyList* prop = Dimension->GetProperties();prop->SetDouble("Value", value);delete prop;prop = NULL;
}//Sets the value of the double block
double DimensionUDB::GetValue() const
{PropertyList* prop = Dimension->GetProperties();double value = prop->GetDouble("Value");delete prop;prop = NULL;return value;
}//Enables/Disables the double block based on toggle. If toggled on, the double-field is disabled
void DimensionUDB::EnableDimensionField()
{PropertyList* prop = sensitiveFlag->GetProperties();bool flag = prop->GetLogical("Value");delete prop;prop = NULL;//Disable double block if toggle field is onPropertyList* dimensionPropertyList = Dimension->GetProperties();dimensionPropertyList->SetLogical("Enable", !flag);delete dimensionPropertyList;dimensionPropertyList = NULL;
}

编写用户定义控件的时候,只需要关注我们需要的内容,这里我们要用到3个功能:

1、切换开关的时候,输入框可用/不可用

2、设置输入框的默认值

3、获取输入框的内容

3. 运行结果截图

总结

官方实例UDB_CreateCylinder

本节主要讲解UDB的生成和使用方法,主要知识点如下:

1)编辑用户定义UI块,生成udx文件

2)UDB的调用方法

3)UDB的后台开发,用户定义方法的开发及调用方法

UG/NX二次开发Siemens官方NXOPEN实例解析—1.8 BlockStyler/UDB_CreateCylinder相关推荐

  1. UG/NX二次开发Siemens官方NXOPEN实例解析—1.6 BlockStyler/SelectionExample

    列文章目录 UG/NX二次开发Siemens官方NXOPEN实例解析-1.1 BlockStyler/ColoredBlock UG/NX二次开发Siemens官方NXOPEN实例解析-1.2 Blo ...

  2. UG/NX二次开发Siemens官方NXOPEN实例解析—1.2 BlockStyler/EditExpression

    列文章目录 UG/NX二次开发Siemens官方NXOPEN实例解析-1.1 BlockStyler/ColoredBlock UG/NX二次开发Siemens官方NXOPEN实例解析-1.2 Blo ...

  3. UG/NX二次开发Siemens官方NXOPEN实例解析—1.3 BlockStyler/ExtrudewithPreview

    列文章目录 UG/NX二次开发Siemens官方NXOPEN实例解析-1.1 BlockStyler/ColoredBlock UG/NX二次开发Siemens官方NXOPEN实例解析-1.2 Blo ...

  4. UG/NX二次开发Siemens官方NXOPEN实例解析—2.8 DrawingCycle(图纸打印)

    列文章目录 UG/NX二次开发Siemens官方NXOPEN实例解析-2.1 AssemblyViewer(树列表) UG/NX二次开发Siemens官方NXOPEN实例解析-2.2 Selectio ...

  5. UG/NX二次开发Siemens官方NXOPEN实例解析—2.7 DiameterSymbol(标注符号)

    列文章目录 UG/NX二次开发Siemens官方NXOPEN实例解析-2.1 AssemblyViewer(树列表) UG/NX二次开发Siemens官方NXOPEN实例解析-2.2 Selectio ...

  6. UG/NX二次开发Siemens官方NXOPEN实例解析—2.6 CreateNote(注释)

    列文章目录 UG/NX二次开发Siemens官方NXOPEN实例解析-2.1 AssemblyViewer(树列表) UG/NX二次开发Siemens官方NXOPEN实例解析-2.2 Selectio ...

  7. UG/NX二次开发Siemens官方NXOPEN实例解析—2.5 QuickExtrude(拉伸)

    列文章目录 UG/NX二次开发Siemens官方NXOPEN实例解析-2.1 AssemblyViewer(树列表) UG/NX二次开发Siemens官方NXOPEN实例解析-2.2 Selectio ...

  8. UG/NX 二次开发(C#)自动出2D零件图(标准件配置Bata版)

    一.前言 昨天分享了自动出2D零件图的思路(UG/NX 二次开发(C#)自动出2D零件图思路),今天整理了Q群里各位大佬的意见,结合当前实际项目情况,做了一个可配置的半自动出图版本,暂且称之为标准件配 ...

  9. UG NX二次开发(C#)-装配-添加组件AddComponent

    在UG NX的使用过程中,装配是很重要的一环,本文是为了实现组件的批量装配,采用UG NX二次开发,采用的主要函数为AddComponent. AddComponent()的帮助说明如下: 其是属于N ...

最新文章

  1. matlab两个多项式相除,C++和MATLAB混合编程求解多项式系数(矩阵相除)
  2. 济南python工资一般多少钱-济南python编程培训班价格
  3. ecc加解密算法 c++_ECC加密算法的基本介绍
  4. iOS 10 的一个重要更新-自定义的通知界面
  5. 【转】面向对象之多态(向上转型与向下转型)
  6. Netty工作笔记0003---IO模型-BIO-Java原生IO
  7. sql 执行计划 嵌套循环_性能调优–嵌套和合并SQL循环与执行计划
  8. mysql 日期计算,今天,明天,本周,下周,本月,下月
  9. 使用N4BiasFieldCorrection处理MRI图像
  10. Kubernetes详解(二)——Kubernetes结构与资源对象
  11. 关于STM32 串口二、串口三串口调试助手无法显示的问题
  12. Dreamweaver制作漂亮的网页Flash电子相册
  13. echarts实现半圆饼图
  14. http: s18.me/ios.html,Public Key Infrastructure Configuration Guide, Cisco IOS XE Release 3S
  15. 股票多空量化策略通过合理释放beta收益一定程度上提升了组合的收益风险比?
  16. Bit Miracle Jpeg2000-SEO狼术
  17. think在PHP中什么意思,thinkphp框架是什么意思
  18. chrome无法检查更新解决方法
  19. 《SolidWorks 2014中文版机械设计从入门到精通》——2.3 草图编辑
  20. 巨蟹座 vs 狮子座

热门文章

  1. 怎样快速给多个视频添加水印?
  2. android qq账号登陆验证手机号码,qq绑定的手机号换了,登陆需要手机验证,怎么办?...
  3. 养生之道--21天改变体质
  4. ANSYS Workbench接触设置—对称和非对称接触
  5. 网络主机防泄密安全保护方案
  6. 新型的P2P下载技术工作原理(PPEASY)
  7. 服务器安全狗拦截微信,服务器软件安全狗误拦截百度蜘蛛
  8. maya多边形建模怎样做曲面_maya将曲面模型转换成多边形模型
  9. android5.0以上手机host修改教程
  10. 计算机登录忘记密码怎么办,电脑登录密码忘记了怎么办