Global Function Extension Dictionary Example

The following example uses global ObjectARX functions to create an xrecord and add it to the dictionary associated with the key ASDK_REC.

int
createXrecord()
{
    struct resbuf *pXrec, *pEnt, *pDict, *pTemp, *pTemp2;
    ads_point dummy, testpt = {1.0, 2.0, 0.0};
    ads_name xrecname, ename, extDict = {0L, 0L};
    // Have the user select an entity.  Then get its data.
    //
    if (acedEntSel("\nselect entity: ", ename, dummy)
        != RTNORM)
    {
        acutPrintf("\nNothing selected");
        acedRetVoid();
        return RTNORM;
    }
    pEnt = acdbEntGet(ename);
    // Now check to see if the entity already has an
    // extension dictionary.
    //
    for (pTemp = pEnt; pTemp->rbnext != NULL;
        pTemp = pTemp->rbnext)
    {
        if (pTemp->restype == 102) {
            if (!strcmp("{ACAD_XDICTIONARY",
                pTemp->resval.rstring))
            {
                ads_name_set(pTemp->rbnext->resval.rlname, extDict);
                break;
            }
        }
    }
    // If no extension dictionary exists, add one.
    //
    if (extDict[0] == 0L) {
        pDict = acutBuildList(RTDXF0, "DICTIONARY", 100,
            "AcDbDictionary", 0);
        acdbEntMakeX(pDict, extDict);
        acutRelRb(pDict);
        pDict = acutBuildList(102, "{ACAD_XDICTIONARY", 360,
            extDict, 102, "}", 0);
        for (pTemp = pEnt; pTemp->rbnext->restype != 100;
            pTemp = pTemp->rbnext)
            { ; }
        for (pTemp2 = pDict; pTemp2->rbnext != NULL;
            pTemp2 = pTemp2->rbnext)
            { ; }
        pTemp2->rbnext = pTemp->rbnext;
        pTemp->rbnext = pDict;
        acdbEntMod(pEnt);
        acutRelRb(pEnt);
    }
    // At this point the entity has an extension dictionary.
    // Create a resbuf list of the xrecord's entity information
    // and data.
    //
    pXrec = acutBuildList(RTDXF0, "XRECORD",
        100, "AcDbXrecord",
        1, "This is a test Xrecord list", //AcDb::kDxfText
        10, testpt,                       //AcDb::kDxfXCoord
        40, 3.14159,                      //AcDb::kDxfReal
        50, 3.14159,                      //AcDb::kDxfAngle
        60, 1,                            //AcDb::kDxfColor
        70, 180,                          //AcDb::kDxfInt16
        0);
    // Create the xrecord with no owner set.  The xrecord's
    // new entity name will be placed into the xrecname
    // argument.
    //
    acdbEntMakeX (pXrec, xrecname);
    acutRelRb (pXrec);
    // Set the xrecord's owner to the extension dictionary
    //
    acdbDictAdd(extDict, "ASDK_XRECADS", xrecname);
    acedRetVoid();
    return RTNORM;
}
// Accesses the xrecord associated with the key ASDK_XRECADS in
// the extension dictionary of a user-selected entity. Then
// list out the contents of this xrecord using the printList
// function.
//
int
listXrecord()
{
    struct resbuf *pXrec, *pEnt, *pTemp;
    ads_point dummy;
    ads_name ename, extDict = {0L, 0L};
    // Have the user select an entity; then get its data.
    //
    if (acedEntSel("\nselect entity: ", ename, dummy) != RTNORM) {
        acutPrintf("\nNothing selected");
        acedRetVoid();
        return RTNORM;
    }
    pEnt = acdbEntGet(ename);
    // Get the entity name of the extension dictionary.
    //
    for (pTemp = pEnt;pTemp->rbnext != NULL;pTemp = pTemp->rbnext) {
        if (pTemp->restype == 102) {
            if (!strcmp("{ACAD_XDICTIONARY", pTemp->resval.rstring)){
                ads_name_set(pTemp->rbnext->resval.rlname, extDict);
                break;
            }
        }
    }
    if (extDict[0] == 0L) {
        acutPrintf("\nNo extension dictionary present.");
        return RTNORM;
    }
    pXrec = acdbDictSearch(extDict, "ASDK_XRECADS", 0);
    if(pXrec) {
        printList(pXrec);
        acutRelRb(pXrec);
    }
    acedRetVoid();
    return RTNORM;
}