Example #1
0
        public void Draw()
        {
            sortedlocalsTech = sortedlocalsTech.Distinct(new CusComparer()).ToList();
            try
            {
                for (int i = 0; i < sortedlocalsTech.Count(); i += 1)
                {
                    foreach (var item in sortedlocalsTech.ElementAt(i))
                    {
                        var myspace = doc.GetElement(item.Id) as Space;
                        SpatialElementGeometryCalculator calculator = new SpatialElementGeometryCalculator(doc);
                        SpatialElementGeometryResults    results    = calculator.CalculateSpatialElementGeometry(myspace); // compute the room geometry
                        Solid roomSolid = results.GetGeometry();
                        results.GetGeometry();

                        XYZ sp = null, ep = null;

                        ElementId levelId  = ElementId.InvalidElementId;
                        Document  document = uidoc.Document;
                        Utils.lazyInstance.GetElementLocation(out sp, myspace);
                        BoundingBoxXYZ bbxyz = myspace.get_BoundingBox(null);

                        bbxyz.Enabled = true;
                        List <XYZ> edges = new List <XYZ>();
                        edges.Add(new XYZ(Math.Round(bbxyz.get_Bounds(0).X, 2), Math.Round(bbxyz.get_Bounds(0).Y, 2), Math.Round(bbxyz.get_Bounds(1).Z, 2)));
                        edges.Add(new XYZ(Math.Round(bbxyz.get_Bounds(1).X, 2), Math.Round(bbxyz.get_Bounds(0).Y, 2), Math.Round(bbxyz.get_Bounds(1).Z, 2)));
                        edges.Add(new XYZ(Math.Round(bbxyz.get_Bounds(0).X, 2), Math.Round(bbxyz.get_Bounds(0).Y, 2), Math.Round(bbxyz.get_Bounds(0).Z, 2)));
                        edges.Add(new XYZ(Math.Round(bbxyz.get_Bounds(1).X, 2), Math.Round(bbxyz.get_Bounds(0).Y, 2), Math.Round(bbxyz.get_Bounds(0).Z, 2)));
                        edges.Add(new XYZ(Math.Round(bbxyz.get_Bounds(0).X, 2), Math.Round(bbxyz.get_Bounds(1).Y, 2), Math.Round(bbxyz.get_Bounds(1).Z, 2)));
                        edges.Add(new XYZ(Math.Round(bbxyz.get_Bounds(1).X, 2), Math.Round(bbxyz.get_Bounds(1).Y, 2), Math.Round(bbxyz.get_Bounds(1).Z, 2)));
                        edges.Add(new XYZ(Math.Round(bbxyz.get_Bounds(0).X, 2), Math.Round(bbxyz.get_Bounds(1).Y, 2), Math.Round(bbxyz.get_Bounds(0).Z, 2)));
                        edges.Add(new XYZ(Math.Round(bbxyz.get_Bounds(1).X, 2), Math.Round(bbxyz.get_Bounds(1).Y, 2), Math.Round(bbxyz.get_Bounds(0).Z, 2)));

                        Utils.lazyInstance.GetLowestAndHighestPolygon(edges, myspace.Level);
                        RevitDataContext.lazyInstance.SpacesInfo.Add(myspace, new Tuple <XYZ,
                                                                                         List <XYZ>,
                                                                                         List <XYZ>,
                                                                                         List <XYZ> >(Utils.lazyInstance.GetCenterOfPolygon(edges),
                                                                                                      edges, new List <XYZ>(Utils.lazyInstance.lowestPolyg), new List <XYZ>(Utils.lazyInstance.highestPolyg)));
                        ep = sp;
                    }
                    Debug.WriteLine("count(): " + RevitDataContext.lazyInstance.SpacesInfo.Count());
                    CreateDucts(i);
                    correspSmallestSpaces.Clear();
                    tiltingSpaces.Clear();
                    currentConnectors.Clear();
                    CorrespIntersec.Clear();
                    RevitDataContext.lazyInstance.SpacesInfo.Clear();
                }
            }
            catch
            {
                TaskDialog.Show("Erreur", "Erreur: Vérifier bien que toutes les gaines ont été correctement assigné. Supprimez tous les espaces non assignés et non clos.");
            }
        }
Example #2
0
        // Get the path  best one
        private Tuple <XYZ, XYZ> GetBestPath()
        {
            XYZ bStartingP = null, bEndingP = null;

            //left in the plan
            XYZ S1 = new XYZ(); XYZ S2 = new XYZ(); XYZ S3 = new XYZ(); XYZ S4 = new XYZ();
            // right in the plan
            XYZ S5 = new XYZ(); XYZ S6 = new XYZ(); XYZ S7 = new XYZ(); XYZ S8 = new XYZ();


            ////// Lookup, it is the 2nd space  we are checking in
            //left in the plan
            XYZ S1Lookup = new XYZ(); XYZ S2Lookup = new XYZ(); XYZ S3Lookup = new XYZ(); XYZ S4Lookup = new XYZ();
            // right in the plan
            XYZ S5Lookup = new XYZ(); XYZ S6Lookup = new XYZ(); XYZ S7Lookup = new XYZ(); XYZ S8Lookup = new XYZ();
            int i = 0;

            foreach (var spaceInfoItem in RevitDataContext.lazyInstance.SpacesInfo)
            {
                // Polygon Right in the plan
                BoundingBoxXYZ bbxyz = spaceInfoItem.Key.get_BoundingBox(null);
                bbxyz.Enabled = true;

                S1 = new XYZ(Math.Round(bbxyz.get_Bounds(0).X, 2), Math.Round(bbxyz.get_Bounds(0).Y, 2), Math.Round(bbxyz.get_Bounds(1).Z, 2));
                S2 = new XYZ(Math.Round(bbxyz.get_Bounds(1).X, 2), Math.Round(bbxyz.get_Bounds(0).Y, 2), Math.Round(bbxyz.get_Bounds(1).Z, 2));
                S3 = new XYZ(Math.Round(bbxyz.get_Bounds(0).X, 2), Math.Round(bbxyz.get_Bounds(0).Y, 2), Math.Round(bbxyz.get_Bounds(0).Z, 2));
                S4 = new XYZ(Math.Round(bbxyz.get_Bounds(1).X, 2), Math.Round(bbxyz.get_Bounds(0).Y, 2), Math.Round(bbxyz.get_Bounds(0).Z, 2));
                S5 = new XYZ(Math.Round(bbxyz.get_Bounds(0).X, 2), Math.Round(bbxyz.get_Bounds(1).Y, 2), Math.Round(bbxyz.get_Bounds(1).Z, 2));
                S6 = new XYZ(Math.Round(bbxyz.get_Bounds(1).X, 2), Math.Round(bbxyz.get_Bounds(1).Y, 2), Math.Round(bbxyz.get_Bounds(1).Z, 2));
                S7 = new XYZ(Math.Round(bbxyz.get_Bounds(0).X, 2), Math.Round(bbxyz.get_Bounds(1).Y, 2), Math.Round(bbxyz.get_Bounds(0).Z, 2));
                S8 = new XYZ(Math.Round(bbxyz.get_Bounds(1).X, 2), Math.Round(bbxyz.get_Bounds(1).Y, 2), Math.Round(bbxyz.get_Bounds(0).Z, 2));

                List <Tuple <Space, List <Tuple <Tuple <XYZ, XYZ>, Tuple <XYZ, XYZ>, XYZ> > > > Gintersections
                    = new List <Tuple <Space, List <Tuple <Tuple <XYZ, XYZ>, Tuple <XYZ, XYZ>, XYZ> > > >();
                ////// Lookup, it is the 2nd space  we are checking in
                for (int j = 0; j < RevitDataContext.lazyInstance.SpacesInfo.Count(); j += 1)
                {
                    if (j != i)
                    {
                        /// param are projected face start & ending point, lookingup start & ending point and intersection respectively
                        List <Tuple <Tuple <XYZ, XYZ>, Tuple <XYZ, XYZ>, XYZ> > intersections = new List <Tuple <Tuple <XYZ, XYZ>, Tuple <XYZ, XYZ>, XYZ> >();

                        BoundingBoxXYZ bbxyzLookup = RevitDataContext.lazyInstance.SpacesInfo.ElementAt(j).Key.get_BoundingBox(null);
                        bbxyzLookup.Enabled = true;

                        // Polygon Left in the plan
                        S1Lookup = new XYZ(Math.Round(bbxyzLookup.get_Bounds(0).X, 2), Math.Round(bbxyzLookup.get_Bounds(0).Y, 2), Math.Round(bbxyzLookup.get_Bounds(1).Z, 2));
                        S2Lookup = new XYZ(Math.Round(bbxyzLookup.get_Bounds(1).X, 2), Math.Round(bbxyzLookup.get_Bounds(0).Y, 2), Math.Round(bbxyzLookup.get_Bounds(1).Z, 2));
                        S3Lookup = new XYZ(Math.Round(bbxyzLookup.get_Bounds(0).X, 2), Math.Round(bbxyzLookup.get_Bounds(0).Y, 2), Math.Round(bbxyzLookup.get_Bounds(0).Z, 2));
                        S4Lookup = new XYZ(Math.Round(bbxyzLookup.get_Bounds(1).X, 2), Math.Round(bbxyzLookup.get_Bounds(0).Y, 2), Math.Round(bbxyzLookup.get_Bounds(0).Z, 2));
                        // Polygon Right in the plan
                        S5Lookup = new XYZ(Math.Round(bbxyzLookup.get_Bounds(0).X, 2), Math.Round(bbxyzLookup.get_Bounds(1).Y, 2), Math.Round(bbxyzLookup.get_Bounds(1).Z, 2));
                        S6Lookup = new XYZ(Math.Round(bbxyzLookup.get_Bounds(1).X, 2), Math.Round(bbxyzLookup.get_Bounds(1).Y, 2), Math.Round(bbxyzLookup.get_Bounds(1).Z, 2));
                        S7Lookup = new XYZ(Math.Round(bbxyzLookup.get_Bounds(0).X, 2), Math.Round(bbxyzLookup.get_Bounds(1).Y, 2), Math.Round(bbxyzLookup.get_Bounds(0).Z, 2));
                        S8Lookup = new XYZ(Math.Round(bbxyzLookup.get_Bounds(1).X, 2), Math.Round(bbxyzLookup.get_Bounds(1).Y, 2), Math.Round(bbxyzLookup.get_Bounds(0).Z, 2));

                        // Polygon projected from highest  of first polygon  to lowest lookup's polygon
                        XYZ S1Pp = new XYZ(Math.Round(S2.X, 2), Math.Round(S2.Y, 2), Math.Round(S4Lookup.Z, 2));
                        XYZ S2Pp = new XYZ(Math.Round(S6.X, 2), Math.Round(S6.Y, 2), Math.Round(S8Lookup.Z, 2));
                        XYZ S3Pp = new XYZ(Math.Round(S1.X, 2), Math.Round(S1.Y, 2), Math.Round(S3Lookup.Z, 2));
                        XYZ S4Pp = new XYZ(Math.Round(S5.X, 2), Math.Round(S5.Y, 2), Math.Round(S7Lookup.Z, 2));

                        // because for some reasons Line object has no properties startingpoint and ending point
                        List <Tuple <Line, XYZ, XYZ> > projectedFace = new List <Tuple <Line, XYZ, XYZ> >();
                        projectedFace.Add(new Tuple <Line, XYZ, XYZ>(Line.CreateBound(S8Lookup, S7Lookup), S8Lookup, S7Lookup));
                        projectedFace.Add(new Tuple <Line, XYZ, XYZ>(Line.CreateBound(S4Lookup, S3Lookup), S4Lookup, S3Lookup));
                        projectedFace.Add(new Tuple <Line, XYZ, XYZ>(Line.CreateBound(S4Lookup, S8Lookup), S4Lookup, S8Lookup));
                        projectedFace.Add(new Tuple <Line, XYZ, XYZ>(Line.CreateBound(S3Lookup, S7Lookup), S3Lookup, S7Lookup));

                        List <Tuple <Line, XYZ, XYZ> > lookingUpFace = new List <Tuple <Line, XYZ, XYZ> >();
                        lookingUpFace.Add(new Tuple <Line, XYZ, XYZ>(Line.CreateBound(S2Pp, S4Pp), S2Pp, S4Pp));
                        lookingUpFace.Add(new Tuple <Line, XYZ, XYZ>(Line.CreateBound(S1Pp, S3Pp), S1Pp, S3Pp));
                        lookingUpFace.Add(new Tuple <Line, XYZ, XYZ>(Line.CreateBound(S1Pp, S2Pp), S1Pp, S2Pp));
                        lookingUpFace.Add(new Tuple <Line, XYZ, XYZ>(Line.CreateBound(S3Pp, S4Pp), S3Pp, S4Pp));

                        foreach (Tuple <Line, XYZ, XYZ> lp in projectedFace)
                        {
                            foreach (Tuple <Line, XYZ, XYZ> llu in lookingUpFace)
                            {
                                IntersectionResultArray intersectionR = new IntersectionResultArray();
                                SetComparisonResult     res           = SetComparisonResult.Disjoint;
                                res = lp.Item1.Intersect(llu.Item1, out intersectionR);
                                if (SetComparisonResult.Disjoint != res)
                                {
                                    if (intersectionR != null)
                                    {
                                        if (!intersectionR.IsEmpty)
                                        {
                                            intersections.Add(new Tuple <Tuple <XYZ, XYZ>, Tuple <XYZ, XYZ>, XYZ>(new Tuple <XYZ, XYZ>(new XYZ(Math.Round(lp.Item2.X, 2), Math.Round(lp.Item2.Y, 2), Math.Round(lp.Item2.Z, 2)),
                                                                                                                                       new XYZ(Math.Round(lp.Item3.X, 2), Math.Round(lp.Item3.Y, 2), Math.Round(lp.Item3.Z, 2))),
                                                                                                                  new Tuple <XYZ, XYZ>(new XYZ(Math.Round(llu.Item2.X, 2), Math.Round(llu.Item2.Y, 2), Math.Round(llu.Item2.Z, 2)),
                                                                                                                                       new XYZ(Math.Round(llu.Item3.X, 2), Math.Round(llu.Item3.Y, 2), Math.Round(llu.Item3.Z, 2))),
                                                                                                                  new XYZ(Math.Round(intersectionR.get_Item(0).XYZPoint.X, 2), Math.Round(intersectionR.get_Item(0).XYZPoint.Y, 2), Math.Round(intersectionR.get_Item(0).XYZPoint.Z, 2))));
                                        }
                                    }
                                }
                            }
                        }
                        Utils.lazyInstance.PurgeList(intersections);
                        Gintersections.Add(new Tuple <Space, List <Tuple <Tuple <XYZ, XYZ>, Tuple <XYZ, XYZ>, XYZ> > >(RevitDataContext.lazyInstance.SpacesInfo.ElementAt(j).Key, intersections));
                    }
                }
                var Ginters = Gintersections.Distinct().ToList();
                CorrespIntersec.Add(spaceInfoItem.Key, Ginters);
                i += 1;
            }
            return(new Tuple <XYZ, XYZ>(bStartingP, bEndingP));
        }
