TA的每日心情 | 开心 昨天 06:36 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
管理员
- 积分
- 1308
|
楼主 |
发表于 2024-5-4 19:16:52
|
显示全部楼层
- //从文本文档到导入图层
- void CModifyLayer::ImportLayer()
- {
- // 打开所要导入的文本文件
- CStdioFile f;
- CFileException e;
- TCHAR *pFileName = 采用T("C:\\layers.txt");
- if (!f.Open(pFileName, CFile::modeRead, &e))
- {
- acutPrintf(采用T("\n打开导入文件失败!"));
- return;
- }
-
- // 获得层表指针
- AcDbLayerTable *pLayerTbl;
- AcDbLayerTableRecord *pLayerTblRcd;
- acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl, AcDb::kForWrite);
- // 读取文件中的每一行数据
- CString strLineText; // 一行文字
- while (f.ReadString(strLineText))
- {
- // 跳过空行
- if (strLineText.IsEmpty())
- continue;
- // 解析出图层名称、颜色、线型和线宽
- CStringArray layerInfos;
- if (!GetFieldText(strLineText, layerInfos))
- continue;
-
- // 创建新的层表记录,或者打开存在的块表记录
- AcDbLayerTableRecord *pLayerTblRcd;
- AcDbObjectId layerTblRcdId;
- if (pLayerTbl->has(layerInfos.GetAt(0)))
- {
- pLayerTbl->getAt(layerInfos.GetAt(0), layerTblRcdId);
- }else
- {
- pLayerTblRcd = new AcDbLayerTableRecord();
- pLayerTblRcd->setName(layerInfos.GetAt(0));
- pLayerTbl->add(layerTblRcdId, pLayerTblRcd);
- pLayerTblRcd->close();
- }
-
- acdbOpenObject(pLayerTblRcd, layerTblRcdId, AcDb::kForWrite);
-
- // 设置层表记录的颜色
- AcCmColor color;
- Adesk::UInt16 colorIndex = 采用wtol(layerInfos.GetAt(1));
- color.setColorIndex(colorIndex);
- pLayerTblRcd->setColor(color);
-
- // 设置线型
- AcDbLinetypeTable *pLinetypeTbl;
- AcDbObjectId linetypeId;
- acdbHostApplicationServices()->workingDatabase()->getLinetypeTable(pLinetypeTbl, AcDb::kForRead);
- if (pLinetypeTbl->has(layerInfos.GetAt(2)))
- {
- pLinetypeTbl->getAt(layerInfos.GetAt(2), linetypeId);
- }else
- {
- pLinetypeTbl->getAt(采用T("Continous"), linetypeId);
- }
- pLayerTblRcd->setLinetypeObjectId(linetypeId);
- pLinetypeTbl->close();
-
- // 设置线宽
- AcDb::LineWeight lineWeight = (AcDb::LineWeight)采用wtol(layerInfos.GetAt(3));
- pLayerTblRcd->setLineWeight(lineWeight);
- pLayerTblRcd->close();
- }
-
- pLayerTbl->close();
- }
复制代码 |
|