Ejemplo n.º 1
0
        static public Curve GetFamilyInstanceCutBaseLine(FamilyInstance fi)
        {
            XYZ       dir;
            CurveLoop loop  = ExporterIFCUtils.GetInstanceCutoutFromWall(fi.Document, fi.Host as Wall, fi, out dir);
            Curve     curve = loop.Where(x => x.GetEndPoint(0).Z == x.GetEndPoint(1).Z).OrderBy(x => x.GetEndPoint(0).Z).FirstOrDefault();

            return(curve);
        }
        /// <summary>
        /// Creates a creator from DoorWindowInfo.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="doorWindowInfo">The DoorWindowInfo.</param>
        /// <param name="instanceHandle">The instance handle.</param>
        /// <param name="levelId">The level id.</param>
        /// <returns>The creator.</returns>
        public static DoorWindowDelayedOpeningCreator Create(ExporterIFC exporterIFC, DoorWindowInfo doorWindowInfo, IFCAnyHandle instanceHandle, ElementId levelId)
        {
            if (exporterIFC == null || doorWindowInfo == null)
            {
                return(null);
            }

            DoorWindowDelayedOpeningCreator doorWindowDelayedOpeningCreator = null;

            if (doorWindowInfo.HasRealWallHost)
            {
                Document       doc     = doorWindowInfo.HostObject.Document;
                Wall           wall    = doorWindowInfo.HostObject as Wall;
                FamilyInstance famInst = doorWindowInfo.InsertInstance;
                ElementId      hostId  = wall != null ? wall.Id : ElementId.InvalidElementId;
                ElementId      instId  = famInst != null ? famInst.Id : ElementId.InvalidElementId;

                doorWindowDelayedOpeningCreator                           = new DoorWindowDelayedOpeningCreator();
                doorWindowDelayedOpeningCreator.HostId                    = hostId;
                doorWindowDelayedOpeningCreator.InsertId                  = instId;
                doorWindowDelayedOpeningCreator.PosHingeSide              = doorWindowInfo.PosHingeSide;
                doorWindowDelayedOpeningCreator.DoorWindowHnd             = instanceHandle;
                doorWindowDelayedOpeningCreator.LevelId                   = levelId;
                doorWindowDelayedOpeningCreator.CreatedFromDoorWindowInfo = true;

                WallType wallType      = doc.GetElement(wall.GetTypeId()) as WallType;
                double   unScaledWidth = ((wallType != null) && (wallType.Kind != WallKind.Curtain)) ? wallType.Width : 0.0;
                if (!MathUtil.IsAlmostZero(unScaledWidth))
                {
                    IFCAnyHandle openingHnd = exporterIFC.GetDoorWindowOpeningHandle(instId);
                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(openingHnd))
                    {
                        XYZ       cutDir  = null;
                        CurveLoop cutLoop = null;
                        try
                        {
                            cutLoop = ExporterIFCUtils.GetInstanceCutoutFromWall(wall.Document, wall, famInst, out cutDir);
                        }
                        catch
                        {
                            cutLoop = null;
                            // Couldn't create opening for door in wall - report as error in log when we create log file.
                        }

                        if (cutLoop != null)
                        {
                            if (doorWindowDelayedOpeningCreator.ExtrusionData == null)
                            {
                                doorWindowDelayedOpeningCreator.ExtrusionData = new List <IFCExtrusionData>();
                            }

                            IFCExtrusionData extrusionData = new IFCExtrusionData();
                            extrusionData.ExtrusionDirection    = cutDir;
                            extrusionData.ScaledExtrusionLength = UnitUtil.ScaleLength(unScaledWidth);
                            extrusionData.AddLoop(cutLoop);
                            doorWindowDelayedOpeningCreator.ScaledHostWidth = UnitUtil.ScaleLength(unScaledWidth);
                            doorWindowDelayedOpeningCreator.ExtrusionData.Add(extrusionData);
                            doorWindowDelayedOpeningCreator.HasValidGeometry = true;
                        }
                        else
                        {
                            // Couldn't create opening for door in wall - report as error in log when we create log file.
                        }
                    }
                }
            }

            return(doorWindowDelayedOpeningCreator);
        }
        public double GetWallCutArea(
            FamilyInstance fi,
            Wall wall)
        {
            Document doc = fi.Document;

            XYZ cutDir = null;

            CurveLoop curveLoop
                = ExporterIFCUtils.GetInstanceCutoutFromWall(
                      fi.Document, wall, fi, out cutDir);

            IList <CurveLoop> loops = new List <CurveLoop>(1);

            loops.Add(curveLoop);

            if (!wall.IsStackedWallMember)
            {
                return(ExporterIFCUtils.ComputeAreaOfCurveLoops(loops));
            }
            else
            {
                // Will not get multiple stacked walls with
                // varying thickness due to the nature of rooms.
                // Use ReferenceIntersector if we can identify
                // those missing room faces...open for suggestions.

                SolidHandler solHandler = new SolidHandler();
                Options      optCompRef
                    = doc.Application.Create.NewGeometryOptions();
                if (null != optCompRef)
                {
                    optCompRef.ComputeReferences = true;
                    optCompRef.DetailLevel       = ViewDetailLevel.Medium;
                }

                GeometryElement geomElemHost
                    = wall.get_Geometry(optCompRef)
                      as GeometryElement;

                Solid solidOpening = GeometryCreationUtilities
                                     .CreateExtrusionGeometry(loops,
                                                              cutDir.Negate(), .1);

                Solid solidHost
                    = solHandler.CreateSolidFromBoundingBox(
                          null, geomElemHost.GetBoundingBox(), null);

                // We dont really care about the boundingbox
                // rotation as we only need the intersected solid.

                if (solidHost == null)
                {
                    return(0);
                }

                Solid intersectSolid = BooleanOperationsUtils
                                       .ExecuteBooleanOperation(solidOpening,
                                                                solidHost, BooleanOperationsType.Intersect);

                if (intersectSolid.Faces.Size.Equals(0))
                {
                    solidOpening = GeometryCreationUtilities
                                   .CreateExtrusionGeometry(loops, cutDir, .1);

                    intersectSolid = BooleanOperationsUtils
                                     .ExecuteBooleanOperation(solidOpening,
                                                              solidHost, BooleanOperationsType.Intersect);
                }

                if (DebugHandler.EnableSolidUtilityVolumes)
                {
                    using (Transaction t = new Transaction(doc))
                    {
                        t.Start("Stacked1");
                        ShapeCreator.CreateDirectShape(doc,
                                                       intersectSolid, "stackedOpening");
                        t.Commit();
                    }
                }
                return(solHandler.GetLargestFaceArea(
                           intersectSolid));
            }
        }
