动态函数OnDynamicFrame绘制cel单元,cel始终无法显示!急!

动态函数OnDynamicFrame绘制cel单元,cel始终无法显示。但是,将单元换成一段直线可在指定位置动态显示,就是如果调用cel单元库里面的模型,该CEL显示不出来

动态函数OnDynamicFrame

 /// <summary>
        /// 实现onDynamicFramce函数(动态绘制)
        /// </summary>
        /// <param name="ev"></param>
        protected override void OnDynamicFrame(DgnButtonEvent ev)//
        {
            
            DVector3d vecT = outPnt - m_onPnt;
            Angle ang = m_onVec.AngleToXY(vecT);
            DVector3d equVec;
            if (ang.Radians > 0)
            {
                equVec = m_onVec.RotateXY(Angle.FromRadians(Math.PI / 2));
            }
            else
            {
                equVec = m_onVec.RotateXY(Angle.FromRadians(-Math.PI / 2));
            }

            equVec.TryNormalize(out equVec);
            DPoint3d equPnt = m_onPnt + equVec * 5 * 10000;//距离中心线5米,
            DgnModel model = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();
            DgnFile dgnFile = Session.Instance.GetActiveDgnFile();
            String cellName = _form.CellTypeSelected;//如ZDJ9//用于动态绘制
            var pcDef = ParametricCellDefinitionElement.FindByName(cellName, dgnFile);
            ParametricCellElement pc = ParametricCellElement.Create(pcDef, null, model);
            
            // pc.Origin = insertPt;
            pc.Origin = equPnt;
            RedrawElems redrawElems = new RedrawElems();
            redrawElems.DrawMode = DgnDrawMode.TempDraw;
            redrawElems.DrawPurpose = DrawPurpose.Dynamics;
            redrawElems.SetViewport(ev.Viewport);
            redrawElems.SetDynamicsViewsFromActiveViewSet(ev.Viewport);
            redrawElems.DoRedraw(pc);

            //pc.AddToModel();
        }

按键操作中调用动态绘制

//按键操作中调用动态绘制
protected override bool OnDataButton(DgnButtonEvent ev)
        {
            Bentley.DgnPlatformNET.HitPath hitPath = DoLocate(ev, true, 1);
            if (hitPath == null)
                return false;

            Element el = hitPath.GetCursorElement();
            if (el == null)
                return false;
            CurveVector curvec = CurvePathQuery.ElementToCurveVector(el);//侧线
            DTransform3d transf3d = new DTransform3d(ev.Viewport.GetRotation());
            DMatrix4d mat4d = DMatrix4d.From(transf3d);
            CurveLocationDetail loc = curvec.ClosestPointBoundedXY(ev.RawPoint, mat4d);

            m_onPnt = loc.Point;//侧线上的最近点

            curvec.GetAt((int)loc.ComponentIndex).FractionToPoint(loc.ComponentFraction, out m_onPnt, out m_onVec);
			
#if VERSION_NEW
            ConsensusConnection con = new ConsensusConnection(el.DgnModelRef);
            Alignment al = (el.ParentElement == null) ? Alignment.CreateFromElement(con, el) : Alignment.CreateFromElement(con, el.ParentElement);
#else
            Alignment al = (el.ParentElement == null) ? Alignment.CreateFromElement(el) : Alignment.CreateFromElement(el.ParentElement);
#endif

            if (al == null)
                return false;

            if (_form.SelectType == "selectLine")
            {
                if (m_toolState == 0)
                {
                    m_aligment = al;
                    _form.SecondAlignment = al;
                    if (threeDModel == null)
                    {
                        if (m_aligment.ActiveLinearEntity3d != null)
                        {
                            threeDModel = m_aligment.ActiveLinearEntity3d.Element.DgnModel;
                        }
                    }
                    _form.Visible = false;
                    _form.TopMost = false;

                    BeginDynamics();//启动动态绘制函数
                    m_toolState = 1;
                    return true;
                }
                else
                {
                    _form.addDeviceByTwoLine();
                    ExitTool();
                    return true;
                }
            }

Parents
  • 研究了很久,始终无法动态绘制CEL,不知道是不是ORD本身不支持在2D动态绘制? 但是,我们之前开发的放置程序却是在2D中放置,切换到3D后可以看到三维模型

  • 这个代码里的CELL元素的移动需要通过变换矩阵来实现,直接设置原点无法让元素移动到指定的位置,移动代码如下:

    private bool TransformElement(ParametricCellElement CellElement, DgnButtonEvent ev)
            {
                DTransform3d transform;
                
    
                transform = DTransform3d.Identity;
    
                if (null == CellElement)
                    return false;
    
                DPoint3d currentPoint = ev.Point;
    
                transform.Translation = currentPoint;
                TransformInfo transformInfo = new TransformInfo(transform);
    
                CellElement.ApplyTransform(transformInfo);
                return true;
            }

    更多的方法可以参考MS的SDK的安装目录下的C:\Program Files\Bentley\MicroStationCONNECTSDK\examples\Elements\ManagedParametricCellPlacementExample  这个例子

    MISSING RESOURCE: VerifiedBy BIM@Railway 

Reply
  • 这个代码里的CELL元素的移动需要通过变换矩阵来实现,直接设置原点无法让元素移动到指定的位置,移动代码如下:

    private bool TransformElement(ParametricCellElement CellElement, DgnButtonEvent ev)
            {
                DTransform3d transform;
                
    
                transform = DTransform3d.Identity;
    
                if (null == CellElement)
                    return false;
    
                DPoint3d currentPoint = ev.Point;
    
                transform.Translation = currentPoint;
                TransformInfo transformInfo = new TransformInfo(transform);
    
                CellElement.ApplyTransform(transformInfo);
                return true;
            }

    更多的方法可以参考MS的SDK的安装目录下的C:\Program Files\Bentley\MicroStationCONNECTSDK\examples\Elements\ManagedParametricCellPlacementExample  这个例子

    MISSING RESOURCE: VerifiedBy BIM@Railway 

Children
No Data