zoukankan      html  css  js  c++  java
  • ObjectArx学习笔记-导入导出图层列表

    导出图层的实现:

    static void qxzyOperateLayer_ExportLayer(void)
    {
    CStdioFile f;
    CFileException e;
    char *pFileName = "C:\layers.txt";
    if(!f.Open((LPCTSTR)pFileName, CFile::modeCreate|CFile::modeWrite, &e))
    {
    acutPrintf(_T(" 创建导出文件失败!"));
    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;
    ACHAR *layerName;
    pLayerTblRcd->getName(layerName);
    strLayerInfo = layerName;
    free(layerName);
    strLayerInfo += ",";

    CString strColor;
    AcCmColor color = pLayerTblRcd->color();
    strColor.Format(_T("%d"), color.colorIndex());
    strLayerInfo += strColor;
    strLayerInfo += ",";

    CString strLinetype;
    AcDbLinetypeTableRecord *pLinetypeTblRcd;
    acdbOpenObject(pLinetypeTblRcd, pLayerTblRcd->linetypeObjectId(),
    AcDb::kForRead);
    ACHAR *linetypeName;
    pLinetypeTblRcd->getName(linetypeName);
    pLinetypeTblRcd->close();
    strLinetype = linetypeName;
    free(linetypeName);
    strLayerInfo += strLinetype;
    strLayerInfo += ",";

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

    f.WriteString(strLayerInfo);
    f.WriteString(_T(" "));

    pLayerTblRcd->close();
    }
    delete pItr;
    pLayerTbl->close();
    }

    导入图层的实现:
    static void qxzyOperateLayer_ImportLayer(void)
    {
    CStdioFile f;
    CFileException e;
    char *pFileName = "C:\layers.txt";
    if(!f.Open((LPCTSTR)pFileName, CFile::modeRead, &e))
    {
    acutPrintf(_T(" 打开导入文件失败!"));
    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 = atoi((LPSTR)(LPCTSTR)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)atoi((LPSTR)(LPCTSTR)layerInfos.GetAt(3));
    pLayerTblRcd->setLineWeight(lineWeight);
    pLayerTblRcd->close();
    }
    pLayerTbl->close();

    }

    获取字段的一个方法:
    static BOOL GetFieldText(CString strLineText, CStringArray &fields)
    {
    if(strLineText.Find(_T(","), 0) == -1)
    {
    return FALSE;
    }

    int nLeftPos = 0, nRightPos = 0;

    while((nRightPos = strLineText.Find(_T(","), nRightPos))!= -1)
    {
    fields.Add(strLineText.Mid(nLeftPos, nRightPos - nLeftPos));

    nLeftPos = nRightPos + 1;
    nRightPos ++;
    }

    fields.Add(strLineText.Mid(nLeftPos));

    return TRUE;
    }

  • 相关阅读:
    Webstorm常用快捷键
    微信内置浏览器是什么?(复制篇)
    jquery.cookie.js 操作cookie实现记住密码功能的实现代码
    sublime text 3 快捷键大全
    http_load的安装及使用方法
    Mysql压测工具mysqlslap 讲解
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    percona-toolkit工具包的使用教程之开发类工具
    MYSQL管理之主从同步管理
    percona-toolkit系列之介绍和安装(mysql复制工具)
  • 原文地址:https://www.cnblogs.com/mjgw/p/12392686.html
Copyright © 2011-2022 走看看