ARX 选择集获得所有图形 遍历 实例 备忘

////给图形实体,返回与当前图形中,直线实体相交的交点数组、直线方向向量
////参数:曲线实体,2dpoint数组,三维向量
static void GetLineNum(AcDbCurve* pLine,AcGePoint3dArray& ptArr,AcGeVector3d& v)
{
////遍历所有实体
ads_name ssName;////选择集名称
acedSSGet(_T("X"),NULL,NULL,NULL,ssName);
long len = 0;
acedSSLength(ssName,&len);


ads_name entName;
AcDbObjectId id;
AcDbEntity* pEnt = NULL;
AcDbCurve* pCur = NULL;
AcGePoint3dArray ptSecArr;////交点集合


for (int i=0;i<len;i++)
{
if (acedSSName(ssName, i, entName) == RTNORM)
{


////根据名称得到ID
acdbGetObjectId(id,entName);


////以读模式打开,根据ID索引到对象,并打开ENTITY
acdbOpenObject(pEnt,id,AcDb::OpenMode::kForRead);
if (pEnt->isKindOf(AcDbCurve::desc()))
{
pCur = (AcDbCurve*)pEnt;
pCur->intersectWith(pLine,AcDb::Intersect::kOnBothOperands,ptSecArr);
if (ptSecArr.length() > 0)
{
////拿出第一个交点(两直线相交只可能有这一个交点)
AcGePoint3d pt3d (ptSecArr.at(0));
////添加交点
ptArr.append(pt3d);
ptSecArr.removeAll();
pCur->getFirstDeriv(pt3d,v);
//acutPrintf(_T(" 道路方向向量:[x]: %.2f,[y] : %.2f, [z] : %.2f"),v[X],v[Y],v[Z]);
}
pCur->close();
}
}
}
}
 

原文地址:https://www.cnblogs.com/mjgw/p/12509787.html