Пример #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);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Creates a piece of furniture.
        /// </summary>
        /// <param name="properties"> Properties of the object.</param>
        private FamilyInstance CreateFurniture(FurnitureProperty properties)
        {
            if (properties is null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            // get the properties
            double rotation = DeegreToRadians(properties.Rotation);
            XYZ    p0       = GetXYZFromProperties(properties.Coordinate.ElementAt(0));
            XYZ    p1       = GetXYZFromProperties(properties.Coordinate.ElementAt(1));
            XYZ    point    = (p0 + p1) / 2;

            string fsFamilyName = GetFamilySymbolName(properties.Type);

            UV offset = GetFamilyOffset(properties.Type);

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

            offset = VectorManipulator.RotateVector(offset, rotation + baseRotation);

            // Creates a point above the furniture to serve as a rotation axis
            XYZ            axisPoint = new XYZ(point.X, point.Y, baseLevel.Elevation + 1);
            Line           axis      = Line.CreateBound(point, axisPoint);
            FamilyInstance furniture;

            try
            {
                FamilySymbol familySymbol = revitDB.GetFamilySymbol(fsFamilyName);
                Autodesk.Revit.DB.Structure.StructuralType structuralType = Autodesk.Revit.DB.Structure.StructuralType.NonStructural;
                furniture = doc.Create.NewFamilyInstance(point, familySymbol, structuralType);
                ElementTransformUtils.RotateElement(doc, furniture.Id, axis, rotation + baseRotation);
                ElementTransformUtils.MoveElement(doc, furniture.Id, VectorManipulator.TransformUVinXYZ(offset));
            }
            catch (Exception e)
            {
                throw new Exception("Erro ao inserir mobiliario \"" + fsFamilyName + "\".", e);
            }
            return(furniture);
        }