CAD ObjectARX扩展工具的源码(一)

收藏的CAD扩展工具的源码:

Acad::ErrorStatus CDrawFunction::getAllEntity(AcDbDatabase *pDb,AcDbObjectIdArray& IdArr,
const AcArray& layerNameArr)
{
Acad::ErrorStatus es=Acad::eOk;
ASSERT(pDb);
if(pDb==NULL)
return Acad::eInalidInput;
AcDbBlockTable *pBlkTable=NULL;
if((es=pDb->getBlockTable(pBlkTable,AcDb::kForRead))!=Acad::eOk)//打开块表
{
acedAlert("打开块表失败");
return es;
}
AcDbBlockTableRecord *pBlkTableRecord=NULL;
if((es=pBlkTable->getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb::kForRead))!=Acad::eOk)//打开块表记录
{
acedAlert("打开块表记录失败");
pBlkTable->close();
return es;
}
pBlkTable->close();//关闭块表

AcDbBlockTableRecordIterator *pIterator=NULL; //创建叠代器
if((es=pBlkTableRecord->newIterator(pIterator))!=Acad::eOk)
{
pBlkTableRecord->close();
return es;
}

CAcModuleResourceOerride resoerride;
CProgressDlg progress;
progress.Create();
progress.SetPos(0);
progress.SetWindowText("正在检测图形中所有实体...");

for(pIterator->start();!pIterator->done();pIterator->step())//遍历整个数据库
{
AcDbEntity *entity=NULL;
es=pIterator->getEntity(entity,AcDb::kForRead); //打开实体

if(es==Acad::eLockiolation)
{
acedAlert("内存锁定");
}
else if(es==Acad::eWasOpenForWrite)
{
acedAlert("实体以写方式打开");
}
else if(es==Acad::eWasOpenForRead)
{
acedAlert("实体以读方式打开");
}
else
{
if(layerNameArr.contains(entity->layer()))
IdArr.append(entity->objectId());
entity->close();
}
progress.StepIt();
}
delete pIterator;pIterator=NULL;
pBlkTableRecord->close();
acutPrintf("eend");
return es;
}

//得到指定层上指定颜色的所有实体
Acad::ErrorStatus CDrawFunction::getAllEntity(AcDbDatabase *pDb,AcDbObjectIdArray& IdArr,
const AcArray& layerNameArr,Adesk::UInt16 colorIndex)
{
Acad::ErrorStatus es=Acad::eOk;
ASSERT(pDb);
if(pDb==NULL)
return Acad::eInalidInput;
AcDbBlockTable *pBlkTable=NULL;
if((es=pDb->getBlockTable(pBlkTable,AcDb::kForRead))!=Acad::eOk)//打开块表
{
acedAlert("打开块表失败");
return es;
}
AcDbBlockTableRecord *pBlkTableRecord=NULL;
if((es=pBlkTable->getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb::kForRead))!=Acad::eOk)//打开块表记录
{
acedAlert("打开块表记录失败");
pBlkTable->close();
return es;
}
pBlkTable->close();//关闭块表

AcDbBlockTableRecordIterator *pIterator=NULL; //创建叠代器
if((es=pBlkTableRecord->newIterator(pIterator))!=Acad::eOk)
{
pBlkTableRecord->close();
return es;
}

CAcModuleResourceOerride resoerride;
CProgressDlg progress;
progress.Create();
progress.SetPos(0);
progress.SetWindowText("正在检测图形中所有实体...");

for(pIterator->start();!pIterator->done();pIterator->step())//遍历整个数据库
{
AcDbEntity *entity=NULL;
if((es=pIterator->getEntity(entity,AcDb::kForRead))!=Acad::eOk)//打开实体
{
delete pIterator;pIterator=NULL;
pBlkTableRecord->close();
return es;
}
if(layerNameArr.contains(entity->layer())&&entity->colorIndex()==colorIndex)
IdArr.append(entity->objectId());
entity->close();
progress.StepIt();
}
delete pIterator;pIterator=NULL;
pBlkTableRecord->close();
return es;
}

//得到图形中所有的层
Acad::ErrorStatus CDrawFunction::getAllLayerName(AcDbDatabase *pDb,CStringArray& layerArray)
{
Acad::ErrorStatus es=Acad::eOk;
if(pDb==NULL)
return Acad::eInalidInput;
layerArray.RemoeAll();
AcDbLayerTable *pLayerTable=NULL;
if((es=pDb->getSymbolTable(pLayerTable,AcDb::kForRead))!=Acad::eOk)
{
pLayerTable->close();
return es;
}
//创建一个层表迭代器
AcDbLayerTableIterator *pLayerTableIterator;
pLayerTable->newIterator(pLayerTableIterator);
pLayerTable->close();

char *pLayerName=NULL;
CString name;
for(int i=0;!pLayerTableIterator->done();pLayerTableIterator->step(),i++)
{
AcDbLayerTableRecord *pLayerTableRecord=NULL;
pLayerTableIterator->getRecord(pLayerTableRecord,AcDb::kForRead);
pLayerTableRecord->getName(pLayerName);
name.Format("%s",pLayerName);
pLayerTableRecord->close();
layerArray.Add(name);

}

if(pLayerName) acutDelString(pLayerName);
delete pLayerTableIterator;pLayerTableIterator=NULL;
return es;
}

//
//
BOOL CDrawFunction::getLinetypeIdFromString(const char* str, AcDbObjectId& id)
{
//----查找安装目录----//
CString AcadInstallPath;
FindAcadInstallPath(AcadInstallPath);
CString File=AcadInstallPath+"//linetype//user.lin";
//-----查找完毕--------//
ASSERT(str!=NULL);
AcDbLinetypeTable *pLinetypeTable;
acdbHostApplicationSerices()->workingDatabase()->getSymbolTable(pLinetypeTable, AcDb::kForRead);
Acad::ErrorStatus mess;
mess=pLinetypeTable->getAt(str,id);
if(mess==Acad::eKeyNotFound||mess==Acad::ePermanentlyErased)
{
pLinetypeTable->close();
Acad::ErrorStatus error;

error=acdbLoadLineTypeFile(str,File.GetBuffer(0),acdbHostApplicationSerices()->workingDatabase());
if(error==Acad::eNullObjectPointer)
{
AcDbLinetypeTable *pLinetypeTable;
acdbHostApplicationSerices()->workingDatabase()->getSymbolTable(pLinetypeTable, AcDb::kForRead);
pLinetypeTable->getAt("CONTINUOUS", id);
pLinetypeTable->close();
return FALSE;
}
else if(error==Acad::eFileSystemErr)
{
AfxMessageBox("the specified file cannot be opened");
return FALSE;
}
else if(error==Acad::eUndefinedLineType)
{
AcDbLinetypeTable *pLinetypeTable;
acdbHostApplicationSerices()->workingDatabase()->getSymbolTable(pLinetypeTable, AcDb::kForRead);
AfxMessageBox("the linetype name specified by ltname is not found in the file");
pLinetypeTable->getAt("CONTINUOUS", id);
pLinetypeTable->close();
return TRUE;
}
AcDbLinetypeTable *pLinetypeTable;
acdbHostApplicationSerices()->workingDatabase()->getSymbolTable(pLinetypeTable, AcDb::kForRead);
pLinetypeTable->getAt(str,id);
pLinetypeTable->close();
return TRUE;
}
pLinetypeTable->close();
return TRUE;
}

oid CDrawFunction::FindAcadInstallPath(CString &AcadInstallPath)
{
//查找样式目录安装路径
TCHAR AcadPath[255];
HKEY hKey;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE//线路处开发组//RDS2002//1.00"),0,KEY_QUERY_ALUE,&hKey)!=ERROR_SUCCESS)
{
::AfxMessageBox("注册路径不对");
return ;
}
DWORD dwDataType=REG_SZ;
DWORD dwLength=255;
LONG lRet=RegQueryalueEx(hKey,TEXT("path"),NULL,NULL,(LPBYTE)AcadPath,&dwLength);
RegCloseKey(hKey);
if(lRet!=ERROR_SUCCESS)
{
acutPrintf("Read failed/n");
return ;
}
//-----查找完毕--------//
AcadInstallPath.Format("%s",AcadPath);
}

AcDbObjectId CDrawFunction::createTextStyle(CString fontName,CString bigFontName,CString textStyleName)
{
AcGiTextStyle *TextStyle=new AcGiTextStyle
(fontName,
bigFontName,
0,
0.67,
0,
0,
Adesk::kFalse,
Adesk::kFalse,
Adesk::kFalse,
Adesk::kFalse,
Adesk::kFalse,
textStyleName); //字体名
AcDbObjectId textStyleId;
toAcDbTextStyle(*TextStyle,textStyleId);
return textStyleId;
}

AcDbObjectId CDrawFunction::createMutiText(AcGePoint3d BasePoint,AcDb::TextHorzMode hMode,AcDb::TextertMode Mode,CString Text,double texthight,double widthfactor,double angle,int color,CString smallFontName,CString bigFontName,CString layerName)
{
ASSERT(Text!=NULL);
AcDbMText *pMText=new AcDbMText();
if(pMText==NULL)
throw Acad::eOutOfMemory;
AcDbObjectId TextStyleId;
TextStyleId=createTextStyle(smallFontName,bigFontName,"xianlu");
pMText->setTextStyle(TextStyleId);
pMText->setContents(Text.GetBuffer(Text.GetLength()));
pMText->setTextHeight(texthight);
pMText->setRotation(angle);
pMText->setLineSpacingFactor(0.8);
pMText->setColorIndex(color);
if(layerName!="")
pMText->setLayer(layerName.GetBuffer(0));
AcDbObjectId MTextId;
addToModelSpace(MTextId, pMText);
pMText->close();
return MTextId;
}

