NX/UG二次开发常用方法

1. 获取图层编号

Layer::Category *category1(dynamic_cast(workPart->LayerCategories()->FindObject("XX")));
numbers=category1->GetMemberLayers();
layer_num_inletbushing=numbers[0];

2. 获取图层内所有对象

std::vectorobjects1=workPart->Layers()->GetAllObjectsOnLayer(layer_num_inletbushing);

3. 移动对象到某一图层

std::vector objectArray1(1);
objectArray1[0]=body1;
workPart->Layers()->MoveDisplayableObjects(40, objectArray1);

4. 隐藏图层

std::vector stateArray1(1);
stateArray1[0] = Layer::StateInfo(42, Layer::StateHidden);
workPart->Layers()->ChangeStates(stateArray1, false);

5. 隐藏实体

theSession->DisplayManager()->BlankObjects(nxobject1);    
workPart->ModelingViews()->WorkView()->FitAfterShowOrHide(View::ShowOrHideTypeHideOnly);

6. 获得环境变量

UF_translate_variable("ugbhrt",&charBHRT);
NXString str1(charBHRT,NXString::Locale);

7. 当前文档路径

Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
tag_t part_tag = workPart->GetTag();	
char *filepath=" ";
UF_PART_ask_part_name(part_tag,filepath);

8. 获得特征类型

NXString string1= pp->FeatureType();

9. 根据实体名称找到实体

NXOpen::BodyCollection::iterator it;
NXOpen::BodyCollection *body_collection=workPart->Bodies();
for(it=body_collection->begin();it!=body_collection->end();it++)
{
	std::vector objects(1);
	Body *body(dynamic_cast(*it));
	objects[0]=body;
	string strname=objects[0]->Name().GetLocaleText();
	if(strname=="MANIFOLD")       {i_m++;g_manifold     =objects[0]->JournalIdentifier();}
	if(strname=="SUB_SCREW")      {i_t++;g_subscrew     =objects[0]->JournalIdentifier();}
}

10. 判断曲线类型

UF_EVAL_p_t eval;
UF_EVAL_initialize(object->GetTag(),&eval);
logical is_curve;
UF_EVAL_is_arc(eval,&is_curve);
UF_EVAL_free(eval);

11. 获得组名

tag_t arc_tag = cylinder_2d_object->GetTag();
tag_p_t grp_p_tag;
int count;
int i=UF_GROUP_ask_all_owning_groups(arc_tag,&count,&grp_p_tag);
tag_t grp_tag=*grp_p_tag;
TaggedObject *grp_tag_object=NXObjectManager::Get(grp_tag);
NXObject *grp_object=dynamic_cast(grp_tag_object);
NXString str_name=grp_object->Name();
const char *char_name=str_name.GetLocaleText();//
NXString strname(char_name);

12. 用uf倒角

Manifold::CreateChamfer

转载于:https://my.oschina.net/a8376282/blog/802035

你可能感兴趣的:(NX/UG二次开发常用方法)