NXopen 批量输出装配体零件几何模型的STEP和IGS格式文件

博客介绍了通过对话框指定文件夹,然后将该文件夹下的PARt文件输出为STEP和IGS格式文件的内容,与信息技术相关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通过对话框指定文件夹,输出该文件夹下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
            {

            }
  }

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值