CAD ObjectARX扩展工具的源码(一)相关推荐

  1. H5类似易企秀/编辑器/页面制作/开发/生成工具/软件/源码/授权

    代码地址如下: http://www.demodashi.com/demo/14960.html 项目简介 H5DS (HTML5 Design software) 这是一款基于WEB的 H5制作工具 ...

  2. Dubbo第三讲:Dubbo的可扩展机制SPI源码解析

    本文是Dubbo第三讲:Dubbo的可扩展机制SPI源码解析 文章目录 1.Dubbo SPI机制 1.1.Dubbo具有良好拓展性的原因 1.2.Dubbo SPI和Java SPI的区别? 1.3 ...

  3. 免费开源!新学期必收藏的AI学习资源,从课件、工具到源码都齐了

    (图片付费下载于视觉中国) 整理 | Jane 出品 | AI科技大本营(ID:rgznai100) 2019 年 3 月 28 日,教育部公布了 2018 年度普通高等学校本科专业备案和审批结果,共 ...

  4. 可视化工具gephi源码探秘(二)---导入netbeans

    在上篇<可视化工具gephi源码探秘(一)>中主要介绍了如何将gephi的源码导入myeclipse中遇到的一些问题,此篇接着上篇而来,主要讲解当下通过myeclipse导入gephi源码 ...

  5. git工具 将源码clone到本地指定目录的三种方式

    git工具 将源码clone到本地指定目录的三种方式 CreationTime--2018年7月27日15点34分 Author:Marydon 1.情景展示 运行git-bash.exe,输入命令: ...

  6. apk源码查看工具_如何查看Linux命令工具的源码?

    点击上方「嵌入式大杂烩」,「星标公众号」第一时间查看精彩文章! 上一篇分享了两个使用的小工具:<如何同时输出调试信息到终端及文件?>.有位小伙伴留言问道tee工具的代码在哪: 这篇文章我们 ...

  7. [转] 用Diff和Patch工具维护源码

    在Unix系统下,维护源码版本可以使用很多方法,其中最常用的当然是大名鼎鼎的CVS,但实际上,简单的版本维护工作并没有必要使用复杂的CVS等专门的版本维护工具,Unix标配中的diff和patch工具 ...

  8. 玖云个人导航API工具网站源码

    介绍: 玖云个人导航API工具网站源码,简洁个人导航网站主页,附带几个可用的API接口,随机背景图,带简单后台. 源码安装方法: 上传源码,配置config.php文件 导入数据库install.sq ...

  9. 最新鲁班H5页面生成工具系统源码+功能强大/仿易企秀

    正文: 最新鲁班H5页面生成工具系统源码+功能强大/仿易企秀,这系统的功能真的非常强大,都是主流很高级的一些技术开发的. Vue2.0开发,通过拖拽的形式,生成页面的工具,类似易企秀.百度H5等工具. ...

最新文章

  1. 学Redis这篇就够了!
  2. Beta 冲刺(6/7)
  3. UA OPTI570 量子力学34 Harmonic Perturbation简介
  4. css3 线条出现动画效果,CSS3实现的线条波浪动画效果
  5. ITK:遍历图像的线
  6. 【Qt】数据库实战(三)
  7. mysql自定义函数多参数_自定义mysql函数 - 无法传递参数
  8. Git同时使用不同平台代码仓库
  9. springmvc+swagger2
  10. 《C++ Primer》第五版课后习题解答_第二章(1)(01-08)
  11. python写背单词软件_python实现屏保程序(适用于背单词)
  12. struts2自定义标签_Struts 2 –没有为动作和结果输入定义结果
  13. 【C++】std::是什么?
  14. 局域网计算机加密共享文件,局域网共享文件,小编教你局域网共享文件怎么加密...
  15. 向上的箭头 html,HTML中利用div+CSS实现简单的箭头图标
  16. Android:一篇就够!全面详细解析APN(涉及内容:GGSN,authtype,MVNO,pdp,Apns-conf,supl,hipri,dun)
  17. 新员工碰到新问题 公司论坛帮解决
  18. tomcat重启警告:Abandoned connection cleanup thread)
  19. 实测几款常见的DNS,看防护能力怎么样?
  20. 微信公众号 开发详解02【自动回复、发布文章、自定义菜单、3种链接跳转】

热门文章

  1. 扩展名为xls的html文件,htm是什么格式-后缀名为.htm的文件是什么文件
  2. 基于java的电影院在线票务管理系统的设计与实现 毕业设计毕设参考
  3. atomic 内存序_如何理解 C++11 的六种 memory order?
  4. ProE 工程图教程系列-1. 零件的质量属性自动计算
  5. Jama包的矩阵操作
  6. 高新技术企业3年认定期满怎么办
  7. 推荐五个非常实用的软件---(编辑器和日常)
  8. 江西初中生学计算机,江西中专学校初中毕业学计算机专业好吗
  9. 招募法师盗贼开箱游戏java,法师和盗贼经常用的宏
  10. 官方最新版teamview15.5.3.exe