UF_OBJ_cycle心得
UF_initialize();
char msg[111];
theSession->ListingWindow()->Open();
Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
//////组件tag遍历 子类型
tag_t part_tag;
tag_t occ_tag;
Assemblies::Component *component1(dynamic_cast<Assemblies::Component *>(workPart->ComponentAssembly()->RootComponent()->FindObject("COMPONENT 1 1")));
occ_tag = component1->Tag(); //但是此处只是一个occ Tag.不是原零件的tag
part_tag = UF_ASSEM_ask_prototype_of_occ(occ_tag);
sprintf(msg,"组件的part_Tag:%d",part_tag);
theSession->ListingWindow()->WriteLine(msg);
/*////体选择传递
std::vector<TaggedObject*>objects=this->selection0->GetProperties()->GetTaggedObjectVector("SelectedObjects"); //但是此处只是一个occ Tag.不是原零件的tag
///Body *body = dynamic_cast<Body *>(objects[0]); ///////由于返回的是TaggedObject类型的一个vector,故需进行类型转换。
sprintf(msg,"选择的tag%d",objects[0]->Tag()); //选择时注意是compont还是body ,得到的tag会不同
theSession->ListingWindow()->WriteLine(msg);*/
char part_fspec[MAX_FSPEC_SIZE+1];
int curr_part, num_parts;
int count_1 = 0;
int type = UF_line_type; //可以查询line, sketch,其他的edge,feature,solid摸不清规律
tag_t part;
/*当前共打开 多少部件
num_parts = UF_PART_ask_num_parts();
sprintf(msg,"数量为:%d",num_parts);
theSession->ListingWindow()->WriteLine(msg);
////t第几个部件是什么,此两函数配合使用
part = UF_PART_ask_nth_part( 0 );
UF_PART_ask_part_name( part, part_fspec );
sprintf(msg,"第一个名称为:%s,tag为%d",part_fspec,part);
theSession->ListingWindow()->WriteLine(msg);*/
/* Start the cycling process by passing in a NULL_TAG. */
tag_t feature = NULL_TAG;
/*///不重复的Featture优先用名称,不是的再用name_and_type
int count = 0;
tag_t foundThis = NULL_TAG;
tag_t * object ;
UF_OBJ_cycle_by_name("line4",&foundThis);
while ( foundThis != NULL_TAG )
{
count++;
UF_OBJ_cycle_by_name("k1",&foundThis);
}
sprintf(msg,"查询名称的数量tag:%d",count);
theSession->ListingWindow()->WriteLine(msg);
////不重复的Featture优先用名称,不是的再用名称和类型 */
const char * name= "LINE4" ; ///一条直线也分特征名和(对象)名称,注意此处一定是对象名
UF_OBJ_cycle_by_name_and_type(part_tag,name,type, TRUE, &feature);
while ( feature != NULL_TAG )
{
count_1++;
UF_OBJ_cycle_by_name_and_type(part_tag, name,type, TRUE, &feature);//此功能和UF_OBJ_cycle_by_name一样,主要还是遍历特征树这内的内容。而不会遍历边 体等不在树中的对象。否则请用UF_OBJ_cycle_by_by_name_and_type
}
sprintf(msg,"数量tag:%d",count_1);
theSession->ListingWindow()->WriteLine(msg);
/////////////////
//UF_OBJ_cycle_objs_in_part(part_tag, type, &feature ); //此功能和UF_OBJ_cycle_by_name一样,主要还是遍历特征树这内的内容。而不会遍历边 体等不在树中的对象。否则请用UF_OBJ_cycle_by_by_name_and_type
///* Keep cycling until there are no more features to cycle. */
//while ( feature != NULL_TAG )
//{
// count_1++;
// UF_OBJ_cycle_objs_in_part(part_tag, type, &feature );//此功能和UF_OBJ_cycle_by_name一样,主要还是遍历特征树这内的内容。而不会遍历边 体等不在树中的对象。否则请用UF_OBJ_cycle_by_by_name_and_type
//}
//sprintf(msg,"数量tag:%d",count_1);
//theSession->ListingWindow()->WriteLine(msg);
UF_terminate();