其他分享
首页 > 其他分享> > NXOpen替换组件

NXOpen替换组件

作者:互联网

#include <uf_defs.h>
#include <uf_ui_types.h>
#include <iostream>
#include <NXOpen/Session.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/Callback.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/BlockStyler_UIBlock.hxx>
#include <NXOpen/BlockStyler_BlockDialog.hxx>
#include <NXOpen/BlockStyler_PropertyList.hxx>
#include <uf_defs.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_ui_types.h>
#include <iostream>
#include <uf_assem.h>
#include <UF_MODL.h>
#include <uf_part.h>
#include <UF_OBJ.h>
#include <NXOpen/Session.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/Callback.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/BlockStyler_UIBlock.hxx>
#include <NXOpen/BlockStyler_BlockDialog.hxx>
#include <NXOpen/BlockStyler_PropertyList.hxx>
#include <NXOpen/Assemblies_Component.hxx>
#include <NXOpen/Assemblies_ComponentAssembly.hxx>
#include <NXOpen/Face.hxx>
#include <NXOpen/Line.hxx>
#include <NXOpen/LineCollection.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Positioning_ComponentConstraint.hxx>
#include <NXOpen/Positioning_ComponentNetwork.hxx>
#include <NXOpen/Positioning_ComponentPositioner.hxx>
#include <NXOpen/Positioning_Constraint.hxx>
#include <NXOpen/Positioning_ConstraintReference.hxx>
#include <NXOpen/Positioning_Network.hxx>
#include <NXOpen/Positioning_Positioner.hxx>
#include <NXOpen/Preferences_SessionAssemblies.hxx>
#include <NXOpen/Preferences_SessionPreferences.hxx>
#include <NXOpen/Sketch.hxx>
#include <NXOpen/SketchCollection.hxx>
#include <NXOpen/Update.hxx>
#include <NXOpen/Assemblies_Component.hxx>
#include <NXOpen/Assemblies_ComponentAssembly.hxx>
#include <NXOpen/Body.hxx>
#include <NXOpen/BodyCollection.hxx>
#include <NXOpen/Face.hxx>
#include <NXOpen/Line.hxx>
#include <NXOpen/Session.hxx> //有关Session绘画头文件
#include <NXOpen/Part.hxx> //有关部件头文件
#include <NXOpen/PartCollection.hxx> //有关部件头文件
#include <NXOpen/Features_Feature.hxx> //有关特征头文件
#include <NXOpen/Features_CylinderBuilder.hxx> //有关特征头文件
#include <NXOpen/Features_FeatureCollection.hxx>//有关特征头文件
#include <NXOpen/Features_FeatureBuilder.hxx> //有关特征头文件
#include <NXOpen/Features_AssociativeLine.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <NXOpen/Assemblies_ReplaceComponentBuilder.hxx>
#include <NXOpen/Assemblies_AssemblyManager.hxx>
#include <NXOpen/SelectDisplayableObjectList.hxx>

try

{
//---- Enter your callback code here -----
UF_initialize();
char msg[111];

Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());

char* repl_partInsName = "ZGFL" ;
tag_t root_part_occ;
tag_t part_occ_tag;
tag_t InTag;

root_part_occ = UF_ASSEM_ask_root_part_occ(displayPart->Tag());
InTag = UF_ASSEM_ask_instance_of_name(displayPart->Tag(),repl_partInsName); //Return the Tag of named instance
part_occ_tag = UF_ASSEM_ask_part_occ_of_inst (root_part_occ,InTag);//得到Part_occ_tag
//tag_t parTag = UF_ASSEM_ask_prototype_of_occ(part_occ_tag);//获得par_occ的par_tag 后面组件tag转换不需要这一步,后面需要的是:part_occ_tag
/*theSession->ListingWindow()->Open();
sprintf(msg,"InTag:%d",part_occ_tag);
theSession->ListingWindow()->WriteLine(msg);
*/

Assemblies::ReplaceComponentBuilder *replaceComponentBuilder1;
replaceComponentBuilder1 = workPart->AssemblyManager()->CreateReplaceComponentBuilder();

replaceComponentBuilder1->SetComponentNameType(Assemblies::ReplaceComponentBuilder::ComponentNameOptionAsSpecified);

//replaceComponentBuilder1->SetComponentName("ZGFL");
//replaceComponentBuilder1->SetComponentName("");

//Assemblies::Component *component1(dynamic_cast<Assemblies::Component *>(workPart->ComponentAssembly()->RootComponent()->FindObject("COMPONENT GF530-10-001 1")));
Assemblies::Component *component1 = dynamic_cast<Assemblies::Component *>(NXObjectManager::Get(part_occ_tag));
bool added1;
added1 = replaceComponentBuilder1->ComponentsToReplace()->Add(component1);

replaceComponentBuilder1->SetComponentName("ZGFL");

replaceComponentBuilder1->SetReplacementPart("E:\\bgl\\0lib\\33\\GF377-10-001.prt");

replaceComponentBuilder1->SetComponentReferenceSetType(Assemblies::ReplaceComponentBuilder::ComponentReferenceSetMaintain, NULL);

PartLoadStatus *partLoadStatus1;
partLoadStatus1 = replaceComponentBuilder1->RegisterReplacePartLoadStatus();

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

delete partLoadStatus1;

replaceComponentBuilder1->Destroy();

UF_terminate();
}

标签:头文件,occ,tag,NXOpen,replaceComponentBuilder1,组件,part,include,替换
来源: https://www.cnblogs.com/glz7519/p/15375908.html