It is also not that bad to make the ObjectARX code bulletproof, not that hard either.
Here is the code for both the help method and the command callback.
Acad::ErrorStatus GetLength(AcDbObjectId id, double& length)
{
Acad::ErrorStatus es;
AcDbCurve* pEnt;
es = acdbOpenObject(pEnt, id, AcDb::kForRead);
if( es == Acad::eOk && pEnt)
{
double startParam, endParam, startDist, endDist;
es = pEnt->getStartParam(startParam);
if( es!=Acad::eOk ) { pEnt->close(); return es; }
es = pEnt->getEndParam(endParam);
if( es!=Acad::eOk ) { pEnt->close(); return es; }
es = pEnt->getDistAtParam(startParam, startDist);
if( es!=Acad::eOk ) { pEnt->close(); return es; }
es = pEnt->getDistAtParam(endParam, endDist);
if( es!=Acad::eOk ) { pEnt->close(); return es; }
es = pEnt->close();
length = endDist - startDist;
}
return es;
}
void TestGetLength()
{
ads_name ename;
ads_point pt;
if (RTNORM != acedEntSel(_T("\nSelect an entity:"), ename, pt))
return;
AcDbObjectId id;
if(acdbGetObjectId(id, ename) == Acad::eOk)
{
double length = -1;
if( GetLength(id, length) == Acad::eOk )
acutPrintf(_T("\nEntity length: %f"), length);
else
acutPrintf(_T("\nError in getting the length."));
}
}
Does it give people of the feeling that “Bullet proof code makes for some very unreadable prose and this leads to some reluctant compromises in favor of simplicity and readability.”?
Maybe for a few, but not for most, I believe.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides various project wizards, item wizards, coders and widgets to help program AutoCAD .NET addins.
Posted by: |