实例代码:AcDbDatabase符号表的当前值

执行结果

 

当前图层名称:0

当前线型名称:ByLayer

当前线宽名称:kLnWtByLayer

当前文字样式名称:Standard

当前标注样式名称:ISO-25

当前表格样式名称:Standard

当前多线样式名称:STANDARD

 

源代码:

//—————————————————————————–

//—– acrxEntryPoint.h

//—————————————————————————–

#include “StdAfx.h”

#include “resource.h”

#include “dbtable.h”

//—————————————————————————–

#define szRDS _RXST(“”)

//获取符号表记录的名称

Acad::ErrorStatus GetSymbolName(CString& strName,const AcDbObjectId id)

{

AcDbSymbolTableRecordPointer<AcDbSymbolTableRecord> spRec(id,AcDb::kForRead);

if(Acad::eOk!=spRec.openStatus())

{

return spRec.openStatus();

}

const TCHAR* lpName=NULL;

Acad::ErrorStatus es=spRec->getName(lpName);

if(Acad::eOk!=es)

{

return es;

}

strName=CString(lpName);

return Acad::eOk;

}

Acad::ErrorStatus GetTableStyleName(CString& strName,const AcDbObjectId id)

{

AcDbObjectPointer<AcDbTableStyle> spRec(id,AcDb::kForRead);

if(Acad::eOk!=spRec.openStatus())

{

return spRec.openStatus();

}

TCHAR* lpName=NULL;

Acad::ErrorStatus es=spRec->getName(lpName);

if(Acad::eOk!=es)

{

return es;

}

strName=CString(lpName);

acutDelString(lpName);

return Acad::eOk;

}

Acad::ErrorStatus GetMlineStyleName(CString& strName,const AcDbObjectId id)

{

AcDbObjectPointer<AcDbMlineStyle> spRec(id,AcDb::kForRead);

if(Acad::eOk!=spRec.openStatus())

{

return spRec.openStatus();

}

strName=CString(spRec->name());

return Acad::eOk;

}

 

CString GetLineWeightName(const AcDb::LineWeight lt)

{

switch(lt)

{

case AcDb::kLnWt000:

return _T(“kLnWt000”);

case AcDb::kLnWt005:

return _T(“kLnWt005”);

case AcDb::kLnWt009:

return _T(“kLnWt009”);

case AcDb::kLnWt013:

return _T(“kLnWt013”);

case AcDb::kLnWt015:

return _T(“kLnWt015”);

case AcDb::kLnWt018:

return _T(“kLnWt018”);

case AcDb::kLnWt020:

return _T(“kLnWt020”);

case AcDb::kLnWt025:

return _T(“kLnWt025”);

case AcDb::kLnWt030:

return _T(“kLnWt030”);

case AcDb::kLnWt035:

return _T(“kLnWt035”);

case AcDb::kLnWt040:

return _T(“kLnWt040”);

case AcDb::kLnWt050:

return _T(“kLnWt050”);

case AcDb::kLnWt053:

return _T(“kLnWt053”);

case AcDb::kLnWt060:

return _T(“kLnWt060”);

case AcDb::kLnWt070:

return _T(“kLnWt070”);

case AcDb::kLnWt080:

return _T(“kLnWt080”);

case AcDb::kLnWt090:

return _T(“kLnWt090”);

case AcDb::kLnWt100:

return _T(“kLnWt100”);

case AcDb::kLnWt106:

return _T(“kLnWt106”);

case AcDb::kLnWt120:

return _T(“kLnWt120”);

case AcDb::kLnWt140:

return _T(“kLnWt140”);

case AcDb::kLnWt158:

return _T(“kLnWt158”);

case AcDb::kLnWt200:

return _T(“kLnWt200”);

case AcDb::kLnWt211:

return _T(“kLnWt211”);

case AcDb::kLnWtByLayer:

return _T(“kLnWtByLayer”);

case AcDb::kLnWtByBlock:

return _T(“kLnWtByBlock”);

case AcDb::kLnWtByLwDefault:

return _T(“kLnWtByLwDefault”);

default:

return _T(“未知”);

}

}

void Test()

{

//当前数据库

AcDbDatabase* pDb=acdbHostApplicationServices()->workingDatabase();

if(pDb==NULL)

{

acutPrintf(_T(“\n当前数据库为空\n”));

return;

}

CString strName;

Acad::ErrorStatus es=Acad::eOk;

//图层名称

es=GetSymbolName(strName,pDb->clayer());

if(Acad::eOk!=es)

{

acutPrintf(_T(“\n获取当前图层名称出错:%s\n”),acadErrorStatusText(es));

}

else

{

acutPrintf(_T(“\n当前图层名称:%s\n”),strName);

}

//线型

es=GetSymbolName(strName,pDb->celtype());

if(Acad::eOk!=es)

{

acutPrintf(_T(“\n获取当前线型名称出错:%s\n”),acadErrorStatusText(es));

}

else

{

acutPrintf(_T(“\n当前线型名称:%s\n”),strName);

}

//线宽

AcDb::LineWeight lt=pDb->celweight();

acutPrintf(_T(“\n当前线宽名称:%s\n”),GetLineWeightName(lt));

//文字样式

es=GetSymbolName(strName,pDb->textstyle());

if(Acad::eOk!=es)

{

acutPrintf(_T(“\n获取当前文字样式名称出错:%s\n”),acadErrorStatusText(es));

}

else

{

acutPrintf(_T(“\n当前文字样式名称:%s\n”),strName);

}

//标注样式

es=GetSymbolName(strName,pDb->dimstyle());

if(Acad::eOk!=es)

{

acutPrintf(_T(“\n获取当前标注样式名称出错:%s\n”),acadErrorStatusText(es));

}

else

{

acutPrintf(_T(“\n当前标注样式名称:%s\n”),strName);

}

//表格样式

es=GetTableStyleName(strName,pDb->tablestyle());

if(Acad::eOk!=es)

{

acutPrintf(_T(“\n获取当前表格样式名称出错:%s\n”),acadErrorStatusText(es));

}

else

{

acutPrintf(_T(“\n当前表格样式名称:%s\n”),strName);

}

//多线样式

es=GetMlineStyleName(strName,pDb->cmlstyleID());

if(Acad::eOk!=es)

{

acutPrintf(_T(“\n获取当前多线样式名称出错:%s\n”),acadErrorStatusText(es));

}

else

{

acutPrintf(_T(“\n当前多线样式名称:%s\n”),strName);

}

}

//—————————————————————————–

//—– ObjectARX EntryPoint

class CExample002App : public AcRxArxApp {

 

public:

CExample002App () : AcRxArxApp () {}

 

virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {

// TODO: Load dependencies here

 

// You *must* call On_kInitAppMsg here

AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;

 

//增加命令Test

acedRegCmds->addCommand(_T(“Example002App”),_T(“Test”),_T(“Test”),0,Test);

 

// TODO: Add your initialization code here

 

return (retCode) ;

}

 

virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {

// TODO: Add your code here

 

// You *must* call On_kUnloadAppMsg here

AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;

 

// TODO: Unload dependencies here

//删除命令组

acedRegCmds->removeGroup(_T(“Example002App”));

 

return (retCode) ;

}

 

virtual void RegisterServerComponents () {

}

 

} ;

 

//—————————————————————————–

IMPLEMENT_ARX_ENTRYPOINT(CExample002App)

此条目发表在ObjectArx分类目录,贴了, , 标签。将固定链接加入收藏夹。

发表评论