通过对话框指定文件夹,输出该文件夹下PARt文件为STEP和IGS格式文件
//头文件
#include <uf_modl_primitives.h>
#include <NXOpen/Session.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <uf_ui.h>
#include <NXOpen/Assemblies_ComponentAssembly.hxx>
#include <io.h>
#include <fstream>
#include <string>
#include <string>
#include <vector>
#include <iostream>
#include <stdio.h>
//主程序
NXOpen::Session* theSession = NXOpen::Session::GetSession();
NXOpen::Part* workPart(theSession->Parts()->Work());
NXOpen::Part* displayPart(theSession->Parts()->Display());
NXOpen::NXString NXpathi = nativeFolderBrowser0->Path();
const char* pathi = NXpathi.GetLocaleText();
const char* szTemp1 = pathi;
const char* szTemp2 = "*.prt";
const char* path = NULL;
string temp = string(szTemp1) + string(szTemp2);
path = temp.c_str();//result即为合并后的结果
_finddata64i32_t fileInfo;
intptr_t hFile = _findfirst(path, &fileInfo);
vector<string> files;
if (hFile == -1) {
files.clear();
return -1;
}
do
{
files.push_back(fileInfo.name);
} while (_findnext(hFile, &fileInfo) == 0);
vector<string> partfiles;
for (int i = 0; i < files.size(); i++)
{
string PartName = (string)files[i];
PartName = szTemp1 + PartName;
partfiles.push_back(PartName);
}
NXOpen::NXString Spath = nativeFolderBrowser01->Path();
const char* Spathchar = Spath.GetLocaleText();
theSession->ListingWindow()->WriteLine(Spathchar);
for (int i = 0; i < partfiles.size(); i++)
{
NXOpen::BasePart* basePart1;
NXOpen::PartLoadStatus* partLoadStatus1;
basePart1 = theSession->Parts()->OpenActiveDisplay(partfiles[i], NXOpen::DisplayPartOptionAllowAdditional, &partLoadStatus1);
NXOpen::Part* part2 = theSession->Parts()->Work();
delete partLoadStatus1;
theSession->ApplicationSwitchImmediate("UG_APP_MODELING");
Assemblies::ComponentAssembly* compAssy = part2->ComponentAssembly();
Assemblies::Component* rootcomponent = compAssy->RootComponent();
if (rootcomponent == NULL)
{
NXOpen::NXString NXString2 = part2->JournalIdentifier();
const char* Spathi = NXString2.GetLocaleText();
if (toggle0->Value() == 1)
{
const char* pathstep = ".stp";
const char* path22 = NULL;
string temp11 = string(Spathchar) + string(Spathi) + string(pathstep);
path22 = temp11.c_str();//result即为合并后的结果
theSession->ListingWindow()->WriteLine(path22);
NXOpen::PartSaveStatus* partSaveStatus1;
partSaveStatus1 = part2->SaveAs(NXOpen::NXString(path22, NXOpen::NXString::UTF8));
delete partSaveStatus1;
}
if (toggle01->Value() == 1)
{
const char* pathigs = ".igs";
const char* path44 = NULL;
string temp44 = string(Spathchar) + string(Spathi) + string(pathigs);
path44 = temp44.c_str();
theSession->ListingWindow()->WriteLine(path44);
NXOpen::PartSaveStatus* partSaveStatus2;
partSaveStatus2 = part2->SaveAs(path44);
delete partSaveStatus2;
}
}
else
{
}
}