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;
    }

  • 相关阅读:
    HTML5 学习04—— MathML数学标记
    HTML5 学习03——内联 SVG
    HTML5 学习02——新元素:canvas
    HTML5 学习01——浏览器问题、新元素
    HTML 回顾整理
    jQuery 学习05——AJAX:定义、load()方法、get()/post()方法
    jQuery 学习04——遍历:定义、向上、向下、同级、过滤
    jQuery 学习03——HTML:捕获、设置、添加元素、删除元素、CSS类、CSS()方法、尺寸
    UIDatePicker
    UIPikerView的属性
  • 原文地址:https://www.cnblogs.com/mjgw/p/12392686.html
Copyright © 2011-2022 走看看