Esempio n. 1
0
        /// <summary>
        /// Return a grid of points in the room
        /// </summary>
        /// <param name="step">Lenght between two points</param>
        public List <Point> Grid(double step)
        {
            step = UnitConverter.DynamoToHostFactor(DB.UnitType.UT_Length) * step;
            List <Point> grid = new List <Point>();

            DB.BoundingBoxXYZ bb = InternalElement.get_BoundingBox(null);

            for (double x = bb.Min.X; x < bb.Max.X;)
            {
                for (double y = bb.Min.Y; y < bb.Max.Y;)
                {
                    DB.XYZ point = new DB.XYZ(x, y, bb.Min.Z);
                    if (InternalRoom.IsPointInRoom(point))
                    {
                        grid.Add(GeometryPrimitiveConverter.ToPoint(InternalTransform.OfPoint(point)));
                    }
                    y = y + step;
                }

                x = x + step;
            }

            return(grid);
        }
Esempio n. 2
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            if (_reference.ElementReferenceType != ElementReferenceType.REFERENCE_TYPE_SURFACE &&
                _reference.ElementReferenceType != ElementReferenceType.REFERENCE_TYPE_LINEAR)
            {
                ElementId refElementId = _reference.ElementId;
                Element   refElement   = dynRevitSettings.Doc.Document.GetElement(refElementId);
                if (refElement is ReferencePoint)
                {
                    ReferencePoint rp    = refElement as ReferencePoint;
                    XYZ            rpXYZ = rp.Position;
                    return(Value.NewContainer(rpXYZ));
                }
                GeometryObject thisObjectPoint = SelectedElement.GetGeometryObjectFromReference(_reference);
                if (!(thisObjectPoint is Autodesk.Revit.DB.Point))
                {
                    throw new Exception("Could not use face or edge which is not part of the model");
                }
                var thisPoint = thisObjectPoint as Autodesk.Revit.DB.Point;
                XYZ pointXYZ  = thisPoint.Coord;
                return(Value.NewContainer(pointXYZ));
            }

            GeometryObject thisObject = SelectedElement.GetGeometryObjectFromReference(_reference);

            Autodesk.Revit.DB.Transform thisTrf = null;
            if (_init && (old_refXyz == null || !_reference.Equals(old_refXyz)))
            {
                _init = false;
            }

            {
                GeometryObject geomObj =
                    SelectedElement.get_Geometry(new Options());
                var geomElement = geomObj as GeometryElement;

                // ugly code to detect if transform for geometry object is needed or not
                // filed request to provide this info via API, but meanwhile ...
                foreach (GeometryObject geob in geomElement)
                {
                    if (!(geob is GeometryInstance))
                    {
                        continue;
                    }

                    var             ginsta           = geob as GeometryInstance;
                    GeometryElement gSymbolElement   = ginsta.GetSymbolGeometry();
                    var             geometryElements = new List <GeometryElement> {
                        gSymbolElement
                    };
                    bool found = false;
                    for (; geometryElements.Count > 0 && !found;)
                    {
                        GeometryElement thisGeometryElement = geometryElements[0];
                        geometryElements.Remove(thisGeometryElement);

                        foreach (GeometryObject geobSym in thisGeometryElement)
                        {
                            if (geobSym is GeometryElement)
                            {
                                geometryElements.Add(geobSym as GeometryElement);
                                continue;
                            }
                            if ((thisObject is Curve) && (geobSym is Curve) &&
                                (thisObject == geobSym))
                            {
                                found = true;
                                break;
                            }

                            if (thisObject is Curve)
                            {
                                continue;
                            }

                            if ((thisObject is Autodesk.Revit.DB.Face) && (geobSym is Autodesk.Revit.DB.Face) && (thisObject == geobSym))
                            {
                                found = true;
                                break;
                            }

                            if ((thisObject is Edge) && (geobSym is Autodesk.Revit.DB.Face))
                            {
                                var edge = thisObject as Edge;
                                //use GetFace after r2013 support is dropped
                                if (geobSym == edge.get_Face(0) || geobSym == edge.get_Face(1))
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (!(geobSym is Solid))
                            {
                                continue;
                            }

                            FaceArray solidFaces = ((Solid)geobSym).Faces;
                            int       numFaces   = solidFaces.Size;
                            for (int index = 0; index < numFaces && !found; index++)
                            {
                                Autodesk.Revit.DB.Face faceAt = solidFaces.get_Item(index);
                                if ((thisObject is Autodesk.Revit.DB.Face) && (thisObject == faceAt))
                                {
                                    found = true;
                                    break;
                                }
                                if (thisObject is Edge)
                                {
                                    var edge = thisObject as Edge;
                                    //use GetFace after r2013 support is dropped
                                    if (faceAt == edge.get_Face(0) || faceAt == edge.get_Face(1))
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (found)
                    {
                        thisTrf = ginsta.Transform;
                        break;
                    }
                }
                if (thisObject == null)
                {
                    throw new Exception("could not resolve reference for XYZ on Element");
                }
            }

            XYZ thisXYZ;

            if (_reference.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_SURFACE &&
                thisObject is Autodesk.Revit.DB.Face)
            {
                var face = thisObject as Autodesk.Revit.DB.Face;
                if (!_init)
                {
                    _param0 = _reference.UVPoint[0];
                    _param1 = _reference.UVPoint[1];
                    _init   = true;
                }
                var uv = new UV(_param0, _param1);
                thisXYZ = face.Evaluate(uv);
                if (thisTrf != null)
                {
                    thisXYZ = thisTrf.OfPoint(thisXYZ);
                }
            }
            else if (_reference.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_LINEAR)
            {
                Curve curve;
                if (thisObject is Edge)
                {
                    var edge = (Edge)SelectedElement.GetGeometryObjectFromReference(_reference);
                    curve = edge.AsCurve();
                }
                else
                {
                    curve = (Curve)SelectedElement.GetGeometryObjectFromReference(_reference);
                }
                if (curve != null)
                {
                    if (_init)
                    {
                        thisXYZ = curve.Evaluate(_param0, true);
                    }
                    else
                    {
                        XYZ curPoint = _reference.GlobalPoint;
                        if (thisTrf != null)
                        {
                            Autodesk.Revit.DB.Transform inverseTrf = thisTrf.Inverse;
                            curPoint = inverseTrf.OfPoint(_reference.GlobalPoint);
                        }
                        IntersectionResult thisResult = curve.Project(curPoint);
                        _param0 = curve.ComputeNormalizedParameter(thisResult.Parameter);
                        _init   = true;
                    }
                    thisXYZ = curve.Evaluate(_param0, true);
                    _param1 = -1.0;
                }
                else
                {
                    throw new Exception("could not evaluate point on face or edge of the element");
                }
                if (thisTrf != null)
                {
                    thisXYZ = thisTrf.OfPoint(thisXYZ);
                }
            }
            else
            {
                throw new Exception("could not evaluate point on face or edge of the element");
            }

            old_refXyz = _reference;

            return(Value.NewContainer(thisXYZ));
        }