【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
  • 参考文件是只读的,所以无法对参考文件进行写操作。

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

  • 下面代码可以对打开的dgn写元素,既然能写,属性肯定也可以的:

        WString strDgn("D:\\test.dgn");
        DgnDocumentPtr pDgnDoc = DgnDocument::CreateForLocalFile(strDgn.GetWCharCP());
        DgnFilePtr pDgn = DgnFile::Create(*pDgnDoc, DgnFileOpenMode::ReadWrite);
        StatusInt  openForWriteStatus;
        pDgn->LoadDgnFile(&openForWriteStatus);
        if (!pDgn->IsOpen())
        {
            mdlDialog_dmsgsPrint(L"The file can't be written");
            return false;
        }
        pDgn->FillDictionaryModel();
    
        DgnModelPtr pModel = pDgn->LoadModelById(pDgn->GetDefaultModelId());
        pDgn->FillSectionsInModel(pModel.get());
    
        DSegment3d segment = DSegment3d::From(0, 0, 0, 0, 0, 10000);
        EditElementHandle eeh;
        LineHandler::CreateLineElement(eeh, nullptr, segment, true, *pModel);
        eeh.AddToModel();
    
        pDgn->ProcessChanges(DgnSaveReason::FileClose);

  • 给您完整的代码吧 :

        WString strDgn("D:\\test.dgn");
        DgnDocumentPtr pDgnDoc = DgnDocument::CreateForLocalFile(strDgn.GetWCharCP());
        DgnFilePtr pDgn = DgnFile::Create(*pDgnDoc, DgnFileOpenMode::ReadWrite);
        StatusInt  openForWriteStatus;
        pDgn->LoadDgnFile(&openForWriteStatus);
        if (!pDgn->IsOpen())
        {
            mdlDialog_dmsgsPrint(L"The file can't be written");
            return false;
        }
        pDgn->FillDictionaryModel();
    
        DgnModelPtr pModel = pDgn->LoadModelById(pDgn->GetDefaultModelId());
        pDgn->FillSectionsInModel(pModel.get());
    
        DSegment3d segment = DSegment3d::From(0, 0, 0, 0, 0, 10000);
        EditElementHandle eeh;
        LineHandler::CreateLineElement(eeh, nullptr, segment, true, *pModel);
        eeh.AddToModel();
    
        char *appData = "My XAttribute Data";
        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, appData, 30);
        }
        else
        {
            //删除再存
            ITxnManager::GetCurrentTxn().DeleteXAttribute(xAttHandle);
            ITxnManager::GetCurrentTxn().AddXAttribute(eeh.GetElementRef(), xAttHandlerId, xAttId, appData, 30);
            // eeh1.ScheduleDeleteXAttribute(xAttHandlerId, xAttId);
            // eeh1.ScheduleWriteXAttribute(xAttHandlerId, xAttId, size, pdata);
        }
        //mdlModelRef_freeWorking(dgnModel);
        pDgn->ProcessChanges(DgnSaveReason::FileClose);

  • 我这还是不行,我看了一下被参考的文件,发现被参考的文件是一个2Dmodel,然后该model又参考了该dgn的3Dmodel.如下图所示,而我用的defaultModel,所以该Dgn还是只读的,现在我改成了3Dmodel指针,该线画出来了,但是属性没写成功还是返回-108。

    加载model时我改成了这样

    DgnModelPtr pModel = file->LoadModelById(elRef->GetDgnModelP()->GetModelId());//加载鼠标所选的参考文件的元素所在的model

    线画出来了(红色框内),DSegment3d segment = DSegment3d::From(0, 0, 0, 1000000, 0, 0);坐标改了, 要不会是一个点。

    但是iRet = ITxnManager::GetCurrentTxn().AddXAttribute(elRef, xAttHandlerId, xAttId, pdata, size)还是返回-108.

  • 你把你的模型上传一下,我这边试试。

Reply Children