Example #3
0
        /// <summary>
        /// Creates boundaries for masking region based on the room boundaries. the
        /// inner loop is the interior elevation boundary, the outside loop is offset by 6 inches
        /// </summary>
        /// <param name="intElev">interior elevation View Section</param>
        /// <returns>2 sets of curve loops to use as boundaries for creating a masking region</returns>
        public List <CurveLoop> FilledRegionBoundary(ViewSection intElev)
        {
            BoundingBoxXYZ iecb = intElev.CropBox;

            XYZ cbboundsmin = iecb.get_Bounds(0);
            XYZ cbboundsmax = iecb.get_Bounds(1);

            double[][] transform = Matrix.transform2matrix(iecb.Transform);
            double[][] inverse   = Matrix.invert(transform);

            //inside boundary

            XYZ roombb1 = new XYZ(
                cbboundsmin.X + 1,
                cbboundsmin.Y + 1,
                cbboundsmin.Z
                );
            XYZ roombb2 = new XYZ(
                cbboundsmin.X + 1,
                cbboundsmax.Y - 1,
                cbboundsmin.Z
                );
            XYZ roombb3 = new XYZ(
                cbboundsmax.X - 1,
                cbboundsmax.Y - 1,
                cbboundsmin.Z
                );
            XYZ roombb4 = new XYZ(
                cbboundsmax.X - 1,
                cbboundsmin.Y + 1,
                cbboundsmin.Z
                );

            XYZ roombb1T = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(roombb1))) + iecb.Transform.Origin;
            XYZ roombb2T = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(roombb2))) + iecb.Transform.Origin;
            XYZ roombb3T = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(roombb3))) + iecb.Transform.Origin;
            XYZ roombb4T = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(roombb4))) + iecb.Transform.Origin;

            Line li0 = Line.CreateBound(roombb4T, roombb1T);
            Line li1 = Line.CreateBound(roombb1T, roombb2T);
            Line li2 = Line.CreateBound(roombb2T, roombb3T);
            Line li3 = Line.CreateBound(roombb3T, roombb4T);

            IList <Curve> insidecurves = new List <Curve>()
            {
                li0,
                li1,
                li2,
                li3
            };

            XYZ roombbout1 = new XYZ(
                cbboundsmin.X - 0.5,
                cbboundsmin.Y - 0.5,
                cbboundsmin.Z
                );
            XYZ roombbout2 = new XYZ(
                cbboundsmin.X - 0.5,
                cbboundsmax.Y + 0.5,
                cbboundsmin.Z
                );
            XYZ roombbout3 = new XYZ(
                cbboundsmax.X + 0.5,
                cbboundsmax.Y + 0.5,
                cbboundsmin.Z
                );
            XYZ roombbout4 = new XYZ(
                cbboundsmax.X + 0.5,
                cbboundsmin.Y - 0.5,
                cbboundsmin.Z
                );

            XYZ roombbout1T = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(roombbout1))) + iecb.Transform.Origin;
            XYZ roombbout2T = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(roombbout2))) + iecb.Transform.Origin;
            XYZ roombbout3T = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(roombbout3))) + iecb.Transform.Origin;
            XYZ roombbout4T = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(roombbout4))) + iecb.Transform.Origin;

            Line lo0 = Line.CreateBound(roombbout4T, roombbout1T);
            Line lo1 = Line.CreateBound(roombbout1T, roombbout2T);
            Line lo2 = Line.CreateBound(roombbout2T, roombbout3T);
            Line lo3 = Line.CreateBound(roombbout3T, roombbout4T);

            IList <Curve> outsidecurves = new List <Curve>()
            {
                lo0,
                lo1,
                lo2,
                lo3
            };

            //boundaries
            CurveLoop        inside       = CurveLoop.Create(insidecurves);
            CurveLoop        outside      = CurveLoop.Create(outsidecurves);
            List <CurveLoop> frBoundaries = new List <CurveLoop>()
            {
                inside,
                outside
            };

            return(frBoundaries);
        }
