Get the information of a nested entity in an XREFed drawing and its associated groups

By Gopinath Taget

The following piece of code demonstrates how to retrieve information from a nested entity within an XREF. Please keep these key points in mind:

  1. Use the acedNEntSelP() function to select the nested entity instead of acedEntSel().
  2. Use obj->database()->getFilename(fname) to retrieve the XREF drawing name.
  3. The Group object is a persistent reactor attached to its members. You can access all reactors associated with an entity using the obj->reactors() function.

void BZH_readxref() {
    // Get the information of a nested entity in an XREF drawing.
    // Output the group information associated with the entity if applicable.
    int result;
    ads_name ent;
    ads_point ptres;
    int pickflag;
    ads_matrix xformres;
    struct resbuf* refstkres;

    pickflag = 0;
    result = acedNEntSelP(_T("\nSelect a nested entity: "), ent, ptres, pickflag, xformres, &refstkres);

    if (result == RTNORM) {
        AcDbObjectId objId;
        AcDbObject* obj;
        Acad::ErrorStatus es;
        CString str;

        acdbGetObjectId(objId, ent);
        es = acdbOpenAcDbObject(obj, objId, AcDb::kForRead);
        assert(es == Acad::eOk);

        acutPrintf(_T("\n\nClass Name: %s"), obj->isA()->name());
        acutPrintf(_T("\nEntity Name: %lx"), ent[0]);

        AcDbHandle handle;
        ACHAR tempStr[256];
        obj->getAcDbHandle(handle);
        handle.getIntoAsciiBuffer(tempStr);
        str = tempStr;
        acutPrintf(_T("\nHandle: %s"), str);

        const ACHAR* fname;
        es = obj->database()->getFilename(fname);
        acutPrintf(_T("\nDatabase: %s"), fname);

        void* pSomething;
        AcDbVoidPtrArray* reactors = obj->reactors();
        if (reactors != NULL) {
            for (int i = 0; i < reactors->length(); i++) {
                pSomething = reactors->at(i);
                if (acdbIsPersistentReactor(pSomething)) {
                    AcDbObject* pTempObj;
                    es = acdbOpenObject(pTempObj, acdbPersistentReactorObjectId(pSomething), AcDb::kForRead);
                    
                    AcDbGroup* pGroup;
                    pGroup = AcDbGroup::cast(pTempObj);
                    
                    if (pGroup == NULL) {
                        pTempObj->close();
                        continue;
                    } else {
                        pGroup->getAcDbHandle(handle);
                        handle.getIntoAsciiBuffer(tempStr);
                        str = tempStr;
                        acutPrintf(_T("\nGroup handle: %s"), str);
                        pGroup->close();
                    }
                }
            }
        }
        obj->close();
    } else {
        acutPrintf(_T("\nnacedNEntSelP error!"));
    }
    return;
}
    

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading