天气与日历 切换到窄版

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

ObjectARX 智能指针

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]AcDbObjectPointer
class  AcDbObjectPointer;
typedef  AcDbObjectPointer<AcDbDictionary>  AcDbDictionaryPointer;
typedef  AcDbObjectPointer<AcDbEntity>      AcDbEntityPointer;
AcDbSymbolTablePointer
typedef AcDbSymbolTablePointer<AcDbBlockTable>     AcDbBlockTablePointer;
typedef AcDbSymbolTablePointer<AcDbDimStyleTable>  AcDbDimStyleTablePointer;
typedef AcDbSymbolTablePointer<AcDbLayerTable>     AcDbLayerTablePointer;
typedef AcDbSymbolTablePointer<AcDbLinetypeTable>  AcDbLinetypeTablePointer;
typedef AcDbSymbolTablePointer<AcDbRegAppTable>    AcDbRegAppTablePointer;
typedef AcDbSymbolTablePointer<AcDbTextStyleTable> AcDbTextStyleTablePointer;
typedef AcDbSymbolTablePointer<AcDbUCSTable>       AcDbUCSTablePointer;
typedef AcDbSymbolTablePointer<AcDbViewTable>      AcDbViewTablePointer;
typedef AcDbSymbolTablePointer<AcDbViewportTable>  AcDbViewportTablePointer;
AcDbSymbolTableRecordPointer
typedef AcDbSymbolTableRecordPointer<AcDbBlockTableRecord>
                                     AcDbBlockTableRecordPointer;
typedef AcDbSymbolTableRecordPointer<AcDbDimStyleTableRecord>
                                     AcDbDimStyleTableRecordPointer;
typedef AcDbSymbolTableRecordPointer<AcDbLayerTableRecord>
                                     AcDbLayerTableRecordPointer;
typedef AcDbSymbolTableRecordPointer<AcDbLinetypeTableRecord>
                                     AcDbLinetypeTableRecordPointer;
typedef AcDbSymbolTableRecordPointer<AcDbRegAppTableRecord>
                                     AcDbRegAppTableRecordPointer;
typedef AcDbSymbolTableRecordPointer<AcDbTextStyleTableRecord>
                                     AcDbTextStyleTableRecordPointer;
typedef AcDbSymbolTableRecordPointer<AcDbUCSTableRecord>
                                     AcDbUCSTableRecordPointer;
typedef AcDbSymbolTableRecordPointer<AcDbViewTableRecord>
                                     AcDbViewTableRecordPointer;
typedef AcDbSymbolTableRecordPointer<AcDbViewportTableRecord>
                                     AcDbViewportTableRecordPointer;

例子

AcDbBlockTableRecordPointer curSpace(
    curDoc()->database()->currentSpaceId(),
    AcDb::kForWrite);
if (curSpace.openStatus() == Acad::eOk)
{
    ...
}

AcDbObjectPointer<AcDbLine> line;
line.create();
line->setStartPoint(AcGePoint3d(0, 0, 0));
line->setEndPoint(AcGePoint3d(10, 10, 0));

AcDbBlockTableRecordPointer curSpace(
    acDocManager->curDocument()->database()->currentSpaceId(),
    AcDb::kForWrite);
if (curSpace.openStatus() == Acad::eOk)
{
    curSpace->appendAcDbEntity(line);
}

//这个例子在AcDbEntity添加扩展字典数据,使用AcDbEntityPointer 、AcDbDictionaryPointer 、AcDbObjectPointer<AcDbXrecord> 这些类实例销毁时,自动关闭Arx实体/对象,且不用担心中间代码抛出异常。
bool SetEntityDictFromRbChain(AcDbObjectId entId,ACHAR *strDictName,resbuf* pRbValue)
{

    AcDbEntityPointer pObj(entId,AcDb::kForWrite);
    if (pObj.openStatus()!=Acad::eOk ) return false;
    AcDbObjectId extDictId = pObj->extensionDictionary();
    if (extDictId == AcDbObjectId::kNull)
    {
        Acad::ErrorStatus es = pObj->createExtensionDictionary();
        if (es != Acad::eOk)   return false;

        if ((extDictId = pObj->extensionDictionary()) == AcDbObjectId::kNull)
            return false;
    }
    AcDbDictionaryPointer pDict(extDictId,AcDb::kForRead);
    if(pDict.openStatus() != Acad::eOk)
        return false;
    AcDbObjectId xRecId;
    if(pDict->getAt(strDictName,xRecId) != Acad::eOk)
    {
        AcDbXrecord* pXrec = new AcDbXrecord();
        //pXrec 可以使用scoped_ptr
        pDict->upgradeOpen();
        if(pDict->setAt(strDictName,pXrec,xRecId) != Acad::eOk)
        {
            delete pXrec;
            return false;
        }
        pXrec->close();
    }

    AcDbObjectPointer<AcDbXrecord> pXrcord(xRecId,AcDb::kForWrite);
    if(pXrcord.openStatus() != Acad::eOk) return false;

    if(pXrcord->setFromRbChain(*pRbValue) != Acad::eOk) return false;
    acutRelRb(pRbValue);
    return true;
}[/code]

 

 

 

 

ObjectARX 智能指针
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-1 11:33 , Processed in 0.127973 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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