天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 42|回复: 0

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

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]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;
}[/code]

 

 

 

 

CAD ObjectARX扩展工具的源码(一)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 11:27 , Processed in 0.156220 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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