Intersecting a block reference with your entity is tricky. Every time you try to get the intersection points, it will return the intersection of your entity with the bounding box of the block reference. e.g. pLine.->intersectWith( pBlock…) and pBlock->intersectWith( pLine…), just return the intersection of the line entity with the block reference bounding box.
How do you find the real intersection points of an entity with the entities in the block reference?
There are two ways to do this:
1) The first method involves opening the AcDbBlockReference, finding its AcDbBlockTableRecord and then iterating through the entities within the block definition, calling AcDbEntity::intersectWith() on each. This method is fine, except that the code is quite tricky to write. Also you will be checking the entities in the actual block definition so the positions of the entities would then have to be temporarily transformed by the AcDbBlockReference’s transformation matrix for the intersectWith to work correctly.
2) The second way, which is far simpler, is to explode the AcDbBlockReference using the explode() method. This returns an array of entities that would be the exploded version of the AcDbBlockReference. They are even correctly transformed by the blockTransform matrix. All we have to do is iterate through these entities, call intersectWith(), get the results and then delete them.
Here is the relevant code:
//********************************************************* // get the intersection point of 2 entities and return the // result in interSectionPoint // static int GetIntersectionPointsOf ( // ads_name ename1, ads_name ename2, // AcGePoint3dArray &intersectionPoints); // get the intersection point of 2 AcDbEntity's and return // the result in interSectionPoint // static int GetIntersectionPointsOf ( // AcDbEntity *pEnt1, AcDbEntity *pEnt2, // AcGePoint3dArray &intersectionPoints); // get intersection points from a block //static int GetIntersectionPointsFromBlockEntities ( // AcDbEntity *pEnt1, // AcDbEntity *pEnt2, // AcGePoint3dArray &intersectionPoints); // draws a little cross at the pnt specified // static void blip (AcGePoint3d pnt, int colour=4); //**********************************************************
// This is command 'TEST' void asdktest() { ads_name ename1; ads_point pnt; // pick first entity to check int res = acedEntSel ( L"nPick first entity : ", ename1, pnt); // if the user wants to carry on if (res == RTNORM) { // hightlight the entity picked acedRedraw (ename1, 3); ads_name ename2; // now pick the second entity res = acedEntSel ( L"nPick second entity : ", ename2, pnt); // if the user wants to carry on if (res == RTNORM) { // hightlight the entity picked acedRedraw (ename2, 3); AcGePoint3dArray intersectionPoints; // get the intersection point of 2 // entities and return the result in // interSectionPoint if (GetIntersectionPointsOf ( ename1, ename2, intersectionPoints) == RTNORM) { // see how many points we've got int length = intersectionPoints.length (); // loop them and create a linked // list containing all of the points for (int i=0; iclose (); pEnt2->close (); return (res); } } } } return (RTERROR); } //********************************************* // get the intersection point of 2 AcDbEntity's // and return the result in interSectionPoint static int GetIntersectionPointsOf ( AcDbEntity *pEnt1, AcDbEntity *pEnt2, AcGePoint3dArray &intersectionPoints) { // if the first entity is a block reference if (pEnt1->isA() == AcDbBlockReference::desc ()) { // get intersection points from a block GetIntersectionPointsFromBlockEntities ( pEnt1, pEnt2, intersectionPoints); } // if the first entity is a block reference else if ( pEnt2->isA() == AcDbBlockReference::desc ()) { // get intersection points from a block GetIntersectionPointsFromBlockEntities ( pEnt2, pEnt1, intersectionPoints); } else { // found out where they intersect with each other pEnt1->intersectWith ( pEnt2, AcDb::kOnBothOperands, intersectionPoints); } return (RTNORM); } //********************************************* // get intersection points from a block static int GetIntersectionPointsFromBlockEntities ( AcDbEntity *pEnt1, AcDbEntity *pEnt2, AcGePoint3dArray &intersectionPoints) { // can't handle 2 blocks if (pEnt2->isA() == AcDbBlockReference::desc ()) { acutPrintf ( L"nError - this routine can't handle 2 blocks, sorry"); return (RTERROR); } // dynamic cast to BlockReference AcDbBlockReference *pBlockRef = AcDbBlockReference::cast (pEnt1); if (pBlockRef != NULL) { AcDbVoidPtrArray entitySet; // explode the block, this will return a // load of pre-transfromed entities for our perusal Acad::ErrorStatus es = pBlockRef->explode (entitySet);
// if it worked ok if (es == Acad::eOk) { // loop round getting the intersection points for (long i=0l; i
</div> </div> </div> </div>

Leave a Reply