extern "C" DllExport void Feature_Fun() { /* Initialize the API environment */ int errorCode = UF_initialize(); if ( 0 == errorCode ) { /* TODO: Add your application code here */ char part_fspec[MAX_FSPEC_SIZE+1]; //目錄 int curr_part, num_parts; //當前零件;零件總數(shù) int type; //Type of object on which to cycle int count_1; //用于輸出特征總數(shù) tag_t part; //零件被識別的唯一標識 tag_t feature; //特征被識別的唯一標識 char chr[50]; int i=0; char *strings=NULL,*feature_name=NULL; int number_of_exps; //指與當前特征有關的表達式的數(shù)量 tag_t *exps=NULL; double value; Json::Value root; Json::Value arrayObj; Json::Value item; ofstream outfile("d://public.json",ios::out); if (!outfile) { std::cerr << "open error!" << endl; exit(1); } num_parts = UF_PART_ask_num_parts(); /* Get the total number of loaded parts. */ for ( curr_part=0 ; curr_part < num_parts ; curr_part++ ) { part = UF_PART_ask_nth_part( curr_part ); //Get the part tag for the current part number of the //loaded part and get its part name. UF_PART_ask_part_name( part, part_fspec ); //Returns the file specification associated with a part tag. count_1 = 0; type = UF_feature_type; feature = NULL_TAG; UF_UI_open_listing_window(); sprintf(chr,"第 %d 個零件: ",curr_part+1); UF_UI_write_listing_window(chr); UF_UI_write_listing_window(part_fspec); UF_UI_write_listing_window("\n"); UF_OBJ_cycle_objs_in_part( part, type, &feature ); /* Start the cycling process by passing in a NULL_TAG. */ /* Keep cycling until there are no more features to cycle. */ //outfile << chr << part_fspec << endl; while ( feature != NULL_TAG ) { UF_MODL_ask_exps_of_feature(feature,&number_of_exps,&exps);//Gets all expressions related to the supplied feature. UF_MODL_ask_feat_name(feature , &feature_name); //得到特征名 sprintf(chr," 第 %d 個特征:",count_1+1); UF_UI_write_listing_window(chr); UF_UI_write_listing_window(" "); UF_UI_write_listing_window(feature_name); UF_UI_write_listing_window("\n"); item["Name"]= feature_name; //item["Type"]= "STRING"; //outfile << chr << " " << feature_name << endl; for( i=0;i<number_of_exps;i++) { UF_UI_write_listing_window(" "); UF_MODL_ask_exp_tag_string(exps[i],&strings); UF_MODL_ask_exp_tag_value(exps[i],&value); UF_UI_write_listing_window(strings); UF_UI_write_listing_window("\n"); item["Parameter"][i]["name"] = strings; item["Parameter"][i]["value"] =value; } arrayObj.append(item); root["feature"] = arrayObj; count_1++; UF_OBJ_cycle_objs_in_part( part, type, &feature ); root["path"] =part_fspec; } string out = root.toStyledString(); outfile << out << endl; sprintf(chr," 總共:%d 個特征\n",count_1); UF_UI_write_listing_window(chr); UF_UI_write_listing_window("\n"); } UF_free(strings); //釋放空間 UF_free(exps); //釋放空間 UF_free(feature_name); sprintf(chr," 總共:%d 個零件\n",num_parts); UF_UI_write_listing_window(chr); UF_UI_write_listing_window("\n"); outfile.close(); /* Terminate the API environment */ errorCode = UF_terminate(); } }
|
|
來自: 昵稱14205145 > 《待分類1》