admin 发表于 2014-11-4 20:54:40

NX二次开发源码分享:查找体中最大的面积


NX二次开发源码分享:查找体中最大的面积
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询


#include <NXOpen/Session.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/MeasureManager.hxx>
#include <NXOpen/MeasureFaces.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <NXOpen/Body.hxx>
#include <NXOpen/Face.hxx>
#include <NXOpen/Unit.hxx>
#include <NXOpen/UnitCollection.hxx>
using namespace NXOpen;

static tag_t ask_largest_face_interop(tag_t body_tag)
{
    Session *theSession = Session::GetSession();

    Part *workPart(theSession->Parts()->Work());

    Unit *area_units = workPart->UnitCollection()->GetBase("Area");
    Unit *length_units = workPart->UnitCollection()->GetBase("Length");

    Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
    std::vector<Face *> theFaces = theBody->GetFaces();

    double bigArea = 0;
    Face *bigFace;
    std::vector<IParameterizedSurface *> theFace(1);
    for (int ii = 0; ii < theFaces.size(); ii++)
    {
      theFace = dynamic_cast<IParameterizedSurface *>(theFaces);

      MeasureFaces *theMeasure = workPart->MeasureManager()->
            NewFaceProperties(area_units, length_units, 0.999, theFace);

      if (theMeasure->Area() > bigArea)
      {
            bigArea = theMeasure->Area();
            bigFace = theFaces;
      }
    }

    return bigFace->Tag();
}



593232280 发表于 2019-4-25 18:43:12

谢谢分享啊
页: [1]
查看完整版本: NX二次开发源码分享:查找体中最大的面积