Heeds与Siemens NX:参数化模型获取方法

以下是使用C++编写的代码示例,用于在Siemens NX中获取参数化模型prt格式,并传递给Heeds优化设计:

```c++

#include <iostream>

#include <NXOpen/NXSession.hxx>

#include <NXOpen/Part.hxx>

#include <NXOpen/PartCollection.hxx>

#include <NXOpen/FC_Op.hxx>

#include <NXOpen/FC_OpManager.hxx>

#include <NXOpen/FC_Parameter.hxx>

#include <NXOpen/FC_ParamName.hxx>

#include <NXOpen/FC_NxGeometry.hxx>

#include <NXOpen/FC_NxGeometryManager.hxx>

#include <string>

using namespace std;

//定义Heeds的目录和命令

string runCmd = "run heeds.exe prmfile.prm";

string heedsDir = "C:/heeds/";

// 定义获取文件名的函数

string getFileName(string filePath) {

    int startIndex = filePath.find_last_of("\\") + 1;

    int endIndex = filePath.find_last_of(".");

    return filePath.substr(startIndex, endIndex - startIndex);

}

int main(int argc, char* argv[])

{

    NXOpen::NXSession* session = NXOpen::NXSession::GetSession();

    session->SetUndoMarkName("Get Parametric Model");

    NXOpen::PartCollection* partCollection = session->Parts();

    NXOpen::Part* part = partCollection->Work();

    // 将prt文件保存到当前目录

    string filePath = part->FullPath();

    part->SaveAs(filePath);

    // 加载FC_OpManager和FC_NxGeometryManager

    NXOpen::FC_NxGeometryManager* geomManager = NULL;

    geomManager = FC_NxGeometryManager::GetGeometryManager(*part);

    NXOpen::FC_OpManager* opManager = NULL;

    opManager = FC_OpManager::GetOpManager(*part);

    // 创建一个新操作

    NXOpen::FC_Op* op = opManager->CreateOp(NXOpen::FC_OpType::OP_NULL);

    op->SetOpName("Get Parameters");

    // 添加参数名称

    NXOpen::FC_Parameter* parameter = op->AddParameter(NXOpen::FC_ParamName::PN_STRING);

    parameter->SetName("filePath");

    parameter->SetValue(filePath);

    // 添加NX geometry到操作

    op->AttribManager()->SetAttrib("NX_GEOMETRY", NXOpen::FC_NxGeometryHandler::GetGeometryHandler(*geomManager, part));

    // 执行操作

    string report;

    op->Execute(report);

    NXOpen::FC_OpResult* opResult = op->OpResult();

    // 获取参数化模型

    string prmFilePath = heedsDir + getFileName(filePath) + ".prt";

    NXOpen::FC_NxGeometry* nxGeom = dynamic_cast<NXOpen::FC_NxGeometry*>(opResult->GetOutput("OrgGeometry"));

    nxGeom->Save(prmFilePath);

    // 运行Heeds

    system(runCmd.c_str());

    delete opManager;

    delete geomManager;

    delete op;

    delete opResult;

    delete part;

    return 0;

}

```

在此代码示例中,我们首先获取当前工作中的Part,并将其保存为prt文件。

然后,我们使用FC_OpManager和FC_NxGeometryManager从Part中加载NX geometry并创建一个新操作。

该操作需要一个文件路径参数,因此我们添加了一个字符串参数。

我们将其他必要的geometry添加到操作中,并执行操作来获得参数化模型。最后,我们将参数化模型prt文件传递给Heeds进行优化设计。

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空