ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

多组件 装配

2021-08-12 08:00:27  阅读:189  来源: 互联网

标签:装配 dynamic feature cast tag 组件 UF type


int WuCanJieMian::apply_cb()
{
int errorCode = 0;
try
{
//---- Enter your callback code here -----+
UF_initialize();
char msg[100];
Session *theSession = Session::GetSession();
Part *displayPart(theSession->Parts()->Display());
Part *workPart(theSession->Parts()->Work());
tag_t parentPart = UF_PART_ask_display_part();

cycleLine();
/*theSession->ListingWindow()->Open();
sprintf(msg,"LIne数量:%d",lineNum.size());
theSession->ListingWindow()->WriteLine(msg);*/

//////////添加组件

///自悟新方法,原来是*component1,现在定义为std::vector,成一数组,可以在i不确定的情况下动态定义
std::vector<Assemblies::Component*> compNum;
for(int i=0;i<lineNum.size()-1;i++)
{

Assemblies::Component *component0;
compNum.push_back(component1);

}
///自悟新方法,原来是*component1,现在定义为std::vector,成一数组,可以在i不确定的情况下动态定义*/

for(int i=0;i<lineNum.size()-1;i++)
{

line1 =dynamic_cast<Line *>( NXObjectManager::Get(lineNum[i])); //dynamic_cast 将 TaggedObject对象指针转换为实际的 NX 对象指针
line2 =dynamic_cast<Line *>( NXObjectManager::Get(lineNum[i+1])); //dynamic_cast 将 TaggedObject对象指针转换为实际的 NX 对象指针

//添加组件
Point3d basePoint1(0.0, 0.0, 0.0);
Matrix3x3 orientation1;
orientation1.Xx = 1.0;
orientation1.Xy = 0.0;
orientation1.Xz = 0.0;
orientation1.Yx = 0.0;
orientation1.Yy = 1.0;
orientation1.Yz = 0.0;
orientation1.Zx = 0.0;
orientation1.Zy = 0.0;
orientation1.Zz = 1.0;
PartLoadStatus *partLoadStatus1;

/*///自悟新方法,原来是*component1,现在定义为std::vector,成一数组,可以在i不确定的情况下动态定义
std::vector<Assemblies::Component*> compNum;
Assemblies::Component *component1;
compNum.push_back(component1);
///自悟新方法,原来是*component1,现在定义为std::vector,成一数组,可以在i不确定的情况下动态定义*/

//Assemblies::Component *component1;////原函数
compNum[i] = workPart->ComponentAssembly()->AddComponent("E:\\bgl\\0lib\\WT57-10H0-001.prt", "model", "1", basePoint1, orientation1, -1, &partLoadStatus1);
delete partLoadStatus1;

component1 = compNum[i];
assemPart();

//tag_t part_tag;
//tag_t occ_tag;
//occ_tag = component1[0]->Tag(); //但是此处只是一个occ Tag.不是原零件的tag
//part_tag = UF_ASSEM_ask_prototype_of_occ(occ_tag);
//char msg[111];
//
///////获取选择对象的进行动态转换(这个是成功的)
///*Assemblies::Component *component1(dynamic_cast<Assemblies::Component *>(workPart->ComponentAssembly()->RootComponent()->FindObject("COMPONENT WT57-10H0-001 1")));
//std::vector<TaggedObject*>objects1 = this->selection0->GetProperties()->GetTaggedObjectVector("SelectedObjects");
//Line *line7=NULL;
//line7 = dynamic_cast<Line *>(objects1[0]);
//theSession->ListingWindow()->Open();
//sprintf(msg,"数量tag:%d",line7->Tag());
//theSession->ListingWindow()->WriteLine(msg);*/
//////////////
////Assemblies::Component *component1(dynamic_cast<Assemblies::Component *>(workPart->ComponentAssembly()->RootComponent()->FindObject("COMPONENT WT57-10H0-001 1")));

//tag_t feature= NULL_TAG ;
//tag_t feature1= NULL_TAG ;
//std::vector<tag_t> line7Num;
//std::vector<tag_t> line8Num;
//int type = UF_line_type; //可以查询line, sketch,其他的edge,feature,solid摸不清规律
//const char * name7= "LINE7" ; ///一条直线也分特征名和(对象)名称,注意此处一定是对象名
//UF_OBJ_cycle_by_name_and_type(parentPart,name7,type, TRUE, &feature);
//

////while ( feature != NULL_TAG )
////{
//// line7Num.push_back(feature);
//// UF_OBJ_cycle_by_name_and_type(part_tag, name7,type, TRUE, &feature);//此功能和UF_OBJ_cycle_by_name一样,主要还是遍历特征树这内的内容。而不会遍历边 体等不在树中的对象。否则请用UF_OBJ_cycle_by_by_name_and_type
////
////}
///*theSession->ListingWindow()->Open();
//sprintf(msg,"数量tag:%d",line7Num[i]);
//theSession->ListingWindow()->WriteLine(msg);*/
//
//Line *line7 = dynamic_cast<Line*>(NXObjectManager::Get(feature));
//

//const char * name8= "LINE8" ; ///一条直线也分特征名和(对象)名称,注意此处一定是对象名
//feature= NULL_TAG;
//UF_OBJ_cycle_by_name_and_type(parentPart,name8,type, TRUE, &feature);
////while ( feature != NULL_TAG )
////{
//// line8Num.push_back(feature);
//// UF_OBJ_cycle_by_name_and_type(part_tag, name8,type, TRUE, &feature);//此功能和UF_OBJ_cycle_by_name一样,主要还是遍历特征树这内的内容。而不会遍历边 体等不在树中的对象。否则请用UF_OBJ_cycle_by_by_name_and_type

////}

//Line *line8 = dynamic_cast<Line*>(NXObjectManager::Get(feature));
}



UF_terminate();
}

 

void WuCanJieMian::cycleLine()
{
Session *theSession = Session::GetSession();
Part *displayPart(theSession->Parts()->Display());
Part *workPart(theSession->Parts()->Work());

Features::Feature *fcList;
std::vector<NXObject *> entitiesArray; //std::vector是一种数组定义方式
Features::FeatureCollection *fc=workPart->Features();//迭代
Features::FeatureCollection::iterator itr=fc->begin();//获得第一个特征


for (;itr!=fc->end();++itr) //循环获得所有特征
{
fcList=(*itr); //获得特征赋值给fcList
NXString featType = NULL;
featType = fcList->FeatureType();

/*theSession->ListingWindow()->WriteLine(fcList->FeatureType());*/
if(!strcmp(featType.GetLocaleText(),"LINE"))
{
//lineNum.push_back(fcList->Tag());

entitiesArray = fcList->GetEntities(); //GetEntities方法,实体下0对象,Lineg下1对对象,基准下7对象,点集下对象最多
lineNum.push_back(entitiesArray[0]->Tag());

}

}

//line1 =dynamic_cast<Line *>(entitiesArray[0]);

/*for(int i=0;i<lineNum.size();i++)
//{
// //NXObjectManager::Get(lineNum[i]);//通过tag得到 TaggedObject 对象指针.
////line1 =dynamic_cast<Line *>( NXObjectManager::Get(lineNum[i])); //dynamic_cast 将 TaggedObject对象指针转换为实际的 NX 对象指针
}*/

/*line1 = dynamic_cast<Line*>(entitiesArray[0]);
line2 = dynamic_cast<Line*>(entitiesArray[0]); */
//line1 =dynamic_cast<Line *>( NXObjectManager::Get(lineNum[0])); //dynamic_cast 将 TaggedObject对象指针转换为实际的 NX 对象指针
//line2 =dynamic_cast<Line *>( NXObjectManager::Get(lineNum[1])); //dynamic_cast 将 TaggedObject对象指针转换为实际的 NX 对象指针

}

void WuCanJieMian::assemPart()
{

Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
tag_t parentPart = UF_PART_ask_display_part();

/////////////////获取Line7,Line8
tag_t feature= NULL_TAG ;
int type = UF_line_type; //可以查询line, sketch,其他的edge,feature,solid摸不清规律
const char * name7= "LINE7" ; ///一条直线也分特征名和(对象)名称,注意此处一定是对象名
UF_OBJ_cycle_by_name_and_type(parentPart,name7,type, TRUE, &feature);
Line *line7 = dynamic_cast<Line*>(NXObjectManager::Get(feature));

feature= NULL_TAG;
const char * name8= "LINE8" ; ///一条直线也分特征名和(对象)名称,注意此处一定是对象名
UF_OBJ_cycle_by_name_and_type(parentPart,name8,type, TRUE, &feature);
Line *line8 = dynamic_cast<Line*>(NXObjectManager::Get(feature));
///////////////////////////////////////

Positioning::ComponentPositioner *componentPositioner1;
componentPositioner1 = workPart->ComponentAssembly()->Positioner();

componentPositioner1->ClearNetwork();
componentPositioner1->BeginAssemblyConstraints();

Positioning::Network *network1;
network1 = componentPositioner1->EstablishNetwork();

Positioning::ComponentNetwork *componentNetwork1(dynamic_cast<Positioning::ComponentNetwork *>(network1));
componentNetwork1->SetMoveObjectsState(true);

Assemblies::Component *nullAssemblies_Component(NULL);
componentNetwork1->SetDisplayComponent(nullAssemblies_Component);

//第一组
Positioning::Constraint *constraint1;
constraint1 = componentPositioner1->CreateConstraint();

Positioning::ComponentConstraint *componentConstraint1(dynamic_cast<Positioning::ComponentConstraint *>(constraint1));
componentConstraint1->SetConstraintAlignment(Positioning::Constraint::AlignmentInferAlign);
componentConstraint1->SetConstraintType(Positioning::Constraint::TypeTouch);
/////定义约束对象

/////获取选择对象的进行动态转换(这个是成功的)
/*std::vector<TaggedObject*>objects1 = this->selection01->GetProperties()->GetTaggedObjectVector("SelectedObjects");
Line *line3=NULL;
line3 = dynamic_cast<Line *>(objects1[0]); */

////装配进来的件就不用选择了
Positioning::ConstraintReference *constraintReference1;
constraintReference1 = componentConstraint1->CreateConstraintReference(component1, line7, false, false, false);

/*////获取选择对象的进行动态转换(这个是成功的)
std::vector<TaggedObject*>objects2 = this->edge_select01->GetProperties()->GetTaggedObjectVector("SelectedObjects");
//objects2[0]->Tag();
Line *line4=NULL;
line4 = dynamic_cast<Line *>(objects2[0]);*/


///定义约束对象
/*Positioning::ConstraintReference *constraintReference1;
constraintReference1 = componentConstraint1->CreateConstraintReference(component1, line3, false, false, false);*/

Positioning::ConstraintReference *constraintReference2;
constraintReference2 = componentConstraint1->CreateConstraintReference(workPart->ComponentAssembly(), line1, false, false, false);

constraintReference2->SetFixHint(true);

componentNetwork1->Solve();
//第二组
Positioning::Constraint *constraint2;
constraint2 = componentPositioner1->CreateConstraint();

Positioning::ComponentConstraint *componentConstraint2(dynamic_cast<Positioning::ComponentConstraint *>(constraint2));
componentConstraint2->SetConstraintAlignment(Positioning::Constraint::AlignmentInferAlign);
componentConstraint2->SetConstraintType(Positioning::Constraint::TypeTouch);

/////获取选择对象的进行动态转换(这个是成功的)
Positioning::ConstraintReference *constraintReference3;
constraintReference3 = componentConstraint2->CreateConstraintReference(component1, line8, false, false, false);

Positioning::ConstraintReference *constraintReference4;
constraintReference4 = componentConstraint2->CreateConstraintReference(workPart->ComponentAssembly(), line2, false, false, false);

constraintReference4->SetFixHint(true);
componentNetwork1->Solve();

componentPositioner1->ClearNetwork();
componentPositioner1->EndAssemblyConstraints();

}

 

标签:装配,dynamic,feature,cast,tag,组件,UF,type
来源: https://www.cnblogs.com/glz7519/p/15131013.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有