ObjectARX学习笔记(十九)--如何设置扩展字典的数据AcDbDictionary

//扩展字典xtsndict
// (C) Copyright 1996-2006 by Autodesk, Inc. 
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted, 
// provided that the above copyright notice appears in all copies and 
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting 
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to 
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
// Description:
//
// This program demonstrates using extension dictionaries.
// Two commands are defined in this program:  CREATE, and
// LISTXREC.
// 
// The CREATE command calls the function createXrecord()
// which instantiates an xrecord object and adds it to the
// extension dictionary of a user selected object.
// 
// The LISTXREC command calls the listXrecord() function
// which opens the extension dictionary of a user selected
// object, looks for the xrecord created by the CREATE
// command and then calls the printList() function to print
// out the data stored in the xrecord.

#if defined(_DEBUG) && !defined(AC_FULL_DEBUG)
#error _DEBUG should not be defined except in internal Adesk debug builds
#endif

#include <stdlib.h>
#include <rxobject.h>
#include <rxregsvc.h>
#include <aced.h>
#include <dbsymtb.h>
#include <adslib.h>
#include <dbxrecrd.h>
#include <acestext.h>
#include "tchar.h"



void                        createXrecord();
void                        listXrecord();
AcDbObject*                 selectObject(AcDb::OpenMode);
void                        printList(struct resbuf* pBuf);
void                        initApp();
void                        unloadApp();
extern "C"
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);


// The createXrecord() functions creates an xrecord object, 
// adds data to it, and then adds the xrecord to the extension 
// dictionary of a user selected object.
// 
// THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
//
void
createXrecord()
{
    AcDbXrecord *pXrec = new AcDbXrecord;
    AcDbObject *pObj;
    AcDbObjectId dictObjId, xrecObjId;
    AcDbDictionary* pDict;

    pObj = selectObject(AcDb::kForWrite);
    if (pObj == NULL) {
        return;
    }

    // Try to create an extension dictionary for this
    // object.  If the extension dictionary already exists,
    // this will be a no-op.
    // 
    pObj->createExtensionDictionary();

    // Get the object ID of the extension dictionary for the
    // selected object.
    // 
    dictObjId = pObj->extensionDictionary();
    pObj->close();

    // Open the extension dictionary and add the new
    // xrecord to it.
    //
    acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
    pDict->setAt(_T("ASDK_XREC1"), pXrec, xrecObjId);
    pDict->close();

    // Create a resbuf list to add to the xrecord.
    //
    struct resbuf* head;
    ads_point testpt = {1.0, 2.0, 0.0};
    head = acutBuildList(AcDb::kDxfText,
        _T("This is a test Xrecord list"),
        AcDb::kDxfXCoord, testpt,
        AcDb::kDxfReal, 3.14159,
        AcDb::kDxfAngle, 3.14159,
        AcDb::kDxfColor, 1,
        AcDb::kDxfInt16, 180,
        0);

    // Add the data list to the xrecord.  Notice that this
    // member function takes a reference to a resbuf NOT a
    // pointer to a resbuf, so you must dereference the
    // pointer before sending it.
    // 
    pXrec->setFromRbChain(*head);
    pXrec->close();
    acutRelRb(head);
}


// The listxrecord() functions gets the xrecord associated with the 
// key "ASDK_XREC1" and lists out its contents by passing the resbuf 
// list to the function printList().
// 
void
listXrecord()
{
    AcDbObject *pObj;
    AcDbXrecord *pXrec;
    AcDbObjectId dictObjId;
    AcDbDictionary *pDict;

    pObj = selectObject(AcDb::kForRead);
    if (pObj == NULL) {
        return;
    }
    // Get the object ID of the object's extension dictionary.
    //
    dictObjId = pObj->extensionDictionary();
    pObj->close();

    // Open the extension dictionary and get the xrecord
    // associated with the key ASDK_XREC1.
    // 
    acdbOpenObject(pDict, dictObjId, AcDb::kForRead);
    pDict->getAt(_T("ASDK_XREC1"), (AcDbObject*&)pXrec,
        AcDb::kForRead);
    pDict->close();

    // Get the xrecord's data list and then close the xrecord.
    //
    struct resbuf *pRbList;
    pXrec->rbChain(&pRbList);
    pXrec->close();

    printList(pRbList);
    acutRelRb(pRbList);
}

// END CODE APPEARING IN SDK DOCUMENT.

