1. 程式人生 > >NX二次開發-遍歷函式UF_OBJ_cycle_objs_in_part與UF_OBJ_cycle_all

NX二次開發-遍歷函式UF_OBJ_cycle_objs_in_part與UF_OBJ_cycle_all

NX11+VS2013

#include <uf.h>
#include <uf_obj.h>
#include <uf_modl.h>
#include <uf_part.h>
#include <NXOpen/ListingWindow.hxx>

UF_initialize();

//方法1:UF_OBJ_cycle_objs_in_part
std::vector<tag_t> SolidVector;
tag_t ObjectTag = NULL_TAG;
int Type, SubType, Body_Type;
char msg[256];
UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &ObjectTag);
while (ObjectTag != NULL_TAG)
{
	UF_OBJ_ask_type_and_subtype(ObjectTag, &Type, &SubType);
	if (SubType == UF_solid_body_subtype)
	{
		UF_MODL_ask_body_type(ObjectTag, &Body_Type);
		if (Body_Type == UF_MODL_SOLID_BODY)
		{
			UF_OBJ_set_color(ObjectTag, 186);
			SolidVector.push_back(ObjectTag);
		}
	}
	UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &ObjectTag);
}

sprintf_s(msg, "當前有%d個實體", SolidVector.size());
lw->Open();
lw->WriteLine(msg);

/*
	//方法2:UF_OBJ_cycle_all
	std::vector<tag_t> SolidVector1;
	tag_t WorkPartTag = UF_PART_ask_display_part();
	tag_t Next_Tag = NULL_TAG;
	int Type1, SubType1, Body_Type1;
	char msg1[256];
	do 
	{
		Next_Tag = UF_OBJ_cycle_all(WorkPartTag, Next_Tag);
		if (Next_Tag != NULL_TAG)
		{
			UF_OBJ_ask_type_and_subtype(Next_Tag, &Type1,&SubType1);
			if (Type1 == UF_solid_type && SubType1 == UF_solid_body_subtype)
			{
				UF_MODL_ask_body_type(Next_Tag, &Body_Type1);
				if (Body_Type1 == UF_MODL_SOLID_BODY)
				{
					UF_OBJ_set_color(Next_Tag, 200);
					SolidVector1.push_back(Next_Tag);
				}
			}
		}
	} while (Next_Tag != NULL_TAG);

sprintf_s(msg1, "當前有%d個實體", SolidVector1.size());
lw->Open();
lw->WriteLine(msg1);
*/
UF_terminate();

Caesar盧尚宇  
[email protected]

在這裡插入圖片描述