admin 发表于 2016-12-8 21:40:00

NX二次开发源码分享:获取体的重量信息

NX二次开发源码分享:获取体的重量信息
写了个函数,直接用,很简单!

static double ask_bodies_weight_interop(int n, tag_t *bodies)
{
    Session *theSession = Session::GetSession();
    Part *workPart(theSession->Parts()->Work());
    std::vector<IBody *> theBodies(n);
    for (int ii = 0; ii < n; ii++)
      theBodies = dynamic_cast<IBody *>(NXObjectManager::Get(bodies));
    std::vector<Unit *> theUnits(5);
    theUnits = workPart->UnitCollection()->GetBase("Area");
    theUnits = workPart->UnitCollection()->GetBase("Volume");
    theUnits = workPart->UnitCollection()->GetBase("Mass");
    theUnits = workPart->UnitCollection()->GetBase("Length");
    theUnits = workPart->UnitCollection()->GetBase("Mass");
    MeasureBodies *mb =
      workPart->MeasureManager()->NewMassProperties(theUnits, 0.99, theBodies);
    double theWeight = mb->Weight();
    delete mb;// MeasureBodies inherits from TransientObject so delete it
    return theWeight;
}

zs8237 发表于 2016-12-9 10:01:01

老师辛苦了
页: [1]
查看完整版本: NX二次开发源码分享:获取体的重量信息