码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-04-01 00:51:57      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:EDA   box   mac   string   cal   error   cad   sage   char   

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扩展工具的源码(一)

标签:EDA   box   mac   string   cal   error   cad   sage   char   

原文地址:https://www.cnblogs.com/mjgw/p/12609698.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!