天气与日历 切换到窄版

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

OBJECT ARX 操作图层

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]//添加图层
static void TESTaddlayercmd(){

CString strLayerName;
if(acedGetString(Adesk::kFalse,_T("\n输入层名称"),strLayerName.GetBuffer()) != RTNORM){
return;
}


获得当前图形的层表
AcDbLayerTable* pLayerTbl;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForWrite);


是否已经包含制定的层表记录
if(pLayerTbl->has(strLayerName)){
pLayerTbl->close();
return;
}


创建新的层表记录
AcDbLayerTableRecord* pLayerTblRcd;
pLayerTblRcd = new AcDbLayerTableRecord();
pLayerTblRcd->setName(strLayerName);

将新创建的层表记录添加到层表中
AcDbObjectId layerTblRcdId;
pLayerTbl->add(layerTblRcdId,pLayerTblRcd);
acdbHostApplicationServices()->workingDatabase()->setClayer(layerTblRcdId);
pLayerTblRcd->close();
pLayerTbl->close();


}




//修改图层颜色============================


static void TESTlayercolorcmd(){
CString strLayerName;
if(acedGetString(Adesk::kFalse,_T("\n输入图层的名称:"),strLayerName.GetBuffer()) != RTNORM){
return;
}
获得当前的图层列表
AcDbLayerTable* pLayerTbl;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
判断是否包含指定名称的层表记录
if(!pLayerTbl->has(strLayerName)){
pLayerTbl->close();
return;
}


获得制定层表记录的指针
AcDbLayerTableRecord* pLayerTblRcd;
pLayerTbl->getAt(strLayerName,pLayerTblRcd,AcDb::kForWrite);


弹出颜色对话框
AcCmColor oldColor = pLayerTblRcd->color();
int nCurColor = oldColor.colorIndex();//旧的颜色
int nNewColor = oldColor.colorIndex();//用户选择的颜色
if(acedSetColorDialog(nNewColor,Adesk::kFalse,nCurColor)){

AcCmColor color;
color.setColorIndex(nNewColor);
pLayerTblRcd->setColor(color);
}
pLayerTblRcd->close();
pLayerTbl->close();




}


//删除图层
static void TESTdellayercmd(){
CString strLayerName;
if(acedGetString(Adesk::kFalse,_T("\n输入图层名称"),strLayerName.GetBuffer()) != RTNORM){
return;
}


获得当前的图层列表
AcDbLayerTable* pLayerTbl;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
判断是否包含指定名称的层表记录
if(!pLayerTbl->has(strLayerName)){
pLayerTbl->close();
return;
}
获得制定层表记录的指针
AcDbLayerTableRecord* pLayerTblRcd;
pLayerTbl->getAt(strLayerName,pLayerTblRcd,AcDb::kForWrite);
pLayerTblRcd->erase();


pLayerTblRcd->close();
pLayerTbl->close();







}


导出层的信息到文本文件中
static void TESTexportlayercmd(){
//创建要导出的文本文件
CStdioFile f;
CFileException e;
CString pFileName;
pFileName = _T("D:\\layer.txt");
if(!f.Open(pFileName.GetString(),CFile::modeCreate|CFile::modeWrite,&e)){
acutPrintf(_T("\n创建文件失败"));
return;
}


获得层表指针
AcDbLayerTable *pLayerTbl;
AcDbLayerTableRecord* pLayerTblRcd;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
使用遍历器访问每条层表记录
AcDbLayerTableIterator* pItr;
pLayerTbl->newIterator(pItr);
for(pItr->start();!pItr->done();pItr->step()){
pItr->getRecord(pLayerTblRcd,AcDb::kForRead);
输出图层的信息
CString strLayerInfo;
TCHAR* layerName;
pLayerTblRcd->getName(layerName);

名称
strLayerInfo = layerName;
free(layerName);
strLayerInfo.Append(_T(","));

CString strColor;
AcCmColor color = pLayerTblRcd->color();
strColor.Format(_T("%d"),color.colorIndex());
strLayerInfo.Append(strColor);
线型
CString strLineType;
AcDbLinetypeTableRecord* pLinetypeTblRcd;
acdbOpenObject(pLinetypeTblRcd,pLayerTblRcd->linetypeObjectId(),AcDb::kForRead);
TCHAR* linetypeName;
pLinetypeTblRcd->getName(linetypeName);
pLinetypeTblRcd->close();
strLineType = linetypeName;
free(linetypeName);


strLayerInfo.Append(strLineType);
strLayerInfo.Append(_T(","));


线宽
CString strLineWeight;
AcDb::LineWeight lineWeight = pLayerTblRcd->lineWeight();
strLineWeight.Format(_T("%d"),lineWeight);
strLayerInfo.Append(strLineWeight);


/写文件
f.WriteString(strLayerInfo);
f.WriteString(_T("\n"));
pLayerTblRcd->close();




}


delete pItr;
pLayerTbl->close();


}
[/code]

 

 

 

 

OBJECT ARX 操作图层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-1 15:26 , Processed in 0.150338 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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