8

如何使用 NX Open 获取 Siemens NX 中所有开放部件的列表?

我尝试过使用Session.Parts,但我在使用它时遇到了问题,我觉得它很简单。我试过了

for (auto part in session->Parts())
{
    // ...
}

但编译器不喜欢它。

4

1 回答 1

21

C++

NXOpen::Session::Parts()返回一个NXOpen::PartCollection,与所有 NX Open 集合一样,可以对其进行迭代,并且可以取消对迭代器的引用以访问实际Part对象:

#include <NXOpen/Session.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/BasePart.hxx>

NXOpen::Session *session = NXOpen::Session::GetSession();
for (auto it = session->Parts()->begin(); it != session->Parts()->end(); it++)
{
    NXOpen::Part *part = *it;
    std::string name = part->Name().GetText();
    std::string fullPath = part->FullPath().GetText();
    // Do something with name or fullPath...
}

C#

简单地循环NXOpen.Session.Parts就可以了:

using NXOpen.Session;
using NXOpen.Part;

Session session = Session.GetSession();
foreach (Part part in session.Parts)
{
    string name = part.Name;
    string fullPath = part.FullPath;
    // Do something with name or fullPath...
}

爪哇

import nxopen.Session;
import nxopen.Part;
import java.util.Iterator;

Session session = (Session)SessionFactory.get("Session");
for (Iterator it = session.parts().iterator(); it.hasNext();) {
    Part part = (Part)it.next();
    String name = part.name();
    String fullPath = part.fullPath();
    // Do something with name or fullPath...
}
于 2021-10-27T14:45:48.897 回答