NX二次开发:Checkmate例子根据dfa文件检查模型数据

打印 上一主题 下一主题

主题 1026|帖子 1026|积分 3078

NX中的checkmate功能是用于检查模型、图纸数据的工具,在UGOPEN中有例子。手动操作可以检查已加载的装配下所有零部件,可以设置通过后保存模型,检查结果保存到Teamcenter中,默认保存在零组件版本下。
代码中可以设置多个检查规则。相关设置可以在用户默认设置中进行设置。
  1.   1 //=============================
  2.   2 // Checkmate例子
  3.   3 //=============================
  4.   4 // Mandatory UF Includes
  5.   5 #include <uf.h>
  6.   6 #include <uf_object_types.h>
  7.   7 #include <uf_draw.h>
  8.   8 #include <uf_part.h>
  9.   9 #include <uf_ugmgr.h>
  10. 10 #include <uf_ui.h>
  11. 11 #include <uf_obj.h>
  12. 12 #include <uf_drf.h>
  13. 13
  14. 14 // Std C++ Includes
  15. 15 #include <iostream>
  16. 16 #include <sstream>
  17. 17 #include <vector>
  18. 18 #include <string>
  19. 19 #include <algorithm>
  20. 20 #include <tchar.h>
  21. 21 #include <atlconv.h>
  22. 22 #include <shellapi.h>
  23. 23
  24. 24 // check mate
  25. 25 #include <NXOpen/Validate_ValidationManager.hxx>
  26. 26 #include <NXOpen/Validate_Validator.hxx>
  27. 27 #include <NXOpen/Validate_ValidatorOptions.hxx>
  28. 28 #include <NXOpen/Validate_Parser.hxx>
  29. 29
  30. 30 #include <windows.h>
  31. 31 #undef CreateDialog
  32. 32 #pragma comment(lib,"shell32.lib")
  33. 33
  34. 34 using namespace NXOpen;
  35. 35 using std::string;
  36. 36 using std::exception;
  37. 37 using std::stringstream;
  38. 38 using std::endl;
  39. 39 using std::cout;
  40. 40 using std::cerr;
  41. 41
  42. 42 int ExecuteCheckerAndGetResults();
  43. 43
  44. 44 extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
  45. 45 {
  46. 46     try
  47. 47     {
  48. 48         UF_CALL(UF_initialize());
  49. 49
  50. 50         ExecuteCheckerAndGetResults();
  51. 51
  52. 52         UF_CALL(UF_terminate());
  53. 53     }
  54. 54     catch (const NXException& e1)
  55. 55     {
  56. 56         UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
  57. 57     }
  58. 58     catch (const exception& e2)
  59. 59     {
  60. 60         UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
  61. 61     }
  62. 62     catch (...)
  63. 63     {
  64. 64         UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
  65. 65     }
  66. 66 }
  67. 67
  68. 68 extern "C" DllExport int ufusr_ask_unload()
  69. 69 {
  70. 70     return (int)NXOpen::Session::LibraryUnloadOptionImmediately;// 调试用
  71. 71     //return (int)NXOpen::Session::LibraryUnloadOptionAtTermination;// 程序发布用
  72. 72     //return (int)NXOpen::Session::LibraryUnloadOptionExplicitly;
  73. 73 }
  74. 74
  75. 75 int ExecuteCheckerAndGetResults()
  76. 76 {
  77. 77     // Get the NX session, work part, display part.
  78. 78     Session *theSession = Session::GetSession();
  79. 79     Part *workPart(theSession->Parts()->Work());
  80. 80     Part *displayPart(theSession->Parts()->Display());
  81. 81
  82. 82     // Get the NX Check-Mate Validator object.
  83. 83     std::vector<Validate::Validator *> validators1;
  84. 84     theSession->ValidationManager()->FindValidator("Check-Mate", validators1);
  85. 85
  86. 86     // Get the NX Check-Mate ValidatorOptions, and set options.
  87. 87     Validate::ValidatorOptions *validatorOptions1;
  88. 88     validatorOptions1 = validators1[0]->ValidatorOptions();
  89. 89
  90. 90     validatorOptions1->SetSkipChecking(false);
  91. 91     validatorOptions1->SetSkipCheckingDontLoadPart(false);
  92. 92     validatorOptions1->SetSaveResultInTeamcenter(Validate::ValidatorOptions::SaveModeTypesSaveIfPassed);
  93. 93     validatorOptions1->SetSavePartFile(Validate::ValidatorOptions::SaveModeTypesSaveIfPassed);
  94. 94     validatorOptions1->SetSaveResultInPart(false);
  95. 95
  96. 96     // 2023_0328
  97. 97     validatorOptions1->SetAutoDisplayResults(Validate::ValidatorOptions::ResultsDisplayModeTypesAlwaysDisplay);
  98. 98     validatorOptions1->SetExcludeNonOwnerParts(true);
  99. 99     validatorOptions1->SetExcludeReadonlyParts(true);
  100. 100     validatorOptions1->SetGenerateCheckFlag(false);
  101. 101     validatorOptions1->SetGenerateLogFile(false);
  102. 102     validatorOptions1->SetStopOnError(false);
  103. 103     validatorOptions1->SetStopOnWarning(false);
  104. 104     // 2023_0328
  105. 105
  106. 106     // Clear part nodes if any.
  107. 107     validators1[0]->ClearPartNodes();
  108. 108
  109. 109     // Appends the full path of a part file or the current work part.
  110. 110     validators1[0]->AppendPartNode(workPart);
  111. 111
  112. 112     // Manually add this line to clean all existing tests
  113. 113     validators1[0]->ClearCheckerNodes();
  114. 114
  115. 115     // Select a checker and append it into the Validator object.
  116. 116     std::vector<NXString> classnames1(2);
  117. 117     classnames1[0] = "%mqc_report_browseable_features";//mqc_profile_modeling_cn.dfa
  118. 118     classnames1[1] = "%mqc_profile_modeling_cn";//mqc_profile_modeling_cn.dfa
  119. 119     validators1[0]->AppendCheckerNodes(classnames1);
  120. 120
  121. 121     // Execute the Check-Mate checker.
  122. 122     Validation::Result status1;
  123. 123     status1 = validators1[0]->Commit();
  124. 124
  125. 125     // Get a Parser object, and show the checker result.
  126. 126     std::vector<Validate::Parser *> parsers1;
  127. 127     theSession->ValidationManager()->FindParser("Validation Gadget", parsers1);
  128. 128     parsers1[0]->ClearResultObjects();
  129. 129     parsers1[0]->SetDataSource(Validate::Parser::DataSourceTypesMostRecentRun);
  130. 130     parsers1[0]->SetMaxDisplayObjects(10);
  131. 131     parsers1[0]->Commit();
  132. 132
  133. 133     return 0;
  134. 134 }
复制代码
 
设置、保存后、用户默认设置截图:

 
 
 
 调试GIF动态图:

 
黄河远上白云间,一片孤城万仞山。
羌笛何须怨杨柳,春风不度玉门关。
 
诗人初到凉州,面对黄河、边城的辽阔景象,又耳听着《折杨柳》曲,有感而发,写成了这首表现戍守边疆的士兵思念家乡情怀的诗作。
  诗的前两句描绘了西北边地广漠壮阔的风光。首句抓住自下(游)向上(游)、由近及远眺望黄河的特殊感受,描绘出“黄河远上白云间”的动人画面:汹涌澎湃波浪滔滔的黄河竟像一条丝带迤逦飞上云端。写得真是神思飞跃,气象开阔。诗人的另一名句“黄河入海流”,其观察角度与此正好相反,是自上而下的目送;而李白的“黄河之水天上来”,虽也写观望上游,但视线运动却又由远及近,与此句不同。“黄河入海流”和“黄河之水天上来”,同是着意渲染黄河一泻千里的气派,表现的是动态美。而“黄河远上白云间”,方向与河的流向相反,意在突出其源远流长的闲远仪态,表现的是一种静态美。同时展示了边地广漠壮阔的风光,不愧为千古奇句。
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

乌市泽哥

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表