Beispiel #1
0
        /// <summary>
        /// Creates a door given its properties.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateDoor(DoorProperty properties)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            HostedProperty hp   = ConvertToHosted(properties);
            FamilyInstance door = CreateHostedElement(hp, false);

            XYZ facing = door.FacingOrientation * -1;

            facing = VectorManipulator.TransformUVinXYZ(VectorManipulator.RotateVector(facing, baseRotation));
            double angle = Math.Atan2(facing.Y, facing.X);

            if (Math.Abs(angle - DeegreToRadians(properties.Rotation)) > 0.001)
            {
                door.flipFacing();
            }

            if ((door.FacingOrientation.CrossProduct(door.HandOrientation).Z < 0) ^ properties.OpenLeft)
            {
                door.flipHand();
            }

            /*
             * double offset = GetFamilyOffset(properties.Type).U;
             * XYZ translation = door.HandOrientation * offset;
             * ElementTransformUtils.MoveElement(doc, door.Id, translation);
             */

            return(door);
        }
Beispiel #2
0
        /// <summary>
        /// Converts an Hosted object in a HostedProperty.
        /// </summary>
        private static HostedProperty ConvertToHosted(IHosted obj)
        {
            Coordinate     c  = obj.Coordinate;
            HostedProperty hp = new HostedProperty()
            {
                Coordinate = c,
                Type       = obj.Type
            };

            return(hp);
        }
Beispiel #3
0
        /// <summary>
        /// Create a hosted element on a wall.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateHostedElement(HostedProperty properties, bool correctPosition)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            // get the parameters from properties
            XYZ    point  = GetXYZFromProperties(properties.Coordinate);
            string fsName = GetFamilySymbolName(properties.Type);

            UV offset = GetFamilyOffset(properties.Type);

            offset = new UV(UnitUtils.ConvertToInternalUnits(offset.U, UnitTypeId.Meters),
                            UnitUtils.ConvertToInternalUnits(offset.V, UnitTypeId.Meters));

            FamilySymbol familySymbol = revitDB.GetFamilySymbol(fsName);

            Wall wall = FindWall(point, baseLevel);

            // get the normal wall vector
            LocationCurve wallCurve      = wall.Location as LocationCurve;
            Line          wallLine       = wallCurve.Curve as Line;
            XYZ           wallStartPoint = wallLine.GetEndPoint(0);
            XYZ           wallEndPoint   = wallLine.GetEndPoint(1);
            XYZ           wallNormal     = VectorManipulator.CalculateNormal(wallStartPoint - wallEndPoint);

            // calculates the correct direction of the instance
            XYZ insertionPoint   = VectorManipulator.GetClosesetPointInLine(point, wallLine);
            XYZ correctDirection = (point - insertionPoint).Normalize();

            // calculates instance offset
            double angle = Math.Atan2(correctDirection.Y, correctDirection.X);

            offset = VectorManipulator.RotateVector(offset, angle + baseRotation);
            point += VectorManipulator.TransformUVinXYZ(offset);

            // Creates the element
            FamilyInstance instance = doc.Create.NewFamilyInstance(point, familySymbol, wall, baseLevel,
                                                                   Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            // if the initial orientation and the correct orientation are not equal, flip the instance
            if (!wallNormal.IsAlmostEqualTo(correctDirection) && correctPosition)
            {
                instance.flipFacing();
            }

            return(instance);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a windows given its properties.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateWindow(WindowProperty properties)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            HostedProperty hp     = ConvertToHosted(properties);
            FamilyInstance window = CreateHostedElement(hp, false);

            if (window != null)
            {
                window.get_Parameter(BuiltInParameter.INSTANCE_HEAD_HEIGHT_PARAM).Set(UnitUtils.ConvertToInternalUnits(2, UnitTypeId.Meters));
            }

            return(window);
        }