ObjectARX学习笔记(十七)--如何添加扩展记录xrecord

<pre name="code" class="cpp">//这是CAD自带的例子


 
// (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 xrecords.  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 a
// dictionary object in the named objects dictionary.
// 
// The LISTXREC command calls the listXrecord() function
// which opens the dictionary containing 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 <dbapserv.h>
#include <adslib.h>
#include <dbxrecrd.h>
#include "tchar.h"



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


// Creates an xrecord object, adds data to it, and then adds
// the xrecord to a dictionary in the named objects
// dictionary.  Technically we could just add the xrecord to
// the named objects dictionary itself, but that's bad form
// since it will tend to clutter up the named objects
// dictionary.
// 
// THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
//
void
createXrecord()
{
    AcDbDictionary *pNamedobj, *pDict;
    acdbHostApplicationServices()->workingDatabase()
        ->getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite);

    // Check to see if the dictionary we want to create is
    // already present. If not, then create it and add
    // it to the named object dictionary.
    // 
    if (pNamedobj->getAt(_T("ASDK_DICT"), (AcDbObject*&) pDict,
        AcDb::kForWrite) == Acad::eKeyNotFound)
    {
        pDict = new AcDbDictionary;
        AcDbObjectId DictId;
        pNamedobj->setAt(_T("ASDK_DICT"), pDict, DictId);
    }
    pNamedobj->close();

    // Add a new xrecord to the ASDK_DICT dictionary.
    //
    AcDbXrecord *pXrec = new AcDbXrecord;
    AcDbObjectId xrecObjId;
    pDict->setAt(_T("XREC1"), pXrec, xrecObjId);
    pDict->close();

    // Create a resbuf list to add to the xrecord.
    //
    struct resbuf *pHead;
    ads_point testpt = {1.0, 2.0, 0.0};
    pHead = 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 resbuf, NOT a
    // pointer to resbuf, so you must dereference the
    // pointer before sending it.
    // 
    pXrec->setFromRbChain(*pHead);

    acutRelRb(pHead);
    pXrec->close();
}

// Gets the xrecord associated with the key XREC1 and
// lists out it's contents by passing the resbuf list to the
// function printList.
// 
void
listXrecord()
{
    AcDbDictionary *pNamedobj;
    acdbHostApplicationServices()->workingDatabase()
        ->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead);

    // Get the dictionary object associated with the key ASDK_DICT.
    //
    AcDbDictionary *pDict;
    pNamedobj->getAt(_T("ASDK_DICT"), (AcDbObject*&)pDict,
        AcDb::kForRead);
    pNamedobj->close();

    // Get the xrecord associated with the key XREC1.
    //
    AcDbXrecord *pXrec;
    pDict->getAt(_T("XREC1"), (AcDbObject*&) pXrec,
        AcDb::kForRead);
    pDict->close();

    struct resbuf *pRbList;
    pXrec->rbChain(&pRbList);
    pXrec->close();

    printList(pRbList);
    acutRelRb(pRbList);
}

// END CODE APPEARING IN SDK DOCUMENT.

// 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)
            // Entity name (or other sentinel)
            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 // pBuf->restype is already RTSHORT, RTSTR,
            rt = pBuf->restype; // etc. or it is unknown.

        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: // First block entity
            acutPrintf(_T("(%d . <Entity name: %8lx>)\n"),
                pBuf->restype, pBuf->resval.rlname[0]);
            break;
        case -3: // marks start of xdata
            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_XRECORD_COMMANDS"),
        _T("ASDK_CREATE"), _T("CREATE"), ACRX_CMD_MODAL,
        createXrecord);
    acedRegCmds->addCommand(_T("ASDK_XRECORD_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_XRECORD_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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值