// The selectObject() function prompts the user to select an 
// entity or enter an object's handle.  It then proceeds to 
// open the object/entity and return a pointer to it.
// 
AcDbObject*
selectObject(AcDb::OpenMode openMode)
{
    ads_name en;
    ads_point pt;
    TCHAR handleStr[132];
    AcDbObjectId eId;

    Acad::ErrorStatus retStat;
    int ss;

    // Allow user to either pick an entity,
    // or type in the object handle.
    //
    acedInitGet(RSG_OTHER, _T("Handle _Handle"));
    ss = acedEntSel(_T("\nSelect an Entity or enter")
        _T(" 'H' to enter its handle:  "), en, pt);

    switch (ss) {
    case RTNORM:   // got it!
        break;
    case RTKWORD:
        if ((acedGetString(Adesk::kFalse,
            _T("Enter Valid Object Handle: "),
            handleStr) == RTNORM)
            && (acdbHandEnt(handleStr, en) == RTNORM))
        {
            break;
        }
    // Fall-through intentional
    //
    default:
        acutPrintf(_T("Nothing Selected, Return Code==%d\n"),
            ss);
        return NULL;
    }

    // Now, exchange the ads_name for the object Id...
    //
    retStat = acdbGetObjectId(eId, en);
    if (retStat != Acad::eOk) {
        acutPrintf(_T("\nacdbGetObjectId failed"));
        acutPrintf(_T("\nen==(%lx,%lx), retStat==%d\n"),
            en[0], en[1], eId);
        return NULL;
    }

    AcDbObject* pObj;

    if ((retStat = acdbOpenObject(pObj, eId, openMode))
        != Acad::eOk)
    {
        acutPrintf(_T("acdbOpenEntity failed: ename:")
            _T("(%lx,%lx), mode:%d retStat:%d"), en[0],
            en[1], openMode, retStat);
        return NULL;
    }
    return pObj;
}


// The printList() function takes a linked list of resbufs 
// as an argument.  Walks the list printing out the restypes 
// and resval values one set per line.
// 
void
printList(struct resbuf* pBuf)
{
    int rt, i;
    TCHAR buf[133];

    for (i = 0;pBuf != NULL;i++, pBuf = pBuf->rbnext) {
        if (pBuf->restype < 0)
            rt = pBuf->restype;
        else if (pBuf->restype < 10)
            rt = RTSTR;
        else if (pBuf->restype < 38)
            rt = RT3DPOINT;
        else if (pBuf->restype < 60)
            rt = RTREAL;
        else if (pBuf->restype < 80)
            rt = RTSHORT;
        else if (pBuf->restype < 100)
            rt = RTLONG;
        else if (pBuf->restype < 106)
            rt = RTSTR;
        else if (pBuf->restype < 148)
            rt = RTREAL;
        else if (pBuf->restype < 290)
            rt = RTSHORT;
        else if (pBuf->restype < 330)
            rt = RTSTR;
        else if (pBuf->restype < 370)
            rt = RTENAME;
        else if (pBuf->restype < 999)
            rt = RT3DPOINT;
        else
            rt = pBuf->restype;

        switch (rt) {
        case RTSHORT:
            if (pBuf->restype == RTSHORT)
                acutPrintf(_T("RTSHORT : %d\n"),
                    pBuf->resval.rint);
            else
                acutPrintf(_T("(%d . %d)\n"), pBuf->restype,
                    pBuf->resval.rint);
            break;
        case RTREAL:
            if (pBuf->restype == RTREAL)
                acutPrintf(_T("RTREAL : %0.3f\n"),
                    pBuf->resval.rreal);
            else
                acutPrintf(_T("(%d . %0.3f)\n"), pBuf->restype,
                    pBuf->resval.rreal);
            break;
        case RTSTR:
            if (pBuf->restype == RTSTR)
                acutPrintf(_T("RTSTR : %s\n"),
                   pBuf->resval.rstring);
            else
                acutPrintf(_T("(%d . \"%s\")\n"), pBuf->restype,
                    pBuf->resval.rstring);
            break;
        case RT3DPOINT:
            if (pBuf->restype == RT3DPOINT)
                acutPrintf(
                _T("RT3DPOINT : %0.3f, %0.3f, %0.3f\n"),
                    pBuf->resval.rpoint[X],
                    pBuf->resval.rpoint[Y],
                    pBuf->resval.rpoint[Z]);
            else
                acutPrintf(
                   _T("(%d %0.3f %0.3f %0.3f)\n"),
                    pBuf->restype,
                    pBuf->resval.rpoint[X],
                    pBuf->resval.rpoint[Y],
                    pBuf->resval.rpoint[Z]);
            break;
        case RTLONG:
            acutPrintf(_T("RTLONG : %dl\n"),
                pBuf->resval.rlong);
            break;
        case -1:
        case RTENAME:
            acutPrintf(_T("(%d . <Entity name: %8lx>)\n"),
                pBuf->restype, pBuf->resval.rlname[0]);
            break;
        case -3:
            acutPrintf(_T("(-3)\n"));
        }

        if ((i == 23) && (pBuf->rbnext != NULL)) {
            i = 0;
            acedGetString(0,
                _T("Press <ENTER> to continue..."), buf);
        }
    }
    return;
}


// Initialization function called in acrxEntryPoint
// during the kInitAppMsg case.  This is where commands
// are added to the AcEd command stack.
// 
void
initApp()
{
    acedRegCmds->addCommand(_T("ASDK_EXTDICT_COMMANDS"),
        _T("ASDK_CREATE"), _T("CREATE"), ACRX_CMD_MODAL,
        createXrecord);
    acedRegCmds->addCommand(_T("ASDK_EXTDICT_COMMANDS"),
        _T("ASDK_LISTXREC"), _T("LISTXREC"), ACRX_CMD_MODAL,
        listXrecord);
}

// Clean up function called in acrxEntryPoint during the
// kUnloadAppMsg case.  This app's command group is
// removed from the AcEd command stack.
// 
void
unloadApp()
{
    acedRegCmds->removeGroup(_T("ASDK_EXTDICT_COMMANDS"));
}


// ARX entry point.
//
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
    switch (msg) {
    case AcRx::kInitAppMsg:
        acrxDynamicLinker->unlockApplication(appId);
		acrxDynamicLinker->registerAppMDIAware(appId);
        initApp();
        break;
    case AcRx::kUnloadAppMsg:
        unloadApp();
    }
    return AcRx::kRetOK;
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: ObjectARX是一种用于AutoCAD软件定制化开发的API。张帆的《ObjectARX开发实例教程》是一本适合初学者入门的书籍,通过实例的方式对ObjectARX进行系统性讲解。 本书共分为18章,从AutoCAD开发环境的搭建开始讲起,引领读者逐步深入了解ObjectARX。每一章都包含了相关实例,全面讲解了AutoCAD编程基础、ObjectARX、COM技术等相关知识点,让读者能够深入了解各种开发技术,如绘图、编辑、图形操作等。 本书中的实例都是实用性强、综合性好的项目,作者在实例中讲述了ObjectARX的各种技术应用,通过详细讲解及代码演示,使读者能够掌握这些方法,进而灵活应用到实际项目中。此外,文中还介绍了D-BASE文件格式、UNIX操作系统等相关知识,以帮助读者更好地理解AutoCAD的架构原理。 总之,张帆的《ObjectARX开发实例教程》是一本详实而全面的AutoCAD相关书籍,适合有编程基础并对AutoCAD感兴趣的读者学习参考。其中的案例演示丰富,对初学者来说十分友好,同时也能帮助已有一定开发经验的开发人员深造提高。 ### 回答2: ObjectARX是AutoCAD的开放式编程接口,使得开发者可以在AutoCAD上创建个性化的工具和应用程序。这使得AutoCAD成为一个灵活性更高的应用程序。 张帆的《ObjectARX开发实例教程》是一本以实践为主的教程,带领读者从零开始学习如何使用ObjectARX进行自定义开发。教程分为四部分,以一个图像处理器为示例介绍了ObjectARX的编写、调试、应用等技术。 第一部分介绍了ObjectARX的介绍、编程工具的准备和环境的搭建。第二部分从绘图交互的角度介绍了如何利用ObjectARX实现AutoCAD图形处理。第三部分以实例介绍了如何利用ObjectARX编写实用功能的插件程序,并介绍了用户界面设计方面的知识。第四部分介绍了如何编写和发布新的应用程序。 在实例教程中,张帆深入深出地剖析了ObjectARX开发的重要概念和技巧,介绍了它们在实际编程过程中的应用。该书比较深入且严谨,可以帮助读者了解ObjectARX中的各种实用细节,同时它也适合有一定编程基础的开发者学习。 总之,《ObjectARX开发实例教程》是入门到高阶的一本好书,对初学者和已有一定开发经验的开发者都非常适用。它既介绍了ObjectARX的基础,又让读者从编写插件和应用程序的角度发掘ObjectARX的灵活性和强大性。这使得读者可以在实践中学习编程技术,提升创造的灵活性和效率。 ### 回答3: “ObjectARX开发实例教程”是一本详细介绍了如何使用Autodesk的ObjectARX编程接口来进行CAD软件二次开发的实战教程。本书作者张帆是一位经验丰富的Autodesk软件开发专家,既有实践经验,也有丰富的教学经验,因此他在本书中将所涉及的内容讲解得非常清晰易懂。 本书从基础概念入手,先介绍了Autodesk的CAD软件和ObjectARX编程接口的基本知识,并且提供了许多实例来帮助读者更好地理解这些知识。在后续章节中,作者则依次介绍了ObjectARX的各个重要模块,如数据库、图形界面、用户界面、3D绘图等,针对每个模块提供了大量的实例代码,并详细讲解了其实现原理和使用技巧。 作为一本实战教程,本书还提供了很多实际应用场景下的编程技巧,例如如何处理大型CAD工程,如何实现CAD联网等等,这些内容将对实际开发非常有帮助。 总之,“ObjectARX开发实例教程”是一本很实用的CAD软件开发教程,对于想要学习ObjectARX编程接口的开发人员来说,读本书将是一种强有力的支持和帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值