nx二次开发关于导入组件的函数

//删除组件
#include <NXOpen/NXException.hxx>
#include <NXOpen/Assemblies_Component.hxx>
#include <NXOpen/Assemblies_ComponentAssembly.hxx>
#include <NXOpen/Preferences_SessionModeling.hxx>
#include <NXOpen/Preferences_SessionPreferences.hxx>

//删除组件
void auto_generation::deleteComponent(tag_t componentTag)
{
Session* theSession = Session::GetSession();
Part* workPart(theSession->Parts()->Work());
Part* displayPart(theSession->Parts()->Display());
Session::UndoMarkId markId1;
markId1 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, “Delete”);
bool notifyOnDelete1;
notifyOnDelete1 = theSession->Preferences()->Modeling()->NotifyOnDelete();
theSession->UpdateManager()->ClearErrorList();
Session::UndoMarkId markId2;
markId2 = theSession->SetUndoMark(Session::MarkVisibilityVisible, “Delete”);
std::vector<NXObject*> objects1(1);
Assemblies::Component* component1(dynamic_castAssemblies::Component*(NXObjectManager::Get(componentTag)));
objects1[0] = component1;
int nErrs1;
nErrs1 = theSession->UpdateManager()->AddToDeleteList(objects1);
bool notifyOnDelete2;
notifyOnDelete2 = theSession->Preferences()->Modeling()->NotifyOnDelete();
int nErrs2;
nErrs2 = theSession->UpdateManager()->DoUpdate(markId2);
theSession->DeleteUndoMark(markId1, NULL);
}

//移除参数
void auto_generation::movePar(vector<tag_t> objTag)
{
Session* theSession = Session::GetSession();
Part* workPart(theSession->Parts()->Work());
Part* displayPart(theSession->Parts()->Display());

Features::RemoveParametersBuilder* removeParametersBuilder1;
removeParametersBuilder1 = workPart->Features()->CreateRemoveParametersBuilder();
vector<NXObject*>objects;
for (int i = 0; i < objTag.size(); i++)
{
	objects.push_back(dynamic_cast<NXObject*>(NXObjectManager::Get(objTag[i])));
}
removeParametersBuilder1->Objects()->Add(objects);

NXObject* nXObject1;
nXObject1 = removeParametersBuilder1->Commit();

removeParametersBuilder1->Destroy();

}

//创建连接体
tag_t auto_generation::linkBody(tag_t body)
{
Session* theSession = Session::GetSession();
Part* workPart(theSession->Parts()->Work());
Part* displayPart(theSession->Parts()->Display());

Features::Feature* nullFeatures_Feature(NULL);

Features::WaveLinkBuilder* waveLinkBuilder1;
waveLinkBuilder1 = workPart->BaseFeatures()->CreateWaveLinkBuilder(nullFeatures_Feature);

Features::WaveDatumBuilder* waveDatumBuilder1;
waveDatumBuilder1 = waveLinkBuilder1->WaveDatumBuilder();

Features::CompositeCurveBuilder* compositeCurveBuilder1;
compositeCurveBuilder1 = waveLinkBuilder1->CompositeCurveBuilder();

Features::WaveSketchBuilder* waveSketchBuilder1;
waveSketchBuilder1 = waveLinkBuilder1->WaveSketchBuilder();

Features::WaveRoutingBuilder* waveRoutingBuilder1;
waveRoutingBuilder1 = waveLinkBuilder1->WaveRoutingBuilder();

Features::WavePointBuilder* wavePointBuilder1;
wavePointBuilder1 = waveLinkBuilder1->WavePointBuilder();

Features::ExtractFaceBuilder* extractFaceBuilder1;
extractFaceBuilder1 = waveLinkBuilder1->ExtractFaceBuilder();

Features::MirrorBodyBuilder* mirrorBodyBuilder1;
mirrorBodyBuilder1 = waveLinkBuilder1->MirrorBodyBuilder();

extractFaceBuilder1->SetFaceOption(Features::ExtractFaceBuilder::FaceOptionTypeFaceChain);

waveLinkBuilder1->SetType(Features::WaveLinkBuilder::TypesBodyLink);

extractFaceBuilder1->SetFaceOption(Features::ExtractFaceBuilder::FaceOptionTypeFaceChain);

extractFaceBuilder1->SetAngleTolerance(45.0);

waveDatumBuilder1->SetDisplayScale(2.0);

extractFaceBuilder1->SetParentPart(Features::ExtractFaceBuilder::ParentPartTypeOtherPart);

mirrorBodyBuilder1->SetParentPartType(Features::MirrorBodyBuilder::ParentPartOtherPart);

extractFaceBuilder1->SetAssociative(true);

extractFaceBuilder1->SetMakePositionIndependent(false);

extractFaceBuilder1->SetFixAtCurrentTimestamp(false);

extractFaceBuilder1->SetHideOriginal(false);

extractFaceBuilder1->SetInheritDisplayProperties(false);

SelectObjectList* selectObjectList1;
selectObjectList1 = extractFaceBuilder1->BodyToExtract();

extractFaceBuilder1->SetCopyThreads(true);

Body* body1(dynamic_cast<Body*>(NXOpen::NXObjectManager::Get(body)));
bool added1;
added1 = selectObjectList1->Add(body1);

Features::Feature* body_feature;
body_feature = waveLinkBuilder1->CommitFeature();

waveLinkBuilder1->Destroy();

tag_t body2 = NULL_TAG;
UF_MODL_ask_feat_body(body_feature->Tag(), &body2);
return body2;

}

//返回组件的全部实体
vector<tag_t> auto_generation::GetInstanceBodies(tag_t compTag)
{
int nn = 0;
vector<tag_t> bodies;
tag_t tempOcc;
if (compTag != NULL_TAG)
{
int type = 0, subType = 0;
UF_OBJ_ask_type_and_subtype(compTag, &type, &subType);
tag_t* instanceToOcc;
if (type == 68)
{
int nnn = UF_ASSEM_ask_part_occs_of_inst(compTag, &instanceToOcc);
if (nnn)
{
tempOcc = instanceToOcc[0];
}
else
{
//ccc::cecho::echo(“没找到”, nnn, NumLine);
}
}
else if (type == 63)//occ
{
tempOcc = compTag;
}
tag_t member = NULL_TAG;
UF_ASSEM_cycle_objs_in_comp(tempOcc, &member);
while (member != NULL_TAG)
{
int type = 0, subType = 0;
UF_OBJ_ask_type_and_subtype(member, &type, &subType);
if (type == 70 && subType == UF_solid_body_subtype)
{
nn++;
bodies.push_back(member);
}
else if (type == 63)
{
vector<tag_t> temp;
temp = GetInstanceBodies(member);
for (int i = 0; i < temp.size(); i++)
{
bodies.push_back(temp[i]);
}
}
UF_ASSEM_cycle_objs_in_comp(tempOcc, &member);
}
if ((int)bodies.size() == 0)
{
//ccc::cecho::echo(“数量为”, (int)bodies.size(), NumLine);
}
}
else
{
uc1601(“参数为空”, 1);
}
return bodies;
}

//编辑组件表达式
void auto_generation::editComponentExp(string ComponentPath, vector vecExp)
{
string name = ComponentPath.substr(ComponentPath.find_last_of(“\”) + 1, ComponentPath.find_last_of(“.”) - ComponentPath.find_last_of(“\”) - 1);
tag_t partTag = UF_PART_ask_part_tag(name.c_str());
tag_t previous_work_part = NULL_TAG;
UF_ASSEM_set_work_part_quietly(partTag, &previous_work_part);
for (int i = 0; i < vecExp.size(); i++)
{
char cExp[256];
strcpy(cExp, vecExp[i].c_str());
UF_MODL_edit_exp(cExp);
}
UF_MODL_update();
UF_ASSEM_set_work_part(previous_work_part);
}

//添加组件
tag_t auto_generation::addComponent(Point3d point, string filePath, char* name)
{
Session* theSession = Session::GetSession();
Part* workPart(theSession->Parts()->Work());
Part* displayPart(theSession->Parts()->Display());
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;
Assemblies::Component* component1;
component1 = workPart->ComponentAssembly()->AddComponent(filePath.c_str(), “MODL”, name, point, orientation1, 0, &partLoadStatus1, true);
return component1->Tag();
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nx二次开发中,出口函数是一个非常重要的概念。在nx二次开发中,每个功能模块都会有一个出口函数,用于控制模块的入口和出口。 出口函数的主要作用是将模块的核心功能与nx系统的其他模块进行连接,实现模块之间的数据交互和功能扩展。通过定义出口函数,我们可以将模块的数据输出、功能封装和业务逻辑的实现进行统一管理和调用。 在定义出口函数时,需要考虑以下几个方面: 1. 函数参数:根据模块的具体需求,设计合适的函数参数。参数可以是模块的输入数据、输出数据或者其他模块间的通信参数。 2. 返回值:出口函数可以返回模块处理后的结果,供其他模块使用。返回值可以是简单的数据类型,也可以是复杂的对象。 3. 函数命名:出口函数的命名应该具有代表性,方便其他开发人员理解模块的作用和功能。 4. 注释和文档:在定义出口函数时,要添加详细的注释和文档,方便其他开发人员理解函数的用途和使用方法。 在使用出口函数时,需要注意以下几点: 1. 函数调用:通过调用出口函数,可以实现模块的初始化、启动、停止和其他功能。在调用出口函数时,需要传入正确的参数,并对返回值进行处理。 2. 函数扩展:通过在出口函数中添加逻辑代码,可以扩展模块的功能。出口函数可以调用其他函数,实现更复杂的功能。 3. 错误处理:出口函数应该考虑各种异常情况,并进行合适的错误处理。错误处理可以返回错误码或抛出异常,通知调用方出现了异常情况。 总之,出口函数nx二次开发中扮演着重要的角色,能够连接各个功能模块,实现数据交互和功能扩展。合理设计和使用出口函数,可以提高开发效率,降低代码复杂度,实现系统的高效运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值