找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1679|回复: 0

[分享] 如何创建命名UCS并设置到当前的ARX代码

[复制链接]

已领礼包: 13个

财富等级: 恭喜发财

发表于 2013-5-5 01:05:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
[sell=5]
[pcode=cpp,true]//This program shows how to create named ucs and set it current
//Author I. R. Nagwani
//Developer Consulting Group, Autodesk
//Date Written 8-12-99

#include "dbsymtb.h"
#include "rxregsvc.h"           // ARX linker
#include "dbapserv.h"           // Host application services
#include "acdb.h"               // acdb definitions

#include "aced.h"               // aced stuff
#include "adslib.h"             // RXADS definitions

// This command registers an ARX command.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
                                const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal = -1);

// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_MSG
void InitApplication();
void UnloadApplication();
//}}AFX_ARX_MSG

// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_ADDIN_FUNCS
//}}AFX_ARX_ADDIN_FUNCS


void asdktest()
{
        Acad::ErrorStatus es;
        AcDbUCSTableRecord *myUCS = new AcDbUCSTableRecord;


        //define your own ucs
        AcGePoint3d  origin_point(0,0,0);
        AcGeVector3d UCSXaxis(0,1,0);
        AcGeVector3d UCSYaxis(1,0,0);


        myUCS->setOrigin(origin_point);
        myUCS->setXAxis(UCSXaxis);
        myUCS->setYAxis(UCSYaxis);

        es=myUCS->setName( "MyUCS");
        if (es != Acad::eOk)
        {
                acutPrintf("\nFailed to set name");
                return;
        }

        AcDbObjectId UCSId;
        AcDbSymbolTable *pUCSTable;
       


        if (acdbHostApplicationServices()->workingDatabase()->getUCSTable(pUCSTable,AcDb::kForWrite)==Acad::eOk)
        {
                es=pUCSTable->add(UCSId,myUCS);
                es=pUCSTable->close();
                es= myUCS->close();
        }
        else
        {
                acutPrintf("\nFailed to get UCS table");
                return;
        }


        //To set the current UCS, I accessed the active AcDbViewportTableRecord
        // and used setUCS to set the UCS I created as current.


        AcDbViewportTable *pVT;       
        es = acedVports2VportTableRecords();
        if (es != Acad::eOk)
        {
                acutPrintf("\nFailed to load vport info into vport table records");
                return;
        }
       
        es=acdbHostApplicationServices()->workingDatabase()->getViewportTable(pVT,AcDb::kForRead);
        if (es != Acad::eOk)
        {
                acutPrintf("\nFailed to get vport table");
                pVT->close();
                return;
        }

        AcDbViewportTableIterator* pIter = NULL;

        es=pVT->newIterator(pIter);
        if (es != Acad::eOk)
        {
                acutPrintf("\nFailed to get vport table");
                pVT->close();
                delete pIter;
                return;
        }


       
       
        for (pIter->start();!pIter->done();pIter->step())
        {

                AcDbViewportTableRecord* pRec;
                es=pIter->getRecord(pRec,AcDb::kForWrite); //it should be open for write mode
                 if (es != Acad::eOk)
                {
                        acutPrintf("\nFailed to get vport table record");
                        pVT->close();
                        pRec->close();
                        delete pIter;
                        return;
                }       

                char* name=NULL;
                es=pRec->getName(name);
                 if (es != Acad::eOk)
                {
                        acutPrintf("\nFailed to get name from vport table");
                        pVT->close();
                        pRec->close();
                        delete pIter;
                        return;
                }       


                if (stricmp(name,"*ACTIVE")==0)
                {
                        es=pRec->setUcs(UCSId);
                }

                es=pRec->close();                                       
        }
        es=acedVportTableRecords2Vports(); //force update

        es=pVT->close();
        delete pIter;
        return ;       
}

/////////////////////////////////////////////////////////////////////////////
// ObjectARX EntryPoint
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
        switch (msg) {
        case AcRx::kInitAppMsg:
                // Comment out the following line if your
                // application should be locked into memory
                acrxDynamicLinker->unlockApplication(pkt);
                acrxDynamicLinker->registerAppMDIAware(pkt);
                InitApplication();
                break;
        case AcRx::kUnloadAppMsg:
                UnloadApplication();
                break;
        }
        return AcRx::kRetOK;
}


// Init this application. Register your
// commands, reactors...
void InitApplication()
{
        // NOTE: DO NOT edit the following lines.
        //{{AFX_ARX_INIT
        AddCommand("ASDK", "TEST", "TEST", ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, asdktest);
        //}}AFX_ARX_INIT

        // TODO: add your initialization functions

}

// Unload this application. Unregister all objects
// registered in InitApplication.
void UnloadApplication()
{
        // NOTE: DO NOT edit the following lines.
        //{{AFX_ARX_EXIT
        acedRegCmds->removeGroup("ASDK");
        //}}AFX_ARX_EXIT

        // TODO: clean up your application
}

// This functions registers an ARX command.
// It can be used to read the localized command name
// from a string table stored in the resources.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
                                const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal)
{
        char cmdLocRes[65];

        // If idLocal is not -1, it's treated as an ID for
        // a string stored in the resources.
        if (idLocal != -1) {
                HMODULE hModule = GetModuleHandle("asdkucsarx.arx");

                // Load strings from the string table and register the command.
                ::LoadString(hModule, idLocal, cmdLocRes, 64);
                acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc);

        } else
                // idLocal is -1, so the 'hard coded'
                // localized function name is used.
                acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc);
}
[/pcode]
[/sell]

评分

参与人数 1D豆 +2 收起 理由
ScmTools + 2 技术引导讨论和指点奖!

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-22 03:14 , Processed in 0.570382 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表