Ejemplo n.º 4
0
        static private void GetOpeningSize(Wall elHost, Element elInsert, out double width, out double height, out double thickness)
        {
            width     = 0;
            height    = 0;
            thickness = elHost.Width;
            if (elInsert is FamilyInstance)
            {
                FamilyInstance fi  = elInsert as FamilyInstance;
                XYZ            dir = new XYZ();
                try
                {
                    CurveLoop curve       = ExporterIFCUtils.GetInstanceCutoutFromWall(elHost.Document, elHost, fi, out dir);
                    Curve     widthCurve  = curve.Where(x => x.GetEndPoint(0).Z == x.GetEndPoint(1).Z).FirstOrDefault();
                    Curve     heightCurve = curve.Where(x => x.GetEndPoint(0).X == x.GetEndPoint(1).X&& x.GetEndPoint(0).Z != x.GetEndPoint(1).Z).FirstOrDefault();
                    width  = widthCurve != null ? widthCurve.Length : 0;
                    height = heightCurve != null ? heightCurve.Length : 0;
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                {
                    Parameter wp  = fi.LookupParameter("Ширина");
                    Parameter wpp = fi.LookupParameter("Примерная ширина");
                    Parameter hp  = fi.LookupParameter("Высота");
                    Parameter hpp = fi.LookupParameter("Примерная высота");

                    if (wp != null)
                    {
                        width = wp.AsDouble();
                    }
                    else if (wpp != null)
                    {
                        width = wpp.AsDouble();
                    }
                    else
                    {
                        width = 0;
                    }

                    if (hp != null)
                    {
                        height = hp.AsDouble();
                    }
                    else if (hpp != null)
                    {
                        height = hpp.AsDouble();
                    }
                    else
                    {
                        height = 0;
                    }
                }
            }
            else if (elInsert is Wall)
            {
                var hIns  = elInsert.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
                var hHost = elHost.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
                var l     = elInsert.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();

                if (hIns < hHost)
                {
                    width  = l;
                    height = hIns;
                }
                else
                {
                    width  = l;
                    height = hHost;
                }
            }
            else if (elInsert is Opening)
            {
                XYZ min = (elInsert as Opening).BoundaryRect[0];
                XYZ max = (elInsert as Opening).BoundaryRect[1];

                width  = min.X != max.X ? Math.Abs(max.X - min.X) : Math.Abs(max.Y - min.Y);
                height = Math.Abs(max.Z - min.Z);
            }
        }