CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

相关分类

全局函数扩展字典示例

2023-1-1 05:08| 发布者: admin| 查看: 304| 评论: 0|来自: AutoCAD

下面的示例使用全局 ObjectARX 函数创建 xrecord,并将其添加到与键关联的字典中。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;
}

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 15:55

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部