【ORD C++】XAttribute问题

My_elementRef 是当前model中选中的参考文件的元素,写XAttribute失败了,返回值是-105。但是如果将参考文件合并到主文件,就会写入成功。请问是什么原因呢?

ElementRefP My_elementRef = mdlDisplayPath_getElem(path, mdlDisplayPath_getCursorIndex((DisplayPathP)path));
ElementID elID = My_elementRef->GetElementId();
EditElementHandle eeh(elID, ACTIVEMODEL); //添加attribute的元素
...
...
...
XAttributeHandlerId xAttHandlerId(234, 567);

UInt32 xAttId = 101;

XAttributeHandle xAttHandle(eeh.GetElementRef(), xAttHandlerId, xAttId);
StatusInt iRet = -1;
if (xAttHandle.m_node.m_xattr == NULL)
{
//直接存
iRet = ITxnManager::GetCurrentTxn().AddXAttribute(eeh.GetElementRef(), xAttHandlerId, xAttId, pdata, size);
// eeh.ScheduleWriteXAttribute(xAttHandlerId, xAttId, size, pdata);
}

Parents Reply Children
  • 我改成参考文件的model指针也不行啊。返回值-108

  • 您给我发下您的模型,或者发我邮箱xiaoqi.zhang@bentley.com

  • 何为“参考”?就是只能查看不能修改。何为Active?当前。所以,各种Active都只能对当前文件起作用,不能对参考文件起作用。

    要想修改参考文件可以考虑将参考文件打开成当前文件再行修改。

  • 好的,我试试,我打开参考文件进行修改再刷新一下。

  • WString filepath = elRef->GetDgnModelP()->GetDgnFileP()->GetDocumentPtr()->GetFileName();
    DgnDocumentPtr pDgnDoc = DgnDocument::CreateForLocalFile(filepath.GetWCharCP());
    DgnFilePtr file = DgnFile::Create(*pDgnDoc, DgnFileOpenMode::ReadWrite);
    StatusInt openForWriteStatus;
    file->LoadDgnFile(&openForWriteStatus);
    if (!file->IsOpen())
    {
    mdlDialog_dmsgsPrint(L"The file can't be written");
    delete[] pdata;
    return;
    }
    
    DgnModelRefP dgnModel = NULL;
    ModelId modelid = file->GetDefaultModelId();
    file->FillSectionsInModel(file->LoadRootModelById(NULL, modelid, true, true, true));
    mdlModelRef_createWorking(&dgnModel, file.get(), modelid, true, true);
    
    EditElementHandle eeh;
    LineHandler::CreateLineElement(eeh, NULL, DSegment3d::From(DPoint3d::From(0, 0, 0), DPoint3d::From(1000000, 0, 0)), true, *dgnModel);
    eeh.AddToModel();
    EditElementHandle eeh1(elRef->GetElementId(), dgnModel); //添加attribute的元素
    eeh1.GetElementDescrP();
    //存储的key值
    XAttributeHandlerId xAttHandlerId(234, 567);
    UInt32 xAttId = 101;
    XAttributeHandle xAttHandle(elRef, xAttHandlerId, xAttId);
    StatusInt iRet = -1;
    if (xAttHandle.m_node.m_xattr == NULL)
    {
    //直接存
    iRet = ITxnManager::GetCurrentTxn().AddXAttribute(elRef, xAttHandlerId, xAttId, pdata, size);
    }
    else
    {
    //删除再存
    ITxnManager::GetCurrentTxn().DeleteXAttribute(xAttHandle);
    ITxnManager::GetCurrentTxn().AddXAttribute(elRef, xAttHandlerId, xAttId, pdata, size);
    // eeh1.ScheduleDeleteXAttribute(xAttHandlerId, xAttId);
    // eeh1.ScheduleWriteXAttribute(xAttHandlerId, xAttId, size, pdata);
    }
    mdlModelRef_freeWorking(dgnModel);
    file->ProcessChanges(DgnSaveReason::FileClose);
    
    
    
    

    我打开参考文件进行修改也写不成功,我画条线也没有画成功,麻烦帮我看下这段代码哪里有问题吗?

    iRet = -108