ms迷您好,我想在ABD视图中,选中某个元素后,并对此元素进行居中显示,能否有C#或mdl方法实现元素居中操作呢?实在没有,keyin也行。
可以先获取到此元素的Range范围,然后调用mdlView_fitViewToRange使视图fit到指定的范围。下面是我写的一段代码,实现对0号视图以ElementID为10563的直线元素居中显示,您可以参考一下。
ElementID eleID = 10563; MSElement msEle; mdlAssoc_getElement(&msEle, NULL, eleID, ACTIVEMODEL); DPoint3d lowPt = msEle.line_3d.start; DPoint3d highPt = msEle.line_3d.end; RotMatrix rotMatrix; mdlRMatrix_fromView(&rotMatrix, 0, FALSE); mdlRMatrix_multiplyPoint(&lowPt, &rotMatrix); mdlRMatrix_multiplyPoint(&highPt, &rotMatrix); FitViewOptions fitViewOptions = { 0 }; if (mdlView_fitViewToRange(&lowPt, &highPt, &fitViewOptions, 0) == SUCCESS) { mdlView_updateSingle(0); mdlOutput_messageCenter(MESSAGE_INFO, "SUCCESS fit view", "SUCCESS fit view", 0); } else { mdlOutput_messageCenter(MESSAGE_INFO, "Fail fit view", "Fail fit view", 0); }
ChenYang Sun said:point1.X = p1.X * UorPerMas; point1.Y = p1.Y * UorPerMas; point1.Z = p1.Z * UorPerMas;
不要*UorPerMas,COM接口用的都是主单位
double UorPerMas = Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMaster;Point3d point1 = new Point3d();
point1.X = p1.X * UorPerMas;point1.Y = p1.Y * UorPerMas;point1.Z = p1.Z * UorPerMas;
这个之前忘删了,这段在函数中没用到,没影响
CalcElementRange返回的单位也是uor单位,view.SetArea接收的应该是主单位,需要转换一下的。
试了好几遍,和这个主单位没关系
不要调用view.Fit呀,Fit就会将整个模型中的图形充满当前视图。