Example #4
0
        /// <summary>
        /// Sets the interior elevation view's cropbox based on the room's bounding box
        /// </summary>
        /// <param name="intElev">Interior Elevations</param>
        /// <param name="r">room</param>
        /// <returns>room bounding box</returns>
        public void SetCropBox(ViewSection intElev, Room r, XYZ markerPosition)
        {
            BoundingBoxXYZ iecb        = intElev.CropBox;
            XYZ            cbboundsmin = iecb.get_Bounds(0);
            XYZ            cbboundsmax = iecb.get_Bounds(1);

            Debug("room " + r.Name + r.Number);
            Debug("cbboundsmin " + cbboundsmin);
            Debug("cbboundsmax " + cbboundsmax);

            Debug("cb origin " + iecb.Transform.Origin);

            iecb.Transform.Origin = markerPosition;
            Debug("cb origin reset 1 " + iecb.Transform.Origin);

            BoundingBoxXYZ rbb    = r.get_BoundingBox(null);
            XYZ            rbbmin = rbb.get_Bounds(0);
            XYZ            rbbmax = rbb.get_Bounds(1);

            Debug("rbbmin " + rbbmin);
            Debug("rbbmax " + rbbmax);

            Debug("rbb origin " + rbb.Transform.Origin);

            double[][] transform = Matrix.transform2matrix(iecb.Transform);

            double centerOffsetX = markerPosition.X - iecb.Transform.Origin.X;
            double centerOffsetY = markerPosition.Y - iecb.Transform.Origin.Y;

            XYZ offsetVector = new XYZ(
                centerOffsetX,
                centerOffsetY,
                0);

            double[] offsetMatrix  = Matrix.xyz2matrix(offsetVector);
            double[] offsetTMatrix = Matrix.dot(transform, offsetMatrix);
            XYZ      offsetT       = new XYZ(
                offsetTMatrix[0],
                offsetTMatrix[1],
                offsetTMatrix[2]);

            //double[] minXMatrix = Matrix.xyz2matrix(new XYZ(cbboundsmin.X, 0, 0));
            //double[] maxXMatrix = Matrix.xyz2matrix(new XYZ(cbboundsmax.X, 0, 0));
            //double[] minXTMatrix = Matrix.dot(transform, minXMatrix);
            //double[] maxXTMatrix = Matrix.dot(transform, maxXMatrix);

            double transformangle  = Math.Atan2(offsetVector.Y, offsetVector.X);
            double transformangle2 = Math.Acos(transform[0][0]);

            Debug("transformangle " + transformangle + ", " + (transformangle * 180 / Math.PI));
            Debug("transformangle2 " + transformangle2 + ", " + (transformangle2 * 180 / Math.PI));

            double transformanglePos = transformangle < 0 ? Math.PI + transformangle : transformangle;

            int transformangleRounded = (int)(Math.Round(transformanglePos * 100));

            Debug("transformangleRounded " + transformangleRounded);

            var segments = r.GetBoundarySegments(new SpatialElementBoundaryOptions()).FirstOrDefault();

            if (segments == null)
            {
                Debug("null segments");
                return;
            }

            double wallLength = 4;

            foreach (var s in segments)
            {
                var c   = s.GetCurve();
                var ep1 = c.GetEndPoint(0);
                var ep2 = c.GetEndPoint(1);

                double rise = ep2.Y - ep1.Y;
                double run  = ep2.X - ep1.X;

                double angle    = Math.Atan2(rise, run);
                double anglePos = angle < 0 ? Math.PI + angle : angle;

                int angleRounded = (int)(Math.Round(anglePos * 100));

                double length = Math.Sqrt(Math.Pow(rise, 2) + Math.Pow(run, 2));

                if (angleRounded == transformangleRounded && length > wallLength)
                {
                    wallLength = length;
                    Debug("selected wallLength " + wallLength);
                }

                Debug("angle " + angle + ", " + (angle * 180 / Math.PI));
                Debug("angleRounded " + angleRounded);
                Debug("length " + length);
            }

            Debug("centerOffset v " + offsetVector);
            Debug("centerOffset vT " + offsetT);

            Debug("wallLength " + wallLength);

            XYZ newcbmin = new XYZ(
                offsetT.X - wallLength / 2 - 1,
                rbbmin.Z - 1,
                cbboundsmin.Z);

            XYZ newcbmax = new XYZ(
                offsetT.X + wallLength / 2 + 1,
                rbbmax.Z + 1,
                cbboundsmax.Z);



            iecb.set_Bounds(0, newcbmin);
            iecb.set_Bounds(1, newcbmax);

            Debug("reset bounds 0 " + iecb.get_Bounds(0));
            Debug("reset bounds 1 " + iecb.get_Bounds(1));

            intElev.CropBox        = iecb;
            intElev.CropBoxVisible = false;

            Debug("cb origin reset 2 " + iecb.Transform.Origin);
        }
