Exemplo n.º 1
0
        public static double DPDistance(DPoint3d ptA, DPoint3d ptB)
        {
            double dx = Sqr((ptA.X - ptB.X));
            double dy = Sqr((ptA.Y - ptB.Y));
            double dz = Sqr((ptA.Z - ptB.Z));

            double dist = Math.Sqrt((dx + dy + dz));

            return dist;
        }
Exemplo n.º 2
0
        public static DPoint3d closestPointOnSurf(DPoint3d point, ISurface surf, double tol)
        {
            Bentley.Interop.MicroStationDGN.Point3d cpRef = new Bentley.Interop.MicroStationDGN.Point3d();
            cpRef.X = point.X;
            cpRef.Y = point.Y;
            cpRef.Z = point.Z;

            Bentley.Interop.MicroStationDGN.Point3d cp = new Bentley.Interop.MicroStationDGN.Point3d();
            Bentley.Interop.MicroStationDGN.Point2d cp2d = new Bentley.Interop.MicroStationDGN.Point2d();

            GeometryTools.BSplineSurfaceComputeMinimumDistance(ref cp, ref cp2d, ref cpRef, tol, surf.com_bsplineSurface);

            return new DPoint3d(cp.X, cp.Y, cp.Z);
        }
Exemplo n.º 3
0
        public static int[] GetConnectedPointID(Mesh m, DPoint3d centerPoint)
        {
            int ptid = -1;
            for (int i = 0; i < m.Vertices.Length; i++)
            {
                if (m.Vertices[i].X == centerPoint.X && m.Vertices[i].Y == centerPoint.Y && m.Vertices[i].Z == centerPoint.Z)
                {
                    ptid = i;
                    break;
                }

            }

            return GetConnectedPointID(m, ptid);
        }
Exemplo n.º 4
0
        public static DPoint3d closestPointOnSurf(DPoint3d point, ISurface surf, double tol, out double Dist, out Point2d UV, out DVector3d normal)
        {
            Bentley.Interop.MicroStationDGN.Point3d cpRef = new Bentley.Interop.MicroStationDGN.Point3d();
            cpRef.X = point.X;
            cpRef.Y = point.Y;
            cpRef.Z = point.Z;

            Bentley.Interop.MicroStationDGN.Point3d cp = new Bentley.Interop.MicroStationDGN.Point3d();
            Bentley.Interop.MicroStationDGN.Point2d cp2d = new Bentley.Interop.MicroStationDGN.Point2d();

            Dist = GeometryTools.BSplineSurfaceComputeMinimumDistance(ref cp, ref cp2d, ref cpRef, tol, surf.com_bsplineSurface);
            UV = new Point2d();
            UV.X = cp2d.X;
            UV.Y = cp2d.Y;

            normal = NormalAtUVParameterOnSurface(surf.com_bsplineSurface, UV.X, UV.Y);

            return new DPoint3d(cp.X, cp.Y, cp.Z);
        }
        // should create on 0,0,0 center
        private Bentley.DgnPlatformNET.Elements.Element CreatePolyhedronCell(string sPolyhedronName,
                                                                             List <DPoint3d> points, List <List <int> > faces, List <DPoint3d> colors)
        {
            try
            {
                List <Bentley.DgnPlatformNET.Elements.Element> listElements = new List <Bentley.DgnPlatformNET.Elements.Element>();

                if (points.Count > 0 && faces.Count > 0)
                {
                    int iFaceIndex = 0;

                    foreach (List <int> listVertices in faces)
                    {
                        List <DPoint3d> listPoints = new List <DPoint3d>();

                        foreach (int iVertexIndex in listVertices)
                        {
                            DPoint3d pt = points[iVertexIndex];
                            pt.ScaleInPlace(uorPerMaster());
                            listPoints.Add(pt);
                        }

                        DPoint3d color = colors.ToArray()[iFaceIndex++];

                        Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement =
                            new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, listPoints.ToArray());

                        DVector3d normal    = new DVector3d();
                        DPoint3d  somePoint = new DPoint3d();
                        DPoint3d  defNormal = listPoints.ToArray()[0];

                        shapeElement.IsPlanar(out normal, out somePoint, ref defNormal);

                        uint iColorIndex = (uint)listPoints.Count - 1;

                        ElementPropertiesSetter pSetter = new ElementPropertiesSetter();

                        pSetter.SetColor(iColorIndex);
                        pSetter.SetFillColor(iColorIndex);
                        shapeElement.AddSolidFill(iColorIndex, false);

                        pSetter.Apply(shapeElement);

                        listElements.Add(shapeElement);
                    }
                }

                if (listElements.Count > 0)
                {
                    DMatrix3d rotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity
                    Bentley.DgnPlatformNET.Elements.CellHeaderElement cellHeaderElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), sPolyhedronName,
                                                                                                                new DPoint3d(0, 0, 0), rotation, listElements);

                    return(cellHeaderElement);
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"CreatePolyhedronCell {ex.Message}\n{ex.StackTrace}");
            }


            return(null);
        }
        protected override bool OnDataButton(DgnButtonEvent ev)
        {
            try
            {
                if (m_haveFirstPoint)
                {
                    // we're going to write the element

                    base.EndDynamics();

                    // now to work on rotation and scale
                    DPoint3d translation = m_firstPoint;

                    DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                    DPoint3d[] blkPts = new DPoint3d[4];

                    // rotate points to orthogonal
                    blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                    blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                    blkPts[2].Z = blkPts[0].Z;

                    DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                    DVector3d angleVec = new DVector3d(ext);

                    double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster()));

                    //RedrawElems redrawElems = new RedrawElems();
                    //redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
                    //redrawElems.DrawMode = DgnDrawMode.Normal;
                    //redrawElems.DrawPurpose = DrawPurpose.ForceRedraw;

                    try
                    {
                        DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                        if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation))
                        {
                            DMatrix3d cellRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                            List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = new List <Bentley.DgnPlatformNET.Elements.Element>();

                            foreach (Bentley.DgnPlatformNET.Elements.Element child in PolyhedraCE.StaticElement.GetChildren())
                            {
                                listChildElements.Add(child);
                            }

                            Bentley.DgnPlatformNET.Elements.CellHeaderElement copiedElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), PolyhedronName,
                                                                                                                    new DPoint3d(0, 0, 0), cellRotation, listChildElements);

                            if (copiedElement != null)
                            {
                                if (copiedElement.IsValid)
                                {
                                    invertedViewportRotation.ScaleInPlace(dScale);

                                    DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation, DMatrix3d.Rotation(2, angleVec.AngleXY));

                                    DTransform3d translateAndRotatetoUpInViewAndScale =
                                        DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation);

                                    TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale);

                                    copiedElement.ApplyTransform(transformInfo2);

                                    copiedElement.AddToModel();

                                    BPSUtilities.WriteLog("Added element to model");

                                    RedrawElems redrawElems = new RedrawElems();
                                    redrawElems.SetDynamicsViewsFromActiveViewSet(ev.Viewport);
                                    redrawElems.DrawMode    = DgnDrawMode.Normal;
                                    redrawElems.DrawPurpose = DrawPurpose.ForceRedraw;

                                    redrawElems.DoRedraw(copiedElement);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BPSUtilities.WriteLog($"OnDataBurron {ex.Message}\n{ex.StackTrace}");
                    }

                    m_haveFirstPoint = false;

                    m_firstPoint = new DPoint3d(0, 0, 0);

                    base.BeginDynamics();

                    return(true);
                }

                m_haveFirstPoint = true;

                m_firstPoint = ev.Point;

                base.BeginDynamics();
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"OnDataButton {ex.Message}\n{ex.StackTrace}");
            }

            return(true);
        }
Exemplo n.º 7
0
        protected override void OnPostInstall()
        {
            try
            {
                BPSUtilities.WriteLog("PlaceQRCode OnPostInstall");

                NotificationManager.OutputPrompt("Enter data point for corner of QR Code. Reset to exit.");
                // AccuSnap.SnapEnabled = true;
                // AccuSnap.LocateEnabled = true;
                base.OnPostInstall();

                m_haveFirstPoint = false;
                // base.BeginDynamics();
                m_firstPoint = DPoint3d.Zero;

                if (!string.IsNullOrEmpty(LongURL))
                {
                    QRCodeEncoderLibrary.QREncoder enc = QRCodeImageFunctions.GetQREncoderObject(LongURL);

                    BPSUtilities.WriteLog($"QRCodeDimension: {enc.QRCodeDimension}");

                    if (enc.QRCodeDimension > 0)
                    {
                        DPoint3d[] blkPts = new DPoint3d[4];

                        blkPts[0] = blkPts[1] = blkPts[2] = blkPts[3] = DPoint3d.Zero;

                        blkPts[0].X = enc.QuietZone;
                        blkPts[0].Y = enc.QuietZone;

                        blkPts[1].X = enc.QuietZone + 1.0;
                        blkPts[1].Y = enc.QuietZone;
                        blkPts[2].X = enc.QuietZone + 1.0;
                        blkPts[2].Y = enc.QuietZone + 1.0;
                        blkPts[3].X = enc.QuietZone;
                        blkPts[3].Y = enc.QuietZone + 1.0;

                        DPoint3d[] blkPts2 = new DPoint3d[4];

                        DVector3d yVec = new DVector3d(0, 1, 0);
                        DVector3d xVec = new DVector3d(1, 0, 0);

                        DMatrix3d cellRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                        List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = new List <Bentley.DgnPlatformNET.Elements.Element>();

                        // bool[,] pixels = enc.ConvertQRCodeMatrixToPixels();

                        for (int i = 0; i < enc.QRCodeDimension; i++)
                        {
                            // reset row
                            for (int index = 0; index < 4; index++)
                            {
                                blkPts2[index] = blkPts[index];
                            }

                            // move up
                            for (int index = 0; index < 4; index++)
                            {
                                blkPts2[index] = DPoint3d.Add(blkPts2[index], yVec, (double)i);
                            }

                            for (int j = 0; j < enc.QRCodeDimension; j++)
                            {
                                if (enc.QRCodeMatrix[i, j])
                                {
                                    Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement =
                                        new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, blkPts2);

                                    ElementPropertiesSetter pSetter = new ElementPropertiesSetter();

                                    pSetter.SetColor((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index);
                                    pSetter.SetFillColor((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index);
                                    shapeElement.AddSolidFill((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index, true);

                                    pSetter.Apply(shapeElement);

                                    if (shapeElement.IsValid)
                                    {
                                        listChildElements.Add(shapeElement);
                                    }
                                }

                                // move across
                                for (int index = 0; index < 4; index++)
                                {
                                    blkPts2[index] = DPoint3d.Add(blkPts2[index], xVec);
                                }
                            }
                        }

                        DPoint3d[] blkPts3 = new DPoint3d[5];

                        blkPts3[0] = blkPts3[1] = blkPts3[2] = blkPts3[3] = blkPts3[4] = DPoint3d.Zero;

                        blkPts3[1].X = 2 * enc.QuietZone + enc.QRCodeDimension;
                        blkPts3[2].X = 2 * enc.QuietZone + enc.QRCodeDimension;
                        blkPts3[2].Y = 2 * enc.QuietZone + enc.QRCodeDimension;
                        blkPts3[3].Y = 2 * enc.QuietZone + enc.QRCodeDimension;

                        Bentley.DgnPlatformNET.Elements.LineStringElement border = new LineStringElement(Session.Instance.GetActiveDgnModel(), null, blkPts3);

                        ElementPropertiesSetter pSetter2 = new ElementPropertiesSetter();

                        pSetter2.SetColor((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index);

                        pSetter2.Apply(border);

                        listChildElements.Add(border);

                        Bentley.DgnPlatformNET.Elements.CellHeaderElement codeElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), "QRCode",
                                                                                                              new DPoint3d(0, 0, 0), cellRotation, listChildElements);

                        // scale down to one...

                        DMatrix3d rotMatrix = DMatrix3d.Identity;

                        rotMatrix.ScaleInPlace((double)1.0 / (double)enc.QRCodeDimension);

                        DTransform3d translateAndScale =
                            DTransform3d.FromMatrixAndTranslation(rotMatrix, DPoint3d.Zero);

                        TransformInfo transformInfo = new TransformInfo(translateAndScale);

                        codeElement.ApplyTransform(transformInfo);

                        CodeElement = codeElement;

                        // might want to tag with the URL...

                        if (CodeElement.IsValid)
                        {
                            base.BeginDynamics();
                        }
                    }
                }

                BPSUtilities.WriteLog($"PlaceQRCode OnPostInstall Dynamics {(this.DynamicsStarted ? "is" : "is not")} started.");
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"PlaceQRCode OnPostInstall {ex.Message}\n{ex.StackTrace}");
            }
        }
Exemplo n.º 8
0
 public static DPoint3d ToDPoint(this BCOM.Point3d pt)
 {
     return(DPoint3d.FromXYZ(pt.X, pt.Y, pt.Z));
 }
Exemplo n.º 9
0
        private static double SquaredDistance(DPoint3d pt0, DPoint3d pt1)
        {
            double dx = pt0.X - pt1.X;
            double dy = pt0.Y - pt1.Y;
            double dz = pt0.Z - pt1.Z;

            return dx * dx + dy * dy + dz * dz;
        }
Exemplo n.º 10
0
 public static bool isPointInside(ISurface bs, DPoint3d testPt, double tol)
 {
     DPoint3d cp;
     DVector3d normal;
     return isPointInside(bs, testPt, tol, out normal, out cp);
 }
Exemplo n.º 11
0
        public static DPoint3d MeshCP(Mesh m, DPoint3d p)
        {
            double cdist = m.Vertices[0].DPoint3d.Distance(ref p);
            double dist;

            DPoint3d cp = m.Vertices[0].DPoint3d;

            foreach (Point mp in m.Vertices)
            {
                dist = mp.DPoint3d.Distance(ref p);
                if (dist < cdist)
                {
                    cp = mp.DPoint3d;
                }

            }

            return cp;
        }
Exemplo n.º 12
0
        public static bool isPointInside(ISurface bs, DPoint3d testPt, double tol, out DVector3d normal, out DPoint3d ClosestPoint)
        {
            Point2d uvPoint = new Point2d();
            DVector3d norm;
            double dist = 0;

            DPoint3d cp = closestPointOnSurf(testPt, bs, tol, out dist, out uvPoint, out norm);

            normal = norm;
            var testVec = new DVector3d(ref cp, ref testPt);

            ClosestPoint = cp;

            if (norm.AngleTo(ref testVec).Degrees <= 90)
            {
                return false;
            }
            else return true;
        }
Exemplo n.º 13
0
        protected override void OnDynamicFrame(Bentley.DgnPlatformNET.DgnButtonEvent ev)
        {
            RedrawElems redrawElems = new RedrawElems();

            redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
            redrawElems.DrawMode    = DgnDrawMode.TempDraw;
            redrawElems.DrawPurpose = DrawPurpose.Dynamics;

            try
            {
                DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation))
                {
                    if (CodeElement != null)
                    {
                        if (CodeElement.IsValid)
                        {
                            List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = CodeElement.GetChildren().GetEnumerator().ConvertToList();

                            Bentley.DgnPlatformNET.Elements.CellHeaderElement codeElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), "QRCode",
                                                                                                                  DPoint3d.Zero, DMatrix3d.Identity, listChildElements);

                            if (codeElement.IsValid)
                            {
                                if (m_haveFirstPoint)
                                {
                                    // now to work on rotation and scale
                                    DPoint3d translation = m_firstPoint;

                                    DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                    DPoint3d[] blkPts = new DPoint3d[4];

                                    // rotate points to orthogonal
                                    blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                    blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                    blkPts[2].Z = blkPts[0].Z;

                                    DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                                    DVector3d angleVec = new DVector3d(ext);

                                    // double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster()));

                                    invertedViewportRotation.ScaleInPlace(ext.Magnitude);

                                    DVector3d xVec = new DVector3d(1, 0, 0);

                                    DVector3d yVec = new DVector3d(0, 1, 0);

                                    Angle angle = Angle.Zero;

                                    //// UR and LR
                                    if (angleVec.AngleTo(xVec).Radians >= 0.0 && angleVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0))
                                    {
                                        if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                        {
                                            angle = Angle.Zero;
                                        }
                                        else
                                        {
                                            angle.Radians = Angle.NEGATIVE_PI.Radians / 2.0;
                                        }
                                    }
                                    // UL and LL
                                    else
                                    {
                                        if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                        {
                                            angle.Radians = Angle.PI.Radians / 2.0;
                                        }
                                        else
                                        {
                                            angle.Radians = Angle.PI.Radians;
                                        }
                                    }

                                    DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation,
                                                                                                      // DMatrix3d.Rotation(2, angleVec.AngleXY));
                                                                                                      DMatrix3d.Rotation(2, angle));

                                    // DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation,
                                    // DMatrix3d.Rotation(2, angleVec.AngleXY));

                                    DTransform3d translateAndRotatetoUpInViewAndScale =
                                        DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation);

                                    TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale);

                                    codeElement.ApplyTransform(transformInfo2);

                                    // below works great for drawing a block
                                    //DPoint3d[] blkPts = new DPoint3d[4];

                                    //DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                    //// rotate points to orthogonal
                                    //blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                    //blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                    //blkPts[2].Z = blkPts[0].Z;

                                    //blkPts[1].X = blkPts[0].X;
                                    //blkPts[1].Y = blkPts[2].Y;
                                    //blkPts[1].Z = blkPts[0].Z;

                                    //blkPts[3].X = blkPts[2].X;
                                    //blkPts[3].Y = blkPts[0].Y;
                                    //blkPts[3].Z = blkPts[0].Z;

                                    //DVector3d dVec = new DVector3d(blkPts[0], blkPts[2]);

                                    //double dWidth = blkPts[0].Distance(blkPts[1]);
                                    //double dHeight = blkPts[0].Distance(blkPts[3]);

                                    //double dDelta = Math.Abs(dWidth);

                                    //if (Math.Abs(dHeight) > Math.Abs(dWidth))
                                    //    dDelta = Math.Abs(dHeight);

                                    //blkPts[3] = blkPts[2] = blkPts[1] = blkPts[0];

                                    //DVector3d xVec = new DVector3d(1, 0, 0);

                                    //DVector3d yVec = new DVector3d(0, 1, 0);

                                    //double xFactor = 1.0, yFactor = 1.0;

                                    //// UR and LR
                                    //if (dVec.AngleTo(xVec).Radians >= 0.0 && dVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //{
                                    //    if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X + dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y + dDelta;
                                    //    }
                                    //    else
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X + dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y - dDelta;
                                    //        yFactor = -1.0;
                                    //    }
                                    //}
                                    //// UL and LL
                                    //else
                                    //{
                                    //    if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X - dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y + dDelta;
                                    //        xFactor = -1.0;
                                    //    }
                                    //    else
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X - dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y - dDelta;
                                    //        xFactor = -1.0;
                                    //        yFactor = -1.0;
                                    //    }
                                    //}

                                    //blkPts[1].X = blkPts[0].X;
                                    //blkPts[1].Y = blkPts[2].Y;
                                    //blkPts[1].Z = blkPts[0].Z;

                                    //blkPts[3].X = blkPts[2].X;
                                    //blkPts[3].Y = blkPts[0].Y;
                                    //blkPts[3].Z = blkPts[0].Z;

                                    //DPoint3d[] blkPts2 = new DPoint3d[4];

                                    //blkPts2[0] = blkPts2[1] = blkPts2[2] = blkPts2[3] = blkPts[0];

                                    //for (int i = 0; i < 4; i++)
                                    //{
                                    //    blkPts[i] = new DPoint3d(invertedViewportRotation.Multiply(new DVector3d(blkPts[i])));
                                    //}

                                    //Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement =
                                    //    new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, blkPts);

                                    //blkPts2[0].X += (xFactor) * dDelta / 4.0;
                                    //blkPts2[0].Y += (yFactor) * dDelta / 4.0;

                                    //blkPts2[2].X += (xFactor) * 3.0 * (dDelta / 4.0);
                                    //blkPts2[2].Y += (yFactor) * 3.0 * (dDelta / 4.0);

                                    //blkPts2[1].X = blkPts2[0].X;
                                    //blkPts2[1].Y = blkPts2[2].Y;
                                    //blkPts2[1].Z = blkPts2[0].Z;

                                    //blkPts2[3].X = blkPts2[2].X;
                                    //blkPts2[3].Y = blkPts2[0].Y;
                                    //blkPts2[3].Z = blkPts2[0].Z;

                                    //for (int i = 0; i < 4; i++)
                                    //{
                                    //    blkPts2[i] = new DPoint3d(invertedViewportRotation.Multiply(new DVector3d(blkPts2[i])));
                                    //}

                                    //Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement2 =
                                    //    new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, blkPts2);

                                    //redrawElems.DoRedraw(shapeElement);
                                    //redrawElems.DoRedraw(shapeElement2);
                                }
                                else
                                {
                                    // picking something arbitrary to use as scale factor
                                    invertedViewportRotation.ScaleInPlace(Bentley.MstnPlatformNET.Settings.TextHeight);

                                    DTransform3d scaleAndRotateToUpInView = DTransform3d.FromMatrixAndTranslation(invertedViewportRotation, ev.Point);

                                    TransformInfo transformInfo = new TransformInfo(scaleAndRotateToUpInView);

                                    codeElement.ApplyTransform(transformInfo);
                                }

                                redrawElems.DoRedraw(codeElement);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}");
            }
        }
Exemplo n.º 14
0
        protected override bool OnDataButton(DgnButtonEvent ev)
        {
            try
            {
                if (m_haveFirstPoint)
                {
                    // we're going to write the element

                    base.EndDynamics();

                    if (CodeElement != null)
                    {
                        if (CodeElement.IsValid)
                        {
                            List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = CodeElement.GetChildren().GetEnumerator().ConvertToList();

                            Bentley.DgnPlatformNET.Elements.CellHeaderElement codeElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), "QRCode",
                                                                                                                  DPoint3d.Zero, DMatrix3d.Identity, listChildElements);

                            if (codeElement.IsValid)
                            {
                                DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                                if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation))
                                {
                                    // now to work on rotation and scale
                                    DPoint3d translation = m_firstPoint;

                                    DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                    DPoint3d[] blkPts = new DPoint3d[4];

                                    // rotate points to orthogonal
                                    blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                    blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                    blkPts[2].Z = blkPts[0].Z;

                                    DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                                    DVector3d angleVec = new DVector3d(ext);

                                    // double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster()));

                                    invertedViewportRotation.ScaleInPlace(ext.Magnitude);

                                    DVector3d xVec = new DVector3d(1, 0, 0);

                                    DVector3d yVec = new DVector3d(0, 1, 0);

                                    Angle angle = Angle.Zero;

                                    //// UR and LR
                                    if (angleVec.AngleTo(xVec).Radians >= 0.0 && angleVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0))
                                    {
                                        if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                        {
                                            angle = Angle.Zero;
                                        }
                                        else
                                        {
                                            angle.Radians = Angle.NEGATIVE_PI.Radians / 2.0;
                                        }
                                    }
                                    // UL and LL
                                    else
                                    {
                                        if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                        {
                                            angle.Radians = Angle.PI.Radians / 2.0;
                                        }
                                        else
                                        {
                                            angle.Radians = Angle.PI.Radians;
                                        }
                                    }

                                    DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation,
                                                                                                      // DMatrix3d.Rotation(2, angleVec.AngleXY));
                                                                                                      DMatrix3d.Rotation(2, angle));

                                    DTransform3d translateAndRotatetoUpInViewAndScale =
                                        DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation);

                                    TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale);

                                    codeElement.ApplyTransform(transformInfo2);

                                    //DPoint3d[] blkPts = new DPoint3d[4];

                                    //DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                    //// rotate points to orthogonal
                                    //blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                    //blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                    //blkPts[2].Z = blkPts[0].Z;

                                    //blkPts[1].X = blkPts[0].X;
                                    //blkPts[1].Y = blkPts[2].Y;
                                    //blkPts[1].Z = blkPts[0].Z;

                                    //blkPts[3].X = blkPts[2].X;
                                    //blkPts[3].Y = blkPts[0].Y;
                                    //blkPts[3].Z = blkPts[0].Z;

                                    //DVector3d dVec = new DVector3d(blkPts[0], blkPts[2]);

                                    //double dWidth = blkPts[0].Distance(blkPts[1]);
                                    //double dHeight = blkPts[0].Distance(blkPts[3]);

                                    //double dDelta = Math.Max(Math.Abs(dWidth), Math.Abs(dHeight));

                                    //blkPts[3] = blkPts[2] = blkPts[1] = blkPts[0];

                                    //DVector3d xVec = new DVector3d(1, 0, 0);

                                    //DVector3d yVec = new DVector3d(0, 1, 0);

                                    //// UR and LR
                                    //if (dVec.AngleTo(xVec).Radians >= 0.0 && dVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //{
                                    //    if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X + dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y + dDelta;
                                    //    }
                                    //    else
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X + dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y - dDelta;
                                    //    }
                                    //}
                                    //// UL and LL
                                    //else
                                    //{
                                    //    if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0))
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X - dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y + dDelta;
                                    //    }
                                    //    else
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X - dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y - dDelta;
                                    //    }
                                    //}

                                    //blkPts[1].X = blkPts[0].X;
                                    //blkPts[1].Y = blkPts[2].Y;
                                    //blkPts[1].Z = blkPts[0].Z;

                                    //blkPts[3].X = blkPts[2].X;
                                    //blkPts[3].Y = blkPts[0].Y;
                                    //blkPts[3].Z = blkPts[0].Z;

                                    //for (int i = 0; i < 4; i++)
                                    //{
                                    //    blkPts[i] = new DPoint3d(invertedViewportRotation.Multiply(new DVector3d(blkPts[i])));
                                    //}

                                    //Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement =
                                    //    new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, blkPts);

                                    RedrawElems redrawElems = new RedrawElems();
                                    redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
                                    redrawElems.DrawMode    = DgnDrawMode.Normal;
                                    redrawElems.DrawPurpose = DrawPurpose.ForceRedraw;

                                    codeElement.AddToModel();

                                    redrawElems.DoRedraw(codeElement);

                                    m_haveFirstPoint = false;

                                    m_firstPoint = new DPoint3d(0, 0, 0);

                                    base.BeginDynamics();

                                    return(true);
                                }
                            }
                        }
                    }
                }
                else
                {
                    m_haveFirstPoint = true;

                    m_firstPoint = ev.Point;

                    // base.BeginDynamics();
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"OnDataButton {ex.Message}\n{ex.StackTrace}");
            }

            return(true);
        }
        protected override void OnDynamicFrame(Bentley.DgnPlatformNET.DgnButtonEvent ev)
        {
            try
            {
                if (PolyhedraCE.StaticElement == null)
                {
                    if (!string.IsNullOrEmpty(PolyhedronName))
                    {
                        if (PolyhedraCE.ListOfPolyhedra.ContainsKey(PolyhedronName))
                        {
                            BPSUtilities.WriteLog($"Found cell for '{PolyhedronName}'");
                            PolyhedraCE.StaticElement = PolyhedraCE.ListOfPolyhedra[PolyhedronName];
                        }
                        else
                        {
                            m_haveFirstPoint = false;
                            BPSUtilities.WriteLog($"Cell for '{PolyhedronName}' not found.");
                            this.EndDynamics();
                        }
                    }
                    else
                    {
                        BPSUtilities.WriteLog("Polyhedron Name not set.");
                        m_haveFirstPoint = false;
                        this.EndDynamics();
                    }
                }

                try
                {
                    Bentley.DgnPlatformNET.Elements.CellHeaderElement cellElem = (Bentley.DgnPlatformNET.Elements.CellHeaderElement)(PolyhedraCE.StaticElement);
                    if (cellElem.CellName != PolyhedronName)
                    {
                        BPSUtilities.WriteLog($"Current cell is {cellElem.CellName}");

                        if (!string.IsNullOrEmpty(PolyhedronName))
                        {
                            if (PolyhedraCE.ListOfPolyhedra.ContainsKey(PolyhedronName))
                            {
                                BPSUtilities.WriteLog($"Found cell for '{PolyhedronName}'");

                                if (PolyhedraCE.StaticElement != null)
                                {
                                    PolyhedraCE.StaticElement.Dispose();
                                }

                                PolyhedraCE.StaticElement = PolyhedraCE.ListOfPolyhedra[PolyhedronName];
                            }
                            else
                            {
                                m_haveFirstPoint = false;
                                BPSUtilities.WriteLog($"Cell for '{PolyhedronName}' not found.");
                                this.EndDynamics();
                            }
                        }
                        else
                        {
                            BPSUtilities.WriteLog("Polyhedron Name not set.");
                            m_haveFirstPoint = false;
                            this.EndDynamics();
                        }
                    }
                }
                catch (Exception ex)
                {
                    BPSUtilities.WriteLog($"Error casting cell {ex.Message}");
                }

                if (PolyhedraCE.StaticElement != null)
                {
                    RedrawElems redrawElems = new RedrawElems();
                    redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
                    redrawElems.DrawMode    = DgnDrawMode.TempDraw;
                    redrawElems.DrawPurpose = DrawPurpose.Dynamics;

                    try
                    {
                        DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                        if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation))
                        {
                            DMatrix3d cellRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                            List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = new List <Bentley.DgnPlatformNET.Elements.Element>();

                            foreach (Bentley.DgnPlatformNET.Elements.Element child in PolyhedraCE.StaticElement.GetChildren())
                            {
                                listChildElements.Add(child);
                            }

                            Bentley.DgnPlatformNET.Elements.CellHeaderElement copiedElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), PolyhedronName,
                                                                                                                    new DPoint3d(0, 0, 0), cellRotation, listChildElements);

                            if (copiedElement != null)
                            {
                                if (copiedElement.IsValid)
                                {
                                    if (!m_haveFirstPoint)
                                    {
                                        DPoint3d translation = ev.Point;

                                        DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                        DPoint3d[] blkPts = new DPoint3d[4];

                                        DPoint3d low = DPoint3d.Zero, high = DPoint3d.Zero;

                                        ev.Viewport.GetViewCorners(out low, out high);

                                        // rotate points to orthogonal
                                        blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(low)));

                                        blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(high)));

                                        blkPts[2].Z = blkPts[0].Z;

                                        DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                                        double dScale = Math.Max(0.15 * Math.Abs(ext.Magnitude / uorPerMaster()), 1.0);

                                        DPoint3d dPtScale = ev.Viewport.GetScale();

                                        // dScale = dPtScale.Magnitude;

                                        // BPSUtilities.WriteLog($"Scale: {dScale}, View: {ev.ViewNumber}");

                                        invertedViewportRotation.ScaleInPlace(dScale);

                                        // works
                                        DTransform3d translateAndRotateToUpInViewWithViewBasedScale =
                                            DTransform3d.FromMatrixAndTranslation(invertedViewportRotation, translation);

                                        TransformInfo transformInfo = new TransformInfo(translateAndRotateToUpInViewWithViewBasedScale);

                                        // works
                                        copiedElement.ApplyTransform(transformInfo);
                                    }
                                    else
                                    {
                                        // now to work on rotation and scale
                                        DPoint3d translation = m_firstPoint;

                                        DMatrix3d viewMatrix = ev.Viewport.GetRotation();

                                        DPoint3d[] blkPts = new DPoint3d[4];

                                        // rotate points to orthogonal
                                        blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint)));

                                        blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point)));

                                        blkPts[2].Z = blkPts[0].Z;

                                        DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]);

                                        DVector3d angleVec = new DVector3d(ext);

                                        double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster()));

                                        invertedViewportRotation.ScaleInPlace(dScale);

                                        DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation, DMatrix3d.Rotation(2, angleVec.AngleXY));

                                        DTransform3d translateAndRotatetoUpInViewAndScale =
                                            DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation);

                                        TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale);

                                        copiedElement.ApplyTransform(transformInfo2);
                                    }

                                    redrawElems.DoRedraw(copiedElement);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}");
                    }
                    //    if (!m_haveFirstPoint)
                    //{
                    //    BPSUtilities.WriteLog("Don't have first point.");
                    //    // move it around on cursor
                    //    redrawElems.DoRedraw(GetTransformedElement(m_element, ev));
                    //}
                    //else
                    //{
                    //    BPSUtilities.WriteLog("Do have first point.");
                    //    redrawElems.DoRedraw(GetTransformedElement(m_element, ev));
                    //}
                }
                else
                {
                    BPSUtilities.WriteLog("Element is null");
                    this.EndDynamics();
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"OnDynamicFrame: {ex.Message}\n{ex.StackTrace}");
            }
        }
Exemplo n.º 16
0
        public static DPoint3d[] ConnectedVtx(this Mesh m, DPoint3d searchPoint, out int[] conectedVtxIDs)
        {
            int[] conectedVtxID = CerverFunctions.GetConnectedPointID(m, searchPoint);
            conectedVtxIDs = conectedVtxID;

            List<DPoint3d> connectedVtx = new List<DPoint3d>(conectedVtxID.Length);

            foreach (var id in conectedVtxID)
            {

                connectedVtx.Add(m.Vertices[id].DPoint3d);
            }

            return connectedVtx.ToArray();
        }
Exemplo n.º 17
0
 public ModelHeaderElm Read(BinaryReader br)
 {
     // read each field
     Ehdr             = new Elm_hdr().Read(br);
     Dummy1           = br.ReadUInt32();
     Dummy2           = br.ReadUInt32();
     Dummy3           = br.ReadUInt32();
     Dummy4           = br.ReadUInt32();
     Dummy5           = br.ReadUInt32();
     Dummy6           = br.ReadUInt32();
     Dummy7           = br.ReadUInt32();
     GridPerReference = br.ReadUInt32();
     Dummy9           = br.ReadUInt32();
     Dummy10          = br.ReadUInt32();
     Dummy11          = br.ReadUInt32();
     Dummy12          = br.ReadUInt32();
     MuNumerator      = br.ReadDouble();
     MuDenominator    = br.ReadDouble();
     SuNumerator      = br.ReadDouble();
     SuDenominator    = br.ReadDouble();
     GlobalOrigin     = new DPoint3d().Read(br);
     LastModified     = br.ReadDouble();
     Y0             = br.ReadInt64();
     Y1             = br.ReadInt64();
     Y2             = br.ReadInt64();
     Y3             = br.ReadInt64();
     Y4             = br.ReadInt64();
     Y5             = br.ReadInt64();
     Y6             = br.ReadInt64();
     Y7             = br.ReadInt64();
     Y8             = br.ReadInt64();
     Y9             = br.ReadInt64();
     UorsPerStorage = br.ReadDouble();
     StNumerator    = br.ReadDouble();
     StDenominator  = br.ReadDouble();
     Z0             = br.ReadDouble();
     Z1             = br.ReadDouble();
     Z2             = br.ReadDouble();
     Z3             = br.ReadDouble();
     Z4             = br.ReadDouble();
     Z5             = br.ReadDouble();
     Z6             = br.ReadDouble();
     Z7             = br.ReadDouble();
     Z8             = br.ReadDouble();
     Z9             = br.ReadDouble();
     Z10            = br.ReadDouble();
     Z11            = br.ReadDouble();
     Z12            = br.ReadDouble();
     Z13            = br.ReadDouble();
     Z14            = br.ReadDouble();
     Z15            = br.ReadDouble();
     Z16            = br.ReadDouble();
     Z17            = br.ReadDouble();
     Z18            = br.ReadDouble();
     Z19            = br.ReadDouble();
     Z20            = br.ReadDouble();
     Z21            = br.ReadDouble();
     Z22            = br.ReadDouble();
     Z23            = br.ReadDouble();
     Z24            = br.ReadDouble();
     Z25            = br.ReadDouble();
     Z26            = br.ReadDouble();
     Z27            = br.ReadDouble();
     Z28            = br.ReadDouble();
     Z29            = br.ReadDouble();
     Z30            = br.ReadDouble();
     Linkages       = V8Linkages.V8GetLinkages(br, Ehdr);
     return(this);
 }
Exemplo n.º 18
0
 public static int[] ConnectedVtxID(this Mesh m, DPoint3d searchPoint)
 {
     return CerverFunctions.GetConnectedPointID(m, searchPoint);
 }
Exemplo n.º 19
0
        /*---------------------------------------------------------------------------------**//**
        * Calculates points from start and opposite points and creates a shape
        * @bsimethod                                                              Bentley Systems
        *  /*--------------+---------------+---------------+---------------+---------------+------*/
        private static ShapeElement CreateShapeElement(DgnModel model, DPoint3d start, DPoint3d opposite)
        {
            DPoint3d[] points = new DPoint3d[5];
            points[0] = points[1] = points[3] = points[4] = start;
            points[2] = opposite;

            points[1].X = opposite.X;
            points[3].Y = opposite.Y;

            ShapeElement shape = new ShapeElement(model, null, points);

            return(shape);
        }
Exemplo n.º 20
0
        public NodeUpdateResult PlaceParametricCell
        (
            NodeUpdateContext updateContext,
            [Replicatable, DgnModelProvider] IPoint PlacementPoint,
            [Replicatable] IPlane PlacementPlane,
            [In] string CellLibraryPath,
            [In] string CellDefinitionName,
            [In] string CellVariation,
            [Replicatable(-1, true)] string[] CellVariableNames,
            [Replicatable(-1, true)] string[] CellVariableValues
        )
        {
            this.ClearAndErase(updateContext); // Remove old feature
            
            if (this.ReplicationIndex == 0 && CellLibraryPath == null || CellDefinitionName == null)
            {
                return new NodeUpdateResult.IncompleteInputs(CellLibraryPath, CellDefinitionName);
            }
            else
            {
                //NEED TO IMPLEMENT A SHARED CELL UPDATE IF UpdateSharedCell == true; THEN ONCE UPDATED SET THE PARAMETER TO FALSE SO THAT THE NEXT PLACED CELL DOESN'T UPDATE THE SHARED CELL AGAIN
                //Check if cell library is attached and if not attach it
                if (this.ReplicationIndex == 0 && MSApp.IsCellLibraryAttached == false || MSApp.AttachedCellLibrary.FullName != CellLibraryPath)
                {
                    MSApp.AttachCellLibrary(CellLibraryPath);
                }
                
                DgnFile activeDgnFile = Session.Instance.GetActiveDgnFile();
                DgnModel activeModel = Session.Instance.GetActiveDgnModel();
                DgnModel cellModel = null;
                ParametricCellElement pCell = null;

                ParametricCellDefinitionElement cellDef = ParametricCellDefinitionElement.FindByName(CellDefinitionName, activeDgnFile);

                if (cellDef == null) //cell not in active file, load from attached cell library
                {
                    var opts = CellLibraryOptions.Include3d | CellLibraryOptions.IncludeAllLibraries | CellLibraryOptions.IncludeParametric;
                    var libs = new CellLibraryCollection(opts);

                    foreach (var lib in libs)
                    {
                        if (CellDefinitionName.Equals(lib.Name))
                        {
                            StatusInt status;
                            cellModel = lib.File.LoadRootModelById(out status, lib.File.FindModelIdByName(lib.Name), true, false, true);
                            break;
                        }
                    }

                    if (null == cellModel) //Cell definition (model) doesn't exist in the cell model file
                    {
                        LsBuilder lsBuilder = new LsBuilder();
                        Ls ls = lsBuilder.AppendLineLiteral("Error loading cell definition. Check cell definition name and library are correct.").ToLs();
                        return new NodeUpdateResult.TechniqueFailureMessage(ls);
                    }
                    else
                    {
                        var hdlr = DgnComponentDefinitionHandler.GetForModel(cellModel);
                        var status = hdlr.DefinitionModelHandler.CreateCellDefinition(activeDgnFile);

                        if (ParameterStatus.Success == status)
                            cellDef = ParametricCellDefinitionElement.FindByName(CellDefinitionName, activeDgnFile);
                        else
                        {
                            LsBuilder lsBuilder = new LsBuilder();
                            Ls ls = lsBuilder.AppendLineLiteral("Error creating cell definition in active file.").ToLs();
                            return new NodeUpdateResult.TechniqueFailureMessage(ls);
                        }
                    }
                }
                

                try
                {
                    pCell = ParametricCellElement.Create(cellDef, CellVariation, activeModel);

                    //Cell origin point - adjusted for U.O.R.
                    double uor = MSApp.ActiveModelReference.UORsPerMasterUnit;
                    DPoint3d cellOrigin = DPoint3d.Multiply(uor, PlacementPoint.GetDPoint3d());
                    pCell.Origin = cellOrigin;

                    DTransform3d dTransform3D = PlacementPlane.GetDTransform3d();
                    DPlane3d dPlane3D = PlacementPlane.GetDPlane3d();

                    DMatrix3d dMatrix3D = new DMatrix3d(dTransform3D);

                    pCell.Rotation = dMatrix3D;

                    //pCell.IsInvisible = true; //We don't want multiple elements visible
                    pCell.AddToModel(); //Add to the model so we can assign variables and retrieve the element

                    //Assign custom variables if they exist
                    if (CellVariableNames != null && CellVariableValues != null)
                    {
                        IECClass ecClass = pCell.Parameters.ClassDefinition;
                        IDgnECInstance eci = DgnECManager.FindECInstanceOnElement(pCell, ecClass);

                        for (int i = 0; i < CellVariableNames.Length; ++i)
                        {                            
                            IEnumerator<IECPropertyValue> props = eci.GetEnumerator(false, true);
                            
                            while (props.MoveNext())
                            {
                                if (props.Current.Property.DisplayLabel == CellVariableNames[i].ToString())
                                {
                                    props.Current.StringValue = CellVariableValues[i].ToString();
                                }
                            }
                        }
                        eci.WriteChanges();
                    }
                    
                    IElement ele = MSApp.ActiveModelReference.GetLastValidGraphicalElement();

                    SetElement(ele); //Commit as a GC feature
                    pCell.Dispose(); //Clean up the memory of pCell, only 'ele' will be retained
                }
                catch (Exception ex)
                {
                    return new NodeUpdateResult.TechniqueException(ex);
                }

                return NodeUpdateResult.Success;
            }
        }