#include "aced.h"
#include "dbents.h"
#include "dbapserv.h"
#include "acdocman.h"
#include "geassign.h"
#include "gemat3d.h"
#include "adslib.h"
#include "tchar.h"
// --- Helper: Build WCS → DCS view matrix ---
AcGeMatrix3d getCurrentViewTransform()
{
struct resbuf rbViewDir, rbTarget;
acedGetVar(_T("VIEWDIR"), &rbViewDir);
acedGetVar(_T("TARGET"), &rbTarget);
AcGeVector3d viewDir(
rbViewDir.resval.rpoint[X],
rbViewDir.resval.rpoint[Y],
rbViewDir.resval.rpoint[Z]);
AcGePoint3d target(
rbTarget.resval.rpoint[X],
rbTarget.resval.rpoint[Y],
rbTarget.resval.rpoint[Z]);
viewDir.normalize();
// Define up vector (Z-up by default)
AcGeVector3d up(0, 0, 1);
if (viewDir.isParallelTo(up))
up = AcGeVector3d(0, 1, 0);
AcGeVector3d xAxis = up.crossProduct(viewDir).normal();
AcGeVector3d yAxis = viewDir.crossProduct(xAxis).normal();
AcGeMatrix3d viewXform;
viewXform.setToIdentity();
viewXform.setCoordSystem(target, xAxis, yAxis, viewDir);
return viewXform;
}
// --- Main Command ---
void cmdGetCylinder()
{
acutPrintf(_T("\n🔍 Running GETCYLINDER command..."));
// 1️⃣ Ask user to select a Point Cloud
ads_name ename;
ads_point pickPt;
if (acedEntSel(_T("\nSelect Point Cloud: "), ename, pickPt) != RTNORM)
{
acutPrintf(_T("\n⚠️ Selection cancelled."));
return;
}
AcDbObjectId objId;
if (acdbGetObjectId(objId, ename) != Acad::eOk)
{
acutPrintf(_T("\n❌ Failed to get object ID."));
return;
}
AcDbPointCloudEx* pCloud = nullptr;
if (acdbOpenObject(pCloud, objId, AcDb::kForRead) != Acad::eOk || !pCloud)
{
acutPrintf(_T("\n❌ Could not open Point Cloud entity."));
return;
}
// 2️⃣ Get view transform (WCS → DCS)
AcGeMatrix3d viewXform = getCurrentViewTransform();
// 3️⃣ Ask user to click a point on screen
ads_point userPick;
if (acedGetPoint(nullptr, _T("\nPick a point on the cloud: "), userPick) != RTNORM)
{
acutPrintf(_T("\n⚠️ Pick cancelled."));
pCloud->close();
return;
}
AcGePoint3d pickPt3d(userPick[X], userPick[Y], userPick[Z]);
// 4️⃣ Detect Cylinder
AcGePoint3d origin;
AcGeVector3d axis;
double height = 0.0, radius = 0.0;
Acad::ErrorStatus es = pCloud->getCylinderAt(viewXform, pickPt3d, origin, axis, height, radius);
if (es == Acad::eOk)
{
acutPrintf(_T("\n✅ Cylinder Detected!"));
acutPrintf(_T("\nOrigin: (%.3f, %.3f, %.3f)"), origin.x, origin.y, origin.z);
acutPrintf(_T("\nAxis: (%.3f, %.3f, %.3f)"), axis.x, axis.y, axis.z);
acutPrintf(_T("\nHeight: %.3f"), height);
acutPrintf(_T("\nRadius: %.3f"), radius);
}
else
{
acutPrintf(_T("\n⚠️ No cylinder found or API returned error (%d)."), es);
}
pCloud->close();
}
// --- Register Command ---
void initApp()
{
acedRegCmds->addCommand(_T("POINTCLOUD_CMDS"),
_T("GETCYLINDER"),
_T("GETCYLINDER"),
ACRX_CMD_MODAL,
cmdGetCylinder);
}
void unloadApp()
{
acedRegCmds->removeGroup(_T("POINTCLOUD_CMDS"));
}
extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
switch (msg)
{
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(pkt);
acrxRegisterAppMDIAware(pkt);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
break;
}
return AcRx::kRetOK;
}
--------------------------------------------------------------------------------------------------------------------------
when i click on RCP points pipe (not real pipe it is point cloud pipe ) output from getCylinderAt ePointNotOnEntity.