[C# MSCE]读取未打开dgn中元素的材质

符老师    我想读取未打开dgn中元素的材质  结果得不到   代码如下:

 string file = @"C:\Users\Administrator\Desktop\测试图片.dgn";
            DgnDocument dgnDoc = DgnDocument.CreateForLocalFile(file);
            DgnFileOwner m_dgnFileOwner = DgnFile.Create(dgnDoc, DgnFileOpenMode.ReadWrite);
            DgnFile m_dgnFile = m_dgnFileOwner.DgnFile;
            StatusInt openForReadStatus;
            Bentley.DgnPlatformNET.DgnFileStatus status;
            if (DgnFileStatus.Success != (status = m_dgnFile.LoadDgnFile(out openForReadStatus)))
            {
                System.Windows.Forms.MessageBox.Show(status.ToString());
                return StatusInt.Error;
            }
            foreach (Bentley.DgnPlatformNET.ModelIndex index in m_dgnFile.GetModelIndexCollection())
            {
                ModelId ModelId = m_dgnFile.FindModelIdByName(index.Name);
                Bentley.DgnPlatformNET.StatusInt errorDetails;
                DgnModel model = m_dgnFile.LoadRootModelById(out errorDetails, ModelId, true, true, true);
                List<Bentley.DgnPlatformNET.Elements.Element> elemList = model.GetGraphicElements().ToList();
                foreach (Element el in elemList)
                {
                    if(el.ElementId== 73732)
                    {
                        MaterialSearchStatus searchStatus;
                        Material mat = MaterialManager.FindMaterialAttachment(out searchStatus, el, el.DgnModel, true);
                        if (searchStatus != MaterialSearchStatus.Success)
                        {
                            System.Windows.Forms.MessageBox.Show("失败");
                        }
                    }
                }
            }
            m_dgnFile.ProcessChanges(DgnSaveReason.FileClose);
            m_dgnFile.Release();

4403.测试图片.dgn

求伟大的符老师指导。

Parents Reply Children