QQ登录

只需一步,快速开始

快捷登录

登录 或者 注册 请先

UG爱好者

查看: 1523|回复: 2
打印 上一主题 下一主题

[求助] 二次开发中如何实现管线选择,向ug自带的一样(nx 7.5)

[复制链接]

二级士官

Rank: 2

1

主题

15

帖子

367

积分
跳转到指定楼层
楼主
发表于 2020-12-13 12:32:07 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 loyalsword 于 2020-12-13 12:38 编辑

希望能够实现如ug自带的管线布置选择方式,如图中右侧


我现在的代码如下,红色部分是我自己写的,请各位大神指导一下。
  1. ......//省略没有改动的地方

  2. //------------------------------------------------------------------------------
  3. //---------------------Block UI Styler Callback Functions--------------------------
  4. //------------------------------------------------------------------------------

  5. //------------------------------------------------------------------------------
  6. //Callback Name: initialize_cb
  7. //------------------------------------------------------------------------------
  8. void JXGZ_XINGCHAI::initialize_cb()
  9. {
  10.     try
  11.     {
  12.         group0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("group0"));
  13.         selection0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("selection0"));
  14.         group = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("group"));
  15.         enum0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("enum0"));

  16.                 //管线选择过滤
  17.                 int response0;
  18.                 int count0;
  19.                 tag_t * objects0 ;
  20.                 int types0=UF_UI_ROUTE_SEL_ALL;
  21.                 int method0=UF_UI_ROUTE_SEL_METHOD_ROUTING;
  22.                 int scope0=UF_UI_SEL_SCOPE_WORK_PART;

  23.                 UF_UI_select_routing_objects("选择方式", "定义选择管线的方式:标准、路径、分支、管线布置",types0 ,&method0, scope0, &response0, &count0, &objects0 );
  24.                 //UF_UI_route_invoke_callback("",count0,objects0);
  25.                 UF_free(objects0);
  26.     }
  27.     catch(exception& ex)
  28.     {
  29.         //---- Enter your exception handling code here -----
  30.         JXGZ_XINGCHAI::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
  31.     }
  32. }

  33. //------------------------------------------------------------------------------
  34. //Callback Name: dialogShown_cb
  35. //This callback is executed just before the dialog launch. Thus any value set
  36. //here will take precedence and dialog will be launched showing that value.
  37. //------------------------------------------------------------------------------
  38. void JXGZ_XINGCHAI::dialogShown_cb()
  39. {
  40.     try
  41.     {
  42.         //---- Enter your callback code here -----
  43.            //管线选择过滤
  44.                 int response0;
  45.                 int count0;
  46.                 tag_t * objects0 ;
  47.                 int types0=UF_UI_ROUTE_SEL_ALL;
  48.                 int method0=UF_UI_ROUTE_SEL_METHOD_ROUTING;
  49.                 int scope0=UF_UI_SEL_SCOPE_WORK_PART;

  50.                 UF_UI_select_routing_objects("选择方式", "定义选择管线的方式:标准、路径、分支、管线布置",types0 ,&method0, scope0, &response0, &count0, &objects0 );
  51.                 //UF_UI_route_invoke_callback("",count0,objects0);
  52.                 UF_free(objects0);
  53.     }
  54.     catch(exception& ex)
  55.     {
  56.         //---- Enter your exception handling code here -----
  57.         JXGZ_XINGCHAI::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
  58.     }
  59. }

  60. //------------------------------------------------------------------------------
  61. //Callback Name: apply_cb
  62. //------------------------------------------------------------------------------
  63. int JXGZ_XINGCHAI::apply_cb()
  64. {
  65.     int errorCode = 0;
  66.     try
  67.     {
  68.         //---- Enter your callback code here -----

  69.                 UF_initialize();
  70.                 //管线选择过滤
  71.                 int response0;
  72.                 int count0;
  73.                 tag_t * objects0 ;
  74.                 int types0=UF_UI_ROUTE_SEL_ALL;
  75.                 int method0=UF_UI_ROUTE_SEL_METHOD_ROUTING;
  76.                 int scope0=UF_UI_SEL_SCOPE_WORK_PART;

  77.                 UF_UI_select_routing_objects("选择方式", "定义选择管线的方式:标准、路径、分支、管线布置",types0 ,&method0, scope0, &response0, &count0, &objects0 );
  78.                 //UF_UI_route_invoke_callback("",count0,objects0);
  79.                 UF_free(objects0);        


  80.                 //获取枚举值
  81.                 char * charenumvalue=NULL;
  82.                 int enumvalue=0;
  83.                 enumvalue = this->enum0->GetProperties()->GetEnum("Value");
  84.                 //转化为char*输出
  85.                 ostringstream str_enum;
  86.                 str_enum<<enumvalue;
  87.                 string str1enum=str_enum.str();
  88.                 charenumvalue=(char*)str1enum.c_str();
  89.                 uc1601(charenumvalue,0);

  90.                 //std::vector<TaggedObject*> seg_path=selection0->GetSelectedObjects();
  91.                 //获取对象tag
  92.                 PropertyList* pathselect = selection0->GetProperties();
  93.                 std::vector<NXOpen::TaggedObject*> seg_path = pathselect->GetTaggedObjectVector("SelectedObjects");
  94.                 delete pathselect;
  95.                 pathselect = NULL;

  96.                 tag_t seg_Tag[1000];
  97.                 int type0=0;
  98.                 int subtype0=0;

  99.                 for (int i=0;i<seg_path.size();i++)
  100.                 {
  101.                         seg_Tag[i] = seg_path[i]->Tag();
  102.                         UF_OBJ_ask_type_and_subtype(seg_Tag[i],&type0,&subtype0);
  103.                         char output0[256];
  104.                         sprintf(output0,"类型是:%d,子类型是:%d,管线段数:%d",type0,subtype0,seg_path.size());
  105.                         uc1601(output0,1);
  106.                 }



  107.                 //根据枚举设置型材名字stock_os_part_name
  108.                 char* stock_os_part_name="H=10,L=10,R=1,T=1";
  109.                 if (enumvalue==0)
  110.                 {
  111.                         stock_os_part_name="H=10,L=10,R=1,T=1";
  112.                 }
  113.                 else if (enumvalue==1)
  114.                 {
  115.                         stock_os_part_name="H=20,L=10,R=2,T=1";
  116.                 }
  117.                 else if (enumvalue==2)
  118.                 {
  119.                         stock_os_part_name="H=40,L=40,R=5,T=2";
  120.                 }
  121.                 //定义型材特征参数
  122.                 tag_t stock_data=NULL_TAG;
  123.                 tag_t anchor=NULL_TAG;
  124.                 tag_t cross=NULL_TAG;
  125.                 UF_ROUTE_load_stock_data("PIPE_YJYX.prt", stock_os_part_name, UF_ROUTE_STYLE_DETAIL, &stock_data, &anchor, &cross );//加载型材
  126.                 UF_ROUTE_remove_stock(seg_path.size(), &seg_Tag[0]);//移除现有型材
  127.                 UF_ROUTE_assign_stock(stock_data, anchor,cross, seg_path.size(), &seg_Tag[0] );//赋予新型材

  128.                 //UF_free(seg_Tag);
  129.                 UF_terminate();
  130.     }
  131.     catch(exception& ex)
  132.     {
  133.         //---- Enter your exception handling code here -----
  134.         errorCode = 1;
  135.         JXGZ_XINGCHAI::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
  136.     }
  137.     return errorCode;
  138. }

  139. //------------------------------------------------------------------------------
  140. //Callback Name: update_cb
  141. //------------------------------------------------------------------------------
  142. int JXGZ_XINGCHAI::update_cb(NXOpen::BlockStyler::UIBlock* block)
  143. {
  144.     try
  145.     {
  146.         if(block == selection0)
  147.         {
  148.         //---------Enter your code here-----------
  149.         }
  150.         else if(block == enum0)
  151.         {
  152.         //---------Enter your code here-----------
  153.         }
  154.     }
  155.     catch(exception& ex)
  156.     {
  157.         //---- Enter your exception handling code here -----
  158.         JXGZ_XINGCHAI::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
  159.     }
  160.     return 0;
  161. }

  162. //------------------------------------------------------------------------------
  163. //Callback Name: ok_cb
  164. //------------------------------------------------------------------------------
  165. int JXGZ_XINGCHAI::ok_cb()
  166. {
  167.     int errorCode = 0;
  168.     try
  169.     {
  170.         errorCode = apply_cb();
  171.     }
  172.     catch(exception& ex)
  173.     {
  174.         //---- Enter your exception handling code here -----
  175.         errorCode = 1;
  176.         JXGZ_XINGCHAI::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
  177.     }
  178.     return errorCode;
  179. }

  180. //------------------------------------------------------------------------------
  181. //Callback Name: filter_cb
  182. //------------------------------------------------------------------------------
  183. int JXGZ_XINGCHAI::filter_cb(NXOpen::BlockStyler::UIBlock*  block, NXOpen::TaggedObject* selectObject)
  184. {
  185.     return(UF_UI_SEL_ACCEPT);
  186. }
复制代码


有奖推广贴子: 

回复

使用道具 举报

贵宾

Rank: 9Rank: 9Rank: 9

14

主题

270

帖子

8337

积分

论坛技术员论坛贡献

推荐
发表于 2020-12-13 13:16:00 | 只看该作者
这个选择的地方我可以做到跟官方一模一样。
如果你有预算的话,可以找我:QQ125317589
回复 支持 1 反对 0

使用道具 举报

二级士官

Rank: 2

1

主题

15

帖子

367

积分
板凳
 楼主| 发表于 2020-12-13 14:16:31 | 只看该作者
Jefft* 发表于 2020-12-13 13:16
这个选择的地方我可以做到跟官方一模一样。
如果你有预算的话,可以找我:QQ125317589

大哥,我是自己想做,没有单位预算的,希望能帮帮忙说说
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

 
 
QQ:1359218528
工作时间:
9:00-17:00
 
微信公众号
手机APP
机械社区
微信小程序

手机版|UG爱好者论坛 ( 京ICP备10217105号-2 )    论坛管理员QQ:1359218528

本站信息均由会员发表,不代表本网站立场,如侵犯了您的权利请联系管理员,邮箱:1359218528@qq.com  

Powered by UG爱好者 X3.2  © 2001-2014 Comsenz Inc. GMT+8, 2024-6-4 19:37

返回顶部