How to calculate the length of an entity in ObjectArx/.NET

By Gopinath Taget

You can use the getStartParam() and getEndParam() to obtain the start and end parameters of the Curve based entity and then use GetDistanceAtParameter() method to get the length of the Spline. Please find the code below which will calculate the Length of the Spline.

Acad::ErrorStatus es;
ads_name ename;
ads_point pt;
 
if (RTNORM != acedEntSel(NULL, ename, pt))
{
    return;
}
AcDbObjectId objid;
acdbGetObjectId(objid, ename);
AcDbCurve* pEnt;
acdbOpenObject(pEnt, objid, AcDb::kForRead);
 
double startParam, endParam, startDist, endDist;
es = pEnt->getStartParam(startParam);
es = pEnt->getEndParam(endParam);
es = pEnt->getDistAtParam(startParam, startDist);
es = pEnt->getDistAtParam(endParam, endDist);
acutPrintf(L"nLength = %f", endDist - startDist);

Also in .Net, you can use the something like this to get the entity length.

a = curve.StartParam
b = curve.EndParam
length = curve.GetDistanceAtParameter(b) - 
    curve.GetDistanceAtParameter(a)

Comments

5 responses to “How to calculate the length of an entity in ObjectArx/.NET”

  1. petcon Avatar
    petcon

    there is a huge mistake in the arx code
    everytime use acdbOpenObject PLEASE CHECK the return VALUE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  2. Hi Petcon,
    I am guessing acdbOpenObject caused you some heart burn. I sympathise. Programming is hard.
    The point of the code above was to convey how to determine the length of a curve based entity and in that context the mistake you point to does not seem all that huge.
    Bullet proof code makes for some very unreadable prose and this leads to some reluctant compromises in favor of simplicity and readability.
    But I can always strive better.
    Cheers
    Gopinath

  3. petcon Avatar
    petcon

    fine. for readable.

  4. Gig like

  5. Big Like

Leave a Reply to petconCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading