C#.NET 参考文件View如何选择

从论坛上找到这段代码:

DgnDocumentMoniker moniker = DgnDocumentMoniker.CreateFromFileName(@"H:\XX\XXX\Model.dgn", null);
DgnAttachment att = dgnModel.CreateDgnAttachment(moniker, "2D Metric Design");
if (att != null)
{
att.NestDepth = 99;
att.SetMasterOrigin(setPoint);
att.WriteToModel(true);
}


这段代码用来添加参考文件,如果我想参考文件中已有的view里边的Named Boundaries的视图该如何改写呢?

Parents
  • 试试这段代码,NavedView就是界面中的SavedView

    if ( !string.IsNullOrEmpty(applyNamedView) )
                    {
                    ModelId fromModelId = fromDgnFile.FindModelIdByName(fromModelName);
                    DgnModel fromModel = fromDgnFile.LoadRootModelById(out status, fromModelId, true, true, true);
                    //应用SavedView
                    status = ref1.ApplyNamedView(applyNamedView, 1, 1, new ApplyViewClipOptions(), true, StandardView.Top);
    
                    //设置参考坐标与源模型相同
                    NamedViewCollection nvc = fromModel.GetDgnFile().GetNamedViews();
                    NamedView nv = nvc.FindByName(applyNamedView, false);
                    ViewInformation viewInfo = nv.GetViewInfo();
                    DPoint3d dpOff = new DPoint3d(viewInfo.Delta.X / 2.0, viewInfo.Delta.Y / 2.0, 0);
                    ref1.SetMasterOrigin(viewInfo.Origin + dpOff);
                    } 
     
    

    Answer Verified By: F T 

Reply
  • 试试这段代码,NavedView就是界面中的SavedView

    if ( !string.IsNullOrEmpty(applyNamedView) )
                    {
                    ModelId fromModelId = fromDgnFile.FindModelIdByName(fromModelName);
                    DgnModel fromModel = fromDgnFile.LoadRootModelById(out status, fromModelId, true, true, true);
                    //应用SavedView
                    status = ref1.ApplyNamedView(applyNamedView, 1, 1, new ApplyViewClipOptions(), true, StandardView.Top);
    
                    //设置参考坐标与源模型相同
                    NamedViewCollection nvc = fromModel.GetDgnFile().GetNamedViews();
                    NamedView nv = nvc.FindByName(applyNamedView, false);
                    ViewInformation viewInfo = nv.GetViewInfo();
                    DPoint3d dpOff = new DPoint3d(viewInfo.Delta.X / 2.0, viewInfo.Delta.Y / 2.0, 0);
                    ref1.SetMasterOrigin(viewInfo.Origin + dpOff);
                    } 
     
    

    Answer Verified By: F T 

Children