天气与日历 切换到窄版

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

ObjectARX扩展工具的源码(一)

[复制链接]
  • TA的每日心情
    开心
    昨天 15:23
  • 签到天数: 69 天

    [LV.6]常住居民II

    410

    主题

    167

    回帖

    2704

    积分

    管理员

    积分
    2704
    发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
    [code]Acad::ErrorStatus CDrawFunction::getAllEntity(AcDbDatabase *pDb,AcDbObjectIdArray& IdArr,
    const AcArray& layerNameArr)
    {undefined
    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)//打开块表
    {undefined
    acedAlert("打开块表失败");
    return es;
    }
    AcDbBlockTableRecord *pBlkTableRecord=NULL;
    if((es=pBlkTable->getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb::kForRead))!=Acad::eOk)//打开块表记录
    {undefined
    acedAlert("打开块表记录失败");
    pBlkTable->close();
    return es;
    }
    pBlkTable->close();//关闭块表

    AcDbBlockTableRecordIterator *pIterator=NULL; //创建叠代器
    if((es=pBlkTableRecord->newIterator(pIterator))!=Acad::eOk)
    {undefined
    pBlkTableRecord->close();
    return es;
    }

    CAcModuleResourceOerride resoerride;
    CProgressDlg progress;
    progress.Create();
    progress.SetPos(0);
    progress.SetWindowText("正在检测图形中所有实体...");

    for(pIterator->start();!pIterator->done();pIterator->step())//遍历整个数据库
    {undefined
    AcDbEntity *entity=NULL;
    es=pIterator->getEntity(entity,AcDb::kForRead); //打开实体

    if(es==Acad::eLockiolation)
    {undefined
    acedAlert("内存锁定");
    }
    else if(es==Acad::eWasOpenForWrite)
    {undefined
    acedAlert("实体以写方式打开");
    }
    else if(es==Acad::eWasOpenForRead)
    {undefined
    acedAlert("实体以读方式打开");
    }
    else
    {undefined
    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)
    {undefined
    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)//打开块表
    {undefined
    acedAlert("打开块表失败");
    return es;
    }
    AcDbBlockTableRecord *pBlkTableRecord=NULL;
    if((es=pBlkTable->getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb::kForRead))!=Acad::eOk)//打开块表记录
    {undefined
    acedAlert("打开块表记录失败");
    pBlkTable->close();
    return es;
    }
    pBlkTable->close();//关闭块表

    AcDbBlockTableRecordIterator *pIterator=NULL; //创建叠代器
    if((es=pBlkTableRecord->newIterator(pIterator))!=Acad::eOk)
    {undefined
    pBlkTableRecord->close();
    return es;
    }

    CAcModuleResourceOerride resoerride;
    CProgressDlg progress;
    progress.Create();
    progress.SetPos(0);
    progress.SetWindowText("正在检测图形中所有实体...");

    for(pIterator->start();!pIterator->done();pIterator->step())//遍历整个数据库
    {undefined
    AcDbEntity *entity=NULL;
    if((es=pIterator->getEntity(entity,AcDb::kForRead))!=Acad::eOk)//打开实体
    {undefined
    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)
    {undefined
    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)
    {undefined
    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++)
    {undefined
    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)
    {undefined
    //----查找安装目录----//
    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)
    {undefined
    pLinetypeTable->close();
    Acad::ErrorStatus error;

    error=acdbLoadLineTypeFile(str,File.GetBuffer(0),acdbHostApplicationSerices()->workingDatabase());
    if(error==Acad::eNullObjectPointer)
    {undefined
    AcDbLinetypeTable *pLinetypeTable;
    acdbHostApplicationSerices()->workingDatabase()->getSymbolTable(pLinetypeTable, AcDb::kForRead);
    pLinetypeTable->getAt("CONTINUOUS", id);
    pLinetypeTable->close();
    return FALSE;
    }
    else if(error==Acad::eFileSystemErr)
    {undefined
    AfxMessageBox("the specified file cannot be opened");
    return FALSE;
    }
    else if(error==Acad::eUndefinedLineType)
    {undefined
    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)
    {undefined
    //查找样式目录安装路径
    TCHAR AcadPath[255];
    HKEY hKey;
    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE//线路处开发组//RDS2002//1.00"),0,KEY_QUERY_ALUE,&hKey)!=ERROR_SUCCESS)
    {undefined
    ::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)
    {undefined
    acutPrintf("Read failed/n");
    return ;
    }
    //-----查找完毕--------//
    AcadInstallPath.Format("%s",AcadPath);
    }

    AcDbObjectId CDrawFunction::createTextStyle(CString fontName,CString bigFontName,CString textStyleName)
    {undefined
    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)
    {undefined
    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]

     

     

     

     

    ObjectARX扩展工具的源码(一)
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

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

    GMT+8, 2024-7-1 05:31 , Processed in 0.059758 second(s), 23 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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