如何使用 NX Open 获取 NX 中所有打开零件的列表?

How do I get a list of all open parts in NX using NX Open?

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

我试过使用 Session.Parts,但我在使用时遇到了问题,而且我感觉它非常简单。我试过了

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

但是编译器不喜欢它。

C++

NXOpen::Session::Parts() returns 一个 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...
}

Java

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...
}