Example #5
0
        public BoundingBoxXYZ SetCropBox(ViewSection intElev, Room r)
        {
            BoundingBoxXYZ iecb        = intElev.CropBox;
            XYZ            cbboundsmin = iecb.get_Bounds(0);
            XYZ            cbboundsmax = iecb.get_Bounds(1);

            BoundingBoxXYZ rbb    = r.get_BoundingBox(null);
            XYZ            rbbmin = rbb.get_Bounds(0);
            XYZ            rbbmax = rbb.get_Bounds(1);

            double[][] transform = Matrix.transform2matrix(iecb.Transform);

            XYZ rbbmintransformed = new XYZ
                                    (
                rbbmin.X * transform[0][0] + rbbmin.Y * transform[0][1] + rbbmin.Z * transform[0][2],
                rbbmin.X * transform[1][0] + rbbmin.Y * transform[1][1] + rbbmin.Z * transform[1][2],
                rbbmin.X * transform[2][0] + rbbmin.Y * transform[2][1] + rbbmin.Z * transform[2][2]
                                    );

            XYZ rbbmaxtransformed = new XYZ
                                    (
                rbbmax.X * transform[0][0] + rbbmax.Y * transform[0][1] + rbbmax.Z * transform[0][2],
                rbbmax.X * transform[1][0] + rbbmax.Y * transform[1][1] + rbbmax.Z * transform[1][2],
                rbbmax.X * transform[2][0] + rbbmax.Y * transform[2][1] + rbbmax.Z * transform[2][2]
                                    );

            double minX = rbbmintransformed.X < rbbmaxtransformed.X ? rbbmintransformed.X : rbbmaxtransformed.X;
            double minY = rbbmintransformed.Y < rbbmaxtransformed.Y ? rbbmintransformed.Y : rbbmaxtransformed.Y;

            double maxX = rbbmintransformed.X > rbbmaxtransformed.X ? rbbmintransformed.X : rbbmaxtransformed.X;
            double maxY = rbbmintransformed.Y > rbbmaxtransformed.Y ? rbbmintransformed.Y : rbbmaxtransformed.Y;

            XYZ rbbboundsmin = new XYZ(
                minX,
                minY,
                cbboundsmin.Z);
            XYZ rbbboundsmax = new XYZ(
                maxX,
                maxY,
                cbboundsmax.Z);


            BoundingBoxXYZ rbbtransformed = new BoundingBoxXYZ();

            rbbtransformed.set_Bounds(0, rbbboundsmin);
            rbbtransformed.set_Bounds(1, rbbboundsmax);


            XYZ rbbboundsminextended = new XYZ(
                minX - 1,
                minY - 1,
                cbboundsmin.Z);
            XYZ rbbboundsmaxextended = new XYZ(
                maxX + 1,
                maxY + 1,
                cbboundsmax.Z);


            intElev.CropBox.Min = rbbboundsminextended;
            intElev.CropBox.Max = rbbboundsmaxextended;
            iecb.set_Bounds(0, rbbboundsminextended);
            iecb.set_Bounds(1, rbbboundsmaxextended);
            intElev.CropBox        = iecb;
            intElev.CropBoxVisible = false;

            return(rbb);
        }