|
[code]static void MyGroupMyCommand5 ()
{
ads_name en; ads_point p1; ads_point p2;
if (acedEntSel(_T("\n选择一个对象: "),en,p1) != RTNORM ||
acedGetPoint(NULL,_T("\n第一个出发点: "),p1) != RTNORM ||
acedGetPoint(p1, _T("\n第一个目标点: "),p2) != RTNORM) return;
AcGePoint3d pSrcPt1(p1[X],p1[Y],p1[Z]); AcGePoint3d pDestPt1(p2[X],p2[Y],p2[Z]);
if (acedGetPoint(NULL,_T("\n第二个出发点: "),p1) != RTNORM ||
acedGetPoint(p1, _T("\n第二个目标点: "),p2) != RTNORM) return;
AcGePoint3d pSrcPt2(p1[X],p1[Y],p1[Z]); AcGePoint3d pDestPt2(p2[X],p2[Y],p2[Z]);
AcDbObjectId id;
acdbGetObjectId(id,en);
ALIGN1(id,pSrcPt1,pDestPt1,pSrcPt2,pDestPt2);
}
//图元对齐 (图元 id,第一个出发点 pSrcPt1, 第一个目标点 pDestPt1, 第二个出发点 pSrcPt2, 第二个目标点 pDestPt2)
static void ALIGN1(AcDbObjectId id,AcGePoint3d pSrcPt1, AcGePoint3d pDestPt1, AcGePoint3d pSrcPt2, AcGePoint3d pDestPt2)
{
AcGeVector3d v1(pSrcPt1 - pSrcPt2); AcGeVector3d v2(pDestPt1 - pDestPt2);
AcDbEntityPointer pEnt(id,AcDb::kForWrite);
if (pEnt.openStatus() != Acad::eOk) return;
AcGeMatrix3d mMatScale; AcGeMatrix3d mMatRot; AcGeMatrix3d mMatResul;
mMatRot = v1.rotateTo(v2);
mMatScale.setToScaling(v2.length()/v1.length()); mMatResul = mMatRot * mMatScale;pSrcPt1.transformBy(mMatResul);
mMatResul.setTranslation(pDestPt1 - pSrcPt1);
pEnt->transformBy(mMatResul);
pEnt->close();
}[/code] |
|