【MSCE C#】参考文件的offset值

各位老师好,请问通过Bentley.DgnPlatformNET.DgnAttachment有什么办法能获取到参考文件的Offset值吗?如下图所示

  • 符老师是这样的,我在参考的时候利用SetMasterOrigin设置了原点,但是后面利用GetMasterOrigin去获取之后发现都是(0,0,0),GetRefOrigin也是如此,然后打开参考的窗口发现这个Offset和实际参考的原点一致所以才想着获取这个Offset

  • 我在参考的时候利用SetMasterOrigin设置了原点,但是后面利用GetMasterOrigin去获取之后发现都是(0,0,0)

    SetMasterOrigin设置之后,要调用DgnAttachment的Rewrite才会将修改写回到文件里边。如果您已经调用了Rewrite,通过GetMasterOrigin还获取不到,请提供您的测试代码,测试代码最好是一个单独可编译运行并能复现问题现象的函数,不要引用其他全局变量。

  • //参考
    void attach()
    {
        String^ path = "C:\\test.dgn"; //test
        Bentley::DgnPlatformNET::DgnDocument^ doc = Bentley::DgnPlatformNET::DgnDocument::CreateForLocalFile(path);
        Bentley::DgnPlatformNET::StatusInt fileLoadStatus;
        Bentley::DgnPlatformNET::DgnFile^ dgnFile = Bentley::DgnPlatformNET::DgnFile::Create(doc, Bentley::DgnPlatformNET::DgnFileOpenMode::ReadOnly)->DgnFile;
        dgnFile->LoadDgnFile(fileLoadStatus);
        if (Bentley::DgnPlatformNET::StatusInt::Success != fileLoadStatus)
            return;
        Bentley::DgnPlatformNET::ModelId id = dgnFile->DefaultModelId;
        Bentley::DgnPlatformNET::DgnModel dgnModel = dgnFile->LoadRootModelById(fileLoadStatus, dgnFile->DefaultModelId);
        if (Bentley::DgnPlatformNET::StatusInt::Success != fileLoadStatus)
            return;
                
        Bentley::DgnPlatformNET::DgnModel^ activeDgnModel = Session::Instance->GetActiveDgnModel();
        Bentley::GeometryNET::DPoint3d location = Bentley::GeometryNET::DPoint3d::FromXY(10000, 10000); //test
        Bentley::DgnPlatformNET::DgnAttachment^ attachment = activeDgnModel->CreateDgnAttachment(dgnFile->GetDocument()->GetMoniker(), dgnModel->ModelName);
        attachment->SetMasterOrigin(location);
        //attachment->SetRefOrigin(location);
        attachment->SetLocateLock(true);
        attachment->SetSnapLock(true);
        attachment->Rewrite(true, true);
    }

    //参考信息
    void loadInfo()
    {
        Bentley::DgnPlatformNET::DgnModel^ dgnModel = Session::Instance->GetActiveDgnModel();
        Int64 idInt = 18657; //参考文件ID
        Bentley::DgnPlatformNET::ElementId attchmentID(idInt);    
        Bentley::DgnPlatformNET::DgnAttachment^ attachment = dgnModel->FindDgnAttachmentByElementId(attchmentID);
        Bentley::GeometryNET::DPoint3d location;
        if (attachment != nullptr)
        {
            attachment->GetMasterOrigin(location);
            //location = attachment->GetRefOrigin();
            printf("%f %f %f\n", location.X, location.Y, location.Z);
        }
    }

  • loadInfo函数里边FindDgnAttachmentByElementId获取到的DgnAttachment不是attach函数里边创建的吧。