CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

创建字典

2024-5-18 19:11| 发布者: admin| 查看: 106| 评论: 0|原作者: admin|来自: AutoCAD

创建字典

下面的示例创建一个新字典 (ASDK_DICT) 并将其添加到命名对象字典中。然后,它创建自定义类的两个新对象(派生自 ),并使用该函数将它们添加到字典中。AsdkMyClassAcDbObjectsetAt()

注意:使用函数添加对象后,您需要关闭对象。setAt()
// This function creates two objects of class AsdkMyClass. 
// It fills them in with the integers 1 and 2, and then adds 
// them to the dictionary associated with the key ASDK_DICT. If this
// dictionary doesn't exist, it is created and added to the named
// object dictionary.
//
void
createDictionary()
{
    AcDbDictionary *pNamedobj;
    acdbHostApplicationServices()->workingDatabase()->
        getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite);
    // Check to see if the dictionary we want to create is
    // already present. If not, create it and add
    // it to the named object dictionary.
    //
    AcDbDictionary *pDict;
    if (pNamedobj->getAt("ASDK_DICT", (AcDbObject*&) pDict,
        AcDb::kForWrite) == Acad::eKeyNotFound)
    {
        pDict = new AcDbDictionary;
        AcDbObjectId DictId;
        pNamedobj->setAt("ASDK_DICT", pDict, DictId);
    }
    pNamedobj->close();
    if (pDict) {
        // Create new objects to add to the new dictionary,
        // add them, then close them.
        //
        AsdkMyClass *pObj1 = new AsdkMyClass(1);
        AsdkMyClass *pObj2 = new AsdkMyClass(2);
        AcDbObjectId rId1, rId2;
        pDict->setAt("OBJ1", pObj1, rId1);
        pDict->setAt("OBJ2", pObj2, rId2);
        pObj1->close();
        pObj2->close();
        pDict->close();
    }
}

父主题:

  1. 字典

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-12-15 22:07

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部