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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值