点击查看详细介绍

移动复制对象,这样行吗

WW_TT_TOOLS 6月前 375 0

购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008  QQ号:85585969  


//
void TT_Move_Object_By_Axis::initialize_my()
{
//设置过滤
Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
std::vector<Selection::MaskTriple>maskArray(7);
maskArray[0] = NXOpen::Selection::MaskTriple(UF_solid_type, 0, 0);

maskArray[2] = NXOpen::Selection::MaskTriple(UF_line_type, 0, 0);
maskArray[3] = NXOpen::Selection::MaskTriple(UF_circle_type, 0, 0);
maskArray[4] = NXOpen::Selection::MaskTriple(UF_conic_type, 0, 0);
maskArray[5] = NXOpen::Selection::MaskTriple(UF_spline_type, 0, 0);
maskArray[1] = NXOpen::Selection::MaskTriple(UF_kanji_type, 0, 0);
maskArray[6] = NXOpen::Selection::MaskTriple(UF_point_type, 0, 0);
UI_Select_Obj->GetProperties()->SetSelectionFilter("SelectionFilter", action, maskArray);
}

//设置对话框切换
void TT_Move_Object_By_Axis::dialogShown_my()
{
//枚举移动复制控件的显示
std::vector<int>UI_Enum_MoveorCopy_VisibilityPros[2];
int EnumVisibilityValue[2][4]={
{0,1,1,0},
{1,0,0,1}
};
for (int i = 0; i < 4; i++)
{
UI_Enum_MoveorCopy_VisibilityPros[0].push_back(EnumVisibilityValue[0][i]);
UI_Enum_MoveorCopy_VisibilityPros[1].push_back(EnumVisibilityValue[1][i]);
}
//移动
if (UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==0||UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==1)
{
UI_Enum_MoveorCopy->SetEnumVisibility(UI_Enum_MoveorCopy_VisibilityPros[0]);
UI_Integer_Count->SetShow(false);
}
//复制
else
{
UI_Enum_MoveorCopy->SetEnumVisibility(UI_Enum_MoveorCopy_VisibilityPros[1]);
UI_Integer_Count->SetShow(true);
}
//枚举复制数量控件的显示
if (UI_Enum_Set->GetProperties()->GetEnum("Value")==0)
{
UI_Group4->SetShow(true);UI_Group5->SetShow(false);
}
else
{
UI_Group4->SetShow(false);UI_Group5->SetShow(true);
UI_Select_Obj->SetStepStatusAsString("Required");
}
//枚举XYZ方向控件的显示
std::vector<int>UI_Enum_XYZ_VisibilityPros[6];
int EnumXYZVisibilityValue[6][12]={
{0,1,1,0,1,0,1,0,1,0,1,0},
{1,0,0,1,1,0,1,0,1,0,1,0},
{1,0,1,0,0,1,1,0,1,0,1,0},
{1,0,1,0,1,0,0,1,1,0,1,0},
{1,0,1,0,1,0,1,0,0,1,1,0},
{1,0,1,0,1,0,1,0,1,0,0,1}
};
for (int i = 0; i < 12; i++)
{
UI_Enum_XYZ_VisibilityPros[0].push_back(EnumXYZVisibilityValue[0][i]);
UI_Enum_XYZ_VisibilityPros[1].push_back(EnumXYZVisibilityValue[1][i]);
UI_Enum_XYZ_VisibilityPros[2].push_back(EnumXYZVisibilityValue[2][i]);
UI_Enum_XYZ_VisibilityPros[3].push_back(EnumXYZVisibilityValue[3][i]);
UI_Enum_XYZ_VisibilityPros[4].push_back(EnumXYZVisibilityValue[4][i]);
UI_Enum_XYZ_VisibilityPros[5].push_back(EnumXYZVisibilityValue[5][i]);
}
//正X轴
if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==0||UI_Enum_Axis->GetProperties()->GetEnum("Value")==1)
{
UI_Enum_Axis->SetEnumVisibility(UI_Enum_XYZ_VisibilityPros[0]);
}
//负X轴
else if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==2||UI_Enum_Axis->GetProperties()->GetEnum("Value")==3)
{
UI_Enum_Axis->SetEnumVisibility(UI_Enum_XYZ_VisibilityPros[1]);
}
//正Y轴
else if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==4||UI_Enum_Axis->GetProperties()->GetEnum("Value")==5)
{
UI_Enum_Axis->SetEnumVisibility(UI_Enum_XYZ_VisibilityPros[2]);
}
//负Y轴
else if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==6||UI_Enum_Axis->GetProperties()->GetEnum("Value")==7)
{
UI_Enum_Axis->SetEnumVisibility(UI_Enum_XYZ_VisibilityPros[3]);
}
//正Z轴
else if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==8||UI_Enum_Axis->GetProperties()->GetEnum("Value")==9)
{
UI_Enum_Axis->SetEnumVisibility(UI_Enum_XYZ_VisibilityPros[4]);
}
//负Z轴
else
{
UI_Enum_Axis->SetEnumVisibility(UI_Enum_XYZ_VisibilityPros[5]);
}
}

//移动复制对象1次
void TT_Move_Object_By_Axis::moveobjeat_my()
{
UF_initialize();
//定义矩阵的变量
double translation[3]={0.0,0.0,0.0};
double matrix[12]={0.0};
if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==0||UI_Enum_Axis->GetProperties()->GetEnum("Value")==1)
{
translation[0] = UI_Expression_Distance->Value();
UI_Enum_Axis->GetProperties()->SetEnum("Value",0);
}
else if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==2||UI_Enum_Axis->GetProperties()->GetEnum("Value")==3)
{
translation[0] = -UI_Expression_Distance->Value();
UI_Enum_Axis->GetProperties()->SetEnum("Value",2);
}
else if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==4||UI_Enum_Axis->GetProperties()->GetEnum("Value")==5)
{
translation[1] = UI_Expression_Distance->Value();
UI_Enum_Axis->GetProperties()->SetEnum("Value",4);
}
else if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==6||UI_Enum_Axis->GetProperties()->GetEnum("Value")==7)
{
translation[1] = -UI_Expression_Distance->Value();
UI_Enum_Axis->GetProperties()->SetEnum("Value",6);
}
else if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==8||UI_Enum_Axis->GetProperties()->GetEnum("Value")==9)
{
translation[2] = UI_Expression_Distance->Value();
UI_Enum_Axis->GetProperties()->SetEnum("Value",8);
}
else if (UI_Enum_Axis->GetProperties()->GetEnum("Value")==10||UI_Enum_Axis->GetProperties()->GetEnum("Value")==11)
{
translation[2] = -UI_Expression_Distance->Value();
UI_Enum_Axis->GetProperties()->SetEnum("Value",10);
}
//得到矩阵变量
uf5943(translation,matrix);

//定义数据
int n_objects = 1;//移动对象的数量
int dest_layer = 0; //0为原始图层
int trace_curves = 2;//曲线鬼迹(1为创建曲线移动时的鬼迹,2为不创建移动时的鬼迹);
int move_or_copy; //1移动2复制
if (UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==0||UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==1)
{
move_or_copy=1;
}
else if (UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==2||UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==3)
{
move_or_copy=2;
}
//输出参数
tag_t copies = NULL_TAG;
tag_t trace_curve_group = NULL_TAG;
int status = 0 ;
//获得移动对象的TAG
std::vector<TaggedObject*>SelectObjects = UI_Select_Obj->GetProperties()->GetTaggedObjectVector("SelectedObjects");
tag_t objects = NULL_TAG;//移动的对象
std::vector<TaggedObject*>NewSelectObjects;
//去除参数
uf_list_p_t objects_list;
UF_MODL_create_list(&objects_list);
int type,subtype;
for (int i = 0; i < SelectObjects.size(); i++)
{
objects=SelectObjects[i]->Tag();
UF_OBJ_ask_type_and_subtype(objects,&type,&subtype);
if (type==UF_solid_type&&subtype==UF_solid_body_subtype)
{
if (UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==0||UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==1)
{
UF_MODL_put_list_item(objects_list,objects);
}
}
}
UF_MODL_delete_object_parms(objects_list);
UF_MODL_delete_list(&objects_list);
//复制或移动对象
for (int i = 0; i < SelectObjects.size(); i++)
{
objects=SelectObjects[i]->Tag();
uf5947(matrix,&objects,&n_objects,&move_or_copy,&dest_layer,&trace_curves,&copies,&trace_curve_group,&status);
if (UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==2||UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==3)
{
NewSelectObjects.push_back(dynamic_cast<NXOpen::TaggedObject *>(NXOpen::NXObjectManager::Get(copies)));
}
}
if (UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==2||UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==3)
{
UI_Select_Obj->SetSelectedObjects(NewSelectObjects);
}
UF_terminate();
}

//移动复制对象N次
void TT_Move_Object_By_Axis::more_moveobjeat_my()
{
if (UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==2||UI_Enum_MoveorCopy->GetProperties()->GetEnum("Value")==3)
{
if (UI_Integer_Count->Value()!=1)
{
for (int i = 1; i < UI_Integer_Count->Value(); i++)
{
moveobjeat_my();
}
}
}
}

0

最新回复 (0)
请登录后发表新帖