ade_qryhandent

Land Desktop Development ARX CPP SDK

Up a level
ade_qryhandent
 
 

Gets the entity name for the specified handle.

int

ade_qryhandent(

ade_id dwg_id,

char* handle,

ads_name result);

Returns RTNORM or an error code.

dwg_id ID of the drawing in which the object resides.
handle Original handle of the object in the specified drawing.
result Output the entity name for the specified drawing ID and handle.

This function provides access to the entity name of an object in a source database.

You must use the retrieved entity name immediately before you call any other function (except ade_expreval) or return control to AutoCAD.

Once you have the entity name of an object, you can use it with other functions. For example, you could use entget (or ads_entget) to retrieve the entity and its definition data.

To get the original handle of the object in the source drawing, use the ade_qrygetentlist function.

To obtain a drawing ID, use ade_dslist.

To get the ID of a drawing given a drawing file path, use ade_dwggetid.

The following sample shows how you can combine ade_qrygetentlist and ade_qryhandent to count the number of objects in the source drawing(s) that are of type lwpolyline. First the current query defenition is cleared and a new location query is defined. The drawing ids for the attached drawings are obtained using ade_dslist(). Entity handles for objects which satisfy the current query are obtained from the active drawing using ade_qrygetentlist. The resbuf returned by ade_qrygetentlist is parsed and the entity name for each object is passed to acdbEntGet() which returns entity information that is checked for a type of LWPOLYLINE. A count of lwpolylines is displayed and all resbufs are released as required.

int resultCode = ade_qryclear();

char* pszJoinOperator       = "";   // none
char* pszBgnCondGrouping    = "";   // none
char* pszNotOperator        = "";   // none
char* pszCondType           = "Location";
char* pszEndCondGrouping    = "";   // none

struct resbuf* pLocQueryConditionRb = acutBuildList(
                                        RTLB,
                                            RTSTR, "All",
                                        RTLE,
                                        0 );
ade_id locQueryId = ade_qrydefine(
                        pszJoinOperator,
                        pszBgnCondGrouping,
                        pszNotOperator,
                        pszCondType,
                        pLocQueryConditionRb,
                        pszEndCondGrouping);

long lwPlineCount = 0;
struct resbuf* pSelectedObjHandlesRb = NULL;
struct resbuf* pEntdata = NULL;

struct resbuf* pAttachedDwgsRb = ade_dslist(ADE_NULLID, 1);
if (NULL != pAttachedDwgsRb) {
    struct resbuf* rb = pAttachedDwgsRb;
    while(NULL != rb) {
        if (ADE_TRUE == ade_dwgisactive(rb->resval.rreal)) {
            pSelectedObjHandlesRb = ade_qrygetentlist(rb->resval.rreal);
            if (NULL != pSelectedObjHandlesRb) {
                struct resbuf* rb1 = pSelectedObjHandlesRb;
                while(NULL != rb1) {
                    ads_name queriedEntity;
                    resultCode = ade_qryhandent(
                                    rb->resval.rreal,       // dwg_id
                                    rb1->resval.rstring,    // handle
                                    queriedEntity);
                    pEntdata = acdbEntGet(queriedEntity);
                    while(NULL != pEntdata) {
                        if (0 == pEntdata->restype &&
                            (_tcscmp(pEntdata->resval.rstring, "LWPOLYLINE") == 0)) {

                               lwPlineCount++;
                        }
                        pEntdata = pEntdata->rbnext;
                    }
                    rb1 = rb1->rbnext;
                }
            }
            acutPrintf(
                "\nThere are %d \"LWPOLYLINES\" in the active drawing set."
                , lwPlineCount);
        }
        else{
            acutPrintf(
                "\nThe drawing was not active.");
        }
        rb = rb->rbnext;
    }
}
else {
    acutPrintf(
        "\nThere are no attached drawings in this project.");
}
acutRelRb(pAttachedDwgsRb);
acutRelRb(pSelectedObjHandlesRb);
acutRelRb(pEntdata);