二次开发中如何实现管线选择,向ug自带的一样(nx 7.5)
本帖最后由 loyalsword 于 2020-12-13 12:38 编辑希望能够实现如ug自带的管线布置选择方式,如图中右侧
我现在的代码如下,红色部分是我自己写的,请各位大神指导一下。......//省略没有改动的地方
//------------------------------------------------------------------------------
//---------------------Block UI Styler Callback Functions--------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//Callback Name: initialize_cb
//------------------------------------------------------------------------------
void JXGZ_XINGCHAI::initialize_cb()
{
try
{
group0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("group0"));
selection0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("selection0"));
group = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("group"));
enum0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("enum0"));
//管线选择过滤
int response0;
int count0;
tag_t * objects0 ;
int types0=UF_UI_ROUTE_SEL_ALL;
int method0=UF_UI_ROUTE_SEL_METHOD_ROUTING;
int scope0=UF_UI_SEL_SCOPE_WORK_PART;
UF_UI_select_routing_objects("选择方式", "定义选择管线的方式:标准、路径、分支、管线布置",types0 ,&method0, scope0, &response0, &count0, &objects0 );
//UF_UI_route_invoke_callback("",count0,objects0);
UF_free(objects0);
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
JXGZ_XINGCHAI::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 JXGZ_XINGCHAI::dialogShown_cb()
{
try
{
//---- Enter your callback code here -----
//管线选择过滤
int response0;
int count0;
tag_t * objects0 ;
int types0=UF_UI_ROUTE_SEL_ALL;
int method0=UF_UI_ROUTE_SEL_METHOD_ROUTING;
int scope0=UF_UI_SEL_SCOPE_WORK_PART;
UF_UI_select_routing_objects("选择方式", "定义选择管线的方式:标准、路径、分支、管线布置",types0 ,&method0, scope0, &response0, &count0, &objects0 );
//UF_UI_route_invoke_callback("",count0,objects0);
UF_free(objects0);
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
JXGZ_XINGCHAI::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
//------------------------------------------------------------------------------
//Callback Name: apply_cb
//------------------------------------------------------------------------------
int JXGZ_XINGCHAI::apply_cb()
{
int errorCode = 0;
try
{
//---- Enter your callback code here -----
UF_initialize();
//管线选择过滤
int response0;
int count0;
tag_t * objects0 ;
int types0=UF_UI_ROUTE_SEL_ALL;
int method0=UF_UI_ROUTE_SEL_METHOD_ROUTING;
int scope0=UF_UI_SEL_SCOPE_WORK_PART;
UF_UI_select_routing_objects("选择方式", "定义选择管线的方式:标准、路径、分支、管线布置",types0 ,&method0, scope0, &response0, &count0, &objects0 );
//UF_UI_route_invoke_callback("",count0,objects0);
UF_free(objects0);
//获取枚举值
char * charenumvalue=NULL;
int enumvalue=0;
enumvalue = this->enum0->GetProperties()->GetEnum("Value");
//转化为char*输出
ostringstream str_enum;
str_enum<<enumvalue;
string str1enum=str_enum.str();
charenumvalue=(char*)str1enum.c_str();
uc1601(charenumvalue,0);
//std::vector<TaggedObject*> seg_path=selection0->GetSelectedObjects();
//获取对象tag
PropertyList* pathselect = selection0->GetProperties();
std::vector<NXOpen::TaggedObject*> seg_path = pathselect->GetTaggedObjectVector("SelectedObjects");
delete pathselect;
pathselect = NULL;
tag_t seg_Tag;
int type0=0;
int subtype0=0;
for (int i=0;i<seg_path.size();i++)
{
seg_Tag = seg_path->Tag();
UF_OBJ_ask_type_and_subtype(seg_Tag,&type0,&subtype0);
char output0;
sprintf(output0,"类型是:%d,子类型是:%d,管线段数:%d",type0,subtype0,seg_path.size());
uc1601(output0,1);
}
//根据枚举设置型材名字stock_os_part_name
char* stock_os_part_name="H=10,L=10,R=1,T=1";
if (enumvalue==0)
{
stock_os_part_name="H=10,L=10,R=1,T=1";
}
else if (enumvalue==1)
{
stock_os_part_name="H=20,L=10,R=2,T=1";
}
else if (enumvalue==2)
{
stock_os_part_name="H=40,L=40,R=5,T=2";
}
//定义型材特征参数
tag_t stock_data=NULL_TAG;
tag_t anchor=NULL_TAG;
tag_t cross=NULL_TAG;
UF_ROUTE_load_stock_data("PIPE_YJYX.prt", stock_os_part_name, UF_ROUTE_STYLE_DETAIL, &stock_data, &anchor, &cross );//加载型材
UF_ROUTE_remove_stock(seg_path.size(), &seg_Tag);//移除现有型材
UF_ROUTE_assign_stock(stock_data, anchor,cross, seg_path.size(), &seg_Tag );//赋予新型材
//UF_free(seg_Tag);
UF_terminate();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
JXGZ_XINGCHAI::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Callback Name: update_cb
//------------------------------------------------------------------------------
int JXGZ_XINGCHAI::update_cb(NXOpen::BlockStyler::UIBlock* block)
{
try
{
if(block == selection0)
{
//---------Enter your code here-----------
}
else if(block == enum0)
{
//---------Enter your code here-----------
}
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
JXGZ_XINGCHAI::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
//------------------------------------------------------------------------------
//Callback Name: ok_cb
//------------------------------------------------------------------------------
int JXGZ_XINGCHAI::ok_cb()
{
int errorCode = 0;
try
{
errorCode = apply_cb();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
errorCode = 1;
JXGZ_XINGCHAI::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return errorCode;
}
//------------------------------------------------------------------------------
//Callback Name: filter_cb
//------------------------------------------------------------------------------
int JXGZ_XINGCHAI::filter_cb(NXOpen::BlockStyler::UIBlock*block, NXOpen::TaggedObject* selectObject)
{
return(UF_UI_SEL_ACCEPT);
}
这个选择的地方我可以做到跟官方一模一样。
如果你有预算的话,可以找我:QQ125317589 Jefft* 发表于 2020-12-13 13:16
这个选择的地方我可以做到跟官方一模一样。
如果你有预算的话,可以找我:QQ125317589
大哥,我是自己想做,没有单位预算的,希望能帮帮忙说说
页:
[1]