示例#1
0
        /// <summary>
        /// Exports mullion.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="mullion">
        /// The mullion object.
        /// </param>
        /// <param name="geometryElement">
        /// The geometry element.
        /// </param>
        /// <param name="localPlacement">
        /// The local placement handle.
        /// </param>
        /// <param name="extraParams">
        /// The extrusion creation data.
        /// </param>
        /// <param name="setter">
        /// The IFCPlacementSetter.
        /// </param>
        /// <param name="productWrapper">
        /// The IFCProductWrapper.
        /// </param>
        public static void Export(ExporterIFC exporterIFC, Mullion mullion, GeometryElement geometryElement,
                                  IFCAnyHandle localPlacement, IFCExtrusionCreationData extraParams, IFCPlacementSetter setter, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            ElementId catId = CategoryUtil.GetSafeCategoryId(mullion);

            BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
            IFCAnyHandle        repHnd = RepresentationUtil.CreateBRepProductDefinitionShape(mullion.Document.Application, exporterIFC, mullion, catId,
                                                                                             geometryElement, bodyExporterOptions, null, extraParams);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(repHnd))
            {
                extraParams.ClearOpenings();
                return;
            }

            string       elemGUID       = ExporterIFCUtils.CreateGUID(mullion);
            IFCAnyHandle ownerHistory   = exporterIFC.GetOwnerHistoryHandle();
            string       elemObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, mullion);
            string       elemId         = NamingUtil.CreateIFCElementId(mullion);

            IFCAnyHandle mullionHnd = IFCInstanceExporter.CreateMember(file, elemGUID, ownerHistory, elemObjectType, null, elemObjectType,
                                                                       localPlacement, repHnd, elemId);

            productWrapper.AddElement(mullionHnd, setter, extraParams, LevelUtil.AssociateElementToLevel(mullion));

            PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, mullion, productWrapper);
        }
示例#2
0
        /// <summary>
        /// Create the handle corresponding to the "Axis" IfcRepresentation for a beam, if possible.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC class.</param>
        /// <param name="element">The beam element.</param>
        /// <param name="catId">The beam category id.</param>
        /// <param name="axisInfo">The optional beam axis information.</param>
        /// <param name="offsetTransform">The optional offset transform applied to the "Body" representation.</param>
        /// <param name="elevation">The optional level elevation.</param>
        /// <returns>The handle, or null if not created.</returns>
        private static IFCAnyHandle CreateBeamAxis(ExporterIFC exporterIFC, Element element, ElementId catId, BeamAxisInfo axisInfo, Transform offsetTransform, double elevation)
        {
            if (axisInfo == null)
            {
                return(null);
            }

            Curve     curve   = axisInfo.Axis;
            XYZ       projDir = axisInfo.AxisNormal;
            Transform lcs     = axisInfo.LCSAsTransform;

            string representationTypeOpt = "Curve2D"; // This is by IFC2x2+ convention.

            XYZ curveOffset = XYZ.Zero;

            if (offsetTransform != null)
            {
                curveOffset  = -(offsetTransform.Origin);
                curveOffset -= new XYZ(0, 0, elevation);
            }
            else
            {
                // Note that we do not have to have any scaling adjustment here, since the curve origin is in the
                // same internal coordinate system as the curve.
                curveOffset = -lcs.Origin;
            }

            Transform offsetLCS = new Transform(lcs);

            offsetLCS.Origin = XYZ.Zero;
            IList <IFCAnyHandle> axis_items = null;

            if (ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView)
            {
                IFCAnyHandle axisHnd = GeometryUtil.CreatePolyCurveFromCurve(exporterIFC, curve);
                axis_items = new List <IFCAnyHandle>();
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(axisHnd))
                {
                    axis_items.Add(axisHnd);
                    representationTypeOpt = "Curve3D";   // We use Curve3D for IFC4RV Axis
                }
            }
            else
            {
                IFCGeometryInfo info = IFCGeometryInfo.CreateCurveGeometryInfo(exporterIFC, offsetLCS, projDir, false);
                ExporterIFCUtils.CollectGeometryInfo(exporterIFC, info, curve, curveOffset, true);

                axis_items = info.GetCurves();
            }

            if (axis_items.Count > 0)
            {
                string       identifierOpt = "Axis"; // This is by IFC2x2+ convention.
                IFCAnyHandle axisRep       = RepresentationUtil.CreateShapeRepresentation(exporterIFC, element, catId, exporterIFC.Get3DContextHandle(identifierOpt),
                                                                                          identifierOpt, representationTypeOpt, axis_items);
                return(axisRep);
            }

            return(null);
        }
示例#3
0
        //  Check Profile-----------------------------------------------------------
        public static bool Check_Profile(Element element, Element element_link, Document doc, Document doc_link)
        {
            bool Profile_change = false;

            try
            {
                if (element.Category.Name == Source.Category_Check[4].name)
                {
                    if (ExporterIFCUtils.HasElevationProfile(element as Wall) || ExporterIFCUtils.HasElevationProfile(element_link as Wall))
                    {
                        if (string.Join(",", Support.Get_Profile(doc, element).Select(x => x.ToString())) != string.Join(",", Support.Get_Profile(doc_link, element_link).Select(x => x.ToString())))
                        {
                            Profile_change = true;
                        }
                    }
                }
                else if (element.Category.Name == Source.Category_Check[3].name)
                {
                    if (string.Join(",", Support.Get_Profile(doc, element).Select(x => x.ToString())) != string.Join(",", Support.Get_Profile(doc_link, element_link).Select(x => x.ToString())))
                    {
                        Profile_change = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(Profile_change);
        }
        /// <summary>
        /// Calculates number of risers for a stair.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            bool valid = true;

            if (m_CurrentElement != element)
            {
                double scale = exporterIFC.LinearScale;

                m_CurrentElement = element;
                if (StairsExporter.IsLegacyStairs(element))
                {
                    ExporterIFCUtils.GetLegacyStairsProperties(exporterIFC, element,
                                                               out m_NumberOfRisers, out m_NumberOfTreads,
                                                               out m_RiserHeight, out m_TreadLength, out m_TreadLengthAtInnerSide,
                                                               out m_NosingLength, out m_WaistThickness);
                    m_TreadLengthAtOffset = m_TreadLength;
                    m_WalkingLineOffset   = m_WaistThickness / 2.0;
                }
                else if (element is Stairs)
                {
                    Stairs stairs = element as Stairs;
                    m_NumberOfRisers = stairs.ActualRisersNumber;
                    m_NumberOfTreads = stairs.ActualTreadsNumber;
                    m_RiserHeight    = stairs.ActualRiserHeight * scale;
                    m_TreadLength    = stairs.ActualTreadDepth * scale;
                }
                else if (element is StairsRun)
                {
                    StairsRun     stairsRun     = element as StairsRun;
                    StairsRunType stairsRunType = stairsRun.Document.GetElement(stairsRun.GetTypeId()) as StairsRunType;
                    Stairs        stairs        = stairsRun.GetStairs();
                    StairsType    stairsType    = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;

                    m_NumberOfRisers      = stairs.ActualRisersNumber;
                    m_NumberOfTreads      = stairs.ActualTreadsNumber;
                    m_RiserHeight         = stairs.ActualRiserHeight * scale;
                    m_TreadLength         = stairs.ActualTreadDepth * scale;
                    m_TreadLengthAtOffset = m_TreadLength;
                    m_NosingLength        = stairsRunType.NosingLength * scale;
                    m_WaistThickness      = stairsRun.ActualRunWidth * scale;
                    m_WalkingLineOffset   = m_WaistThickness / 2.0;

                    double treadLengthAtInnerSide;
                    if (ParameterUtil.GetDoubleValueFromElement(stairsType,
                                                                BuiltInParameter.STAIRSTYPE_MINIMUM_TREAD_WIDTH_INSIDE_BOUNDARY, out treadLengthAtInnerSide) != null)
                    {
                        m_TreadLengthAtInnerSide = treadLengthAtInnerSide * scale;
                    }
                    else
                    {
                        m_TreadLengthAtInnerSide = 0.0;
                    }
                }
                else
                {
                    valid = false;
                }
            }
            return(valid);
        }
示例#5
0
        /// <summary>
        /// Calculates total area for a roof
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            double scale = exporterIFC.LinearScale;

            m_Area = ExporterIFCUtils.ComputeRoofProjectedArea(element) * scale * scale;
            return(m_Area > MathUtil.Eps() * MathUtil.Eps());
        }
示例#6
0
        private static Curve FindLongestCurve(Face roomFace)
        {
            Curve longestCurve = null;

            try
            {
                IList <CurveLoop> curveLoopList = roomFace.GetEdgesAsCurveLoops();

                List <Curve> outerCurves = new List <Curve>();
                IList <IList <CurveLoop> > curveLoopLoop = ExporterIFCUtils.SortCurveLoops(curveLoopList);
                foreach (IList <CurveLoop> curveLoops in curveLoopLoop)
                {
                    foreach (CurveLoop curveLoop in curveLoops)
                    {
                        if (curveLoop.IsCounterclockwise(roomFace.ComputeNormal(new UV(0, 0))))
                        {
                            foreach (Curve curve in curveLoop)
                            {
                                outerCurves.Add(curve);
                            }
                            break;
                        }
                    }
                }

                outerCurves  = outerCurves.OrderByDescending(o => o.ApproximateLength).ToList();
                longestCurve = outerCurves.First();
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(longestCurve);
        }
示例#7
0
        /// <summary>
        /// Creates IfcAxis2Placement3D object.
        /// </summary>
        /// <param name="file">
        /// The IFC file.
        /// </param>
        /// <param name="origin">
        /// The origin.
        /// </param>
        /// <param name="zDirection">
        /// The Z direction.
        /// </param>
        /// <param name="xDirection">
        /// The X direction.
        /// </param>
        /// <returns>
        /// The handle.
        /// </returns>
        public static IFCAnyHandle CreateAxis(IFCFile file, XYZ origin, XYZ zDirection, XYZ xDirection)
        {
            IFCAnyHandle direction    = null;
            IFCAnyHandle refDirection = null;
            IFCAnyHandle location     = null;

            if (origin != null)
            {
                IList <double> measure = new List <double>();
                measure.Add(origin.X); measure.Add(origin.Y); measure.Add(origin.Z);
                location = CreateCartesianPoint(file, measure);
            }
            else
            {
                location = ExporterIFCUtils.GetGlobal3DOriginHandle();
            }

            bool exportzDirectionAndxDirection = (zDirection != null && xDirection != null && (!MathUtil.IsAlmostEqual(zDirection[2], 1.0) || !MathUtil.IsAlmostEqual(xDirection[0], 1.0)));

            if (exportzDirectionAndxDirection)
            {
                IList <double> axisPts = new List <double>();
                axisPts.Add(zDirection.X); axisPts.Add(zDirection.Y); axisPts.Add(zDirection.Z);
                direction = CreateDirection(file, axisPts);
            }

            if (exportzDirectionAndxDirection)
            {
                IList <double> axisPts = new List <double>();
                axisPts.Add(xDirection.X); axisPts.Add(xDirection.Y); axisPts.Add(xDirection.Z);
                refDirection = CreateDirection(file, axisPts);
            }

            return(IFCInstanceExporter.CreateAxis2Placement3D(file, location, direction, refDirection));
        }
示例#8
0
        /// <summary>
        /// Calculates number of risers for a stair.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            bool valid = true;

            if (StairsExporter.IsLegacyStairs(element))
            {
                double riserHeight, treadLength, treadLengthAtInnerSide, nosingLength, waistThickness = 0;
                int    numberOfTreads = 0;

                ExporterIFCUtils.GetLegacyStairsProperties(exporterIFC, element,
                                                           out m_NumberOfRisers, out numberOfTreads,
                                                           out riserHeight, out treadLength, out treadLengthAtInnerSide,
                                                           out nosingLength, out waistThickness);
            }
            else if (element is Stairs)
            {
                Stairs stairs = element as Stairs;
                m_NumberOfRisers = stairs.ActualRisersNumber;
            }
            else if (element is StairsRun)
            {
                StairsRun     stairsRun     = element as StairsRun;
                StairsRunType stairsRunType = stairsRun.Document.GetElement(stairsRun.GetTypeId()) as StairsRunType;
                m_NumberOfRisers = stairsRun.ActualRisersNumber;
            }
            else
            {
                valid = false;
            }

            // Get override from parameter
            ParameterUtil.GetIntValueFromElementOrSymbol(element, "NumberOfRiser", out m_NumberOfRisers);

            return(valid);
        }
示例#9
0
            public int Compare(CurveArray x, CurveArray y)
            {
                IList <CurveLoop> curveLoopX = new List <CurveLoop> {
                    CurveArrayToCurveLoop(x)
                };
                double areaX = ExporterIFCUtils.ComputeAreaOfCurveLoops(curveLoopX);

                IList <CurveLoop> curveLoopY = new List <CurveLoop> {
                    CurveArrayToCurveLoop(y)
                };
                double areaY = ExporterIFCUtils.ComputeAreaOfCurveLoops(curveLoopY);

                if (areaX < areaY)
                {
                    return(1);
                }

                if (areaX > areaY)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            }
示例#10
0
        static private CurveLoop GetOuterCurveLoop(PlanarFace targetFace)
        {
            CurveLoop currentCurveLoop = new CurveLoop();

            if (targetFace != null)
            {
                IList <XYZ> Points = new List <XYZ>();
                IList <IList <CurveLoop> > currentListOfListOfCurveLoops = ExporterIFCUtils.SortCurveLoops(targetFace.GetEdgesAsCurveLoops());

                if (currentListOfListOfCurveLoops != null)
                {
                    if (currentListOfListOfCurveLoops.Count > 0)
                    {
                        IList <CurveLoop> currentOuterLoop = currentListOfListOfCurveLoops[0];
                        if (currentOuterLoop != null)
                        {
                            if (currentOuterLoop.Count > 0)
                            {
                                currentCurveLoop = currentOuterLoop[0];
                            }
                        }
                    }
                }
            }
            return(currentCurveLoop);
        }
示例#11
0
        public void CollectLinkInstanceInfo()
        {
            try
            {
                Parameter param = m_instance.get_Parameter(BuiltInParameter.RVT_LINK_INSTANCE_NAME);
                if (null != param)
                {
                    instanceName = param.AsString();
                }

                if (null != m_instance.GetTotalTransform())
                {
                    transformValue = m_instance.GetTotalTransform();
                }

                linkedDocument = m_instance.GetLinkDocument();
                if (null != linkedDocument)
                {
                    linkDocTitle = linkedDocument.Title;
                }

                if (null != linkedDocument)
                {
                    ifcProjectGuid = ExporterIFCUtils.CreateProjectLevelGUID(linkedDocument, IFCProjectLevelGUIDType.Project);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
示例#12
0
        /// <summary>
        /// Sets string value of a built-in parameter of an element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="builtInParameter">The built-in parameter.</param>
        /// <param name="propertyValue">The property value.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when element is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when builtInParameter in invalid.</exception>
        public static void SetStringParameter(Element element, BuiltInParameter builtInParameter, string propertyValue)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (builtInParameter == BuiltInParameter.INVALID)
            {
                throw new ArgumentException("BuiltInParameter is INVALID", "builtInParameter");
            }

            Parameter parameter = element.get_Parameter(builtInParameter);

            if (parameter != null &&
                parameter.HasValue &&
                parameter.StorageType == StorageType.String)
            {
                if (!parameter.IsReadOnly)
                {
                    parameter.Set(propertyValue);
                }
                return;
            }

            ElementId parameterId = new ElementId(builtInParameter);

            ExporterIFCUtils.AddValueString(element, parameterId, propertyValue);
        }
示例#13
0
        /// <summary>
        /// A special case function that can export a Rebar element as an IfcBuildingElementProxy for view-specific exports where the exact geometry of the rebar matters.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="rebarElement">The rebar element to be exported.</param>
        /// <param name="productWrapper">The ProductWrapper object.</param>
        /// <param name="cannotExportRebar">True if we tried to create an IFC entity but failed.</param>
        /// <returns>True if the rebar was exported here, false otherwise.</returns>
        /// <remarks>This functionality may be obsoleted in the future.</remarks>
        private static IFCAnyHandle ExportRebarAsProxyElementInView(ExporterIFC exporterIFC, Element rebarElement, ProductWrapper productWrapper, out bool cannotExportRebar)
        {
            IFCAnyHandle rebarEntity = null;

            cannotExportRebar = false;

            if (rebarElement is Rebar && ExporterCacheManager.ExportOptionsCache.FilterViewForExport != null)
            {
                // The only options handled here is IfcBuildingElementProxy.
                // Not Exported is handled previously, and ReinforcingBar vs Mesh will be handled later.
                string        ifcEnumType;
                IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, rebarElement, out ifcEnumType);

                if (exportType == IFCExportType.IfcBuildingElementProxy ||
                    exportType == IFCExportType.IfcBuildingElementProxyType)
                {
                    GeometryElement rebarGeometry = ExporterIFCUtils.GetRebarGeometry(rebarElement as Rebar, ExporterCacheManager.ExportOptionsCache.FilterViewForExport);

                    if (rebarGeometry != null)
                    {
                        rebarEntity = ProxyElementExporter.ExportBuildingElementProxy(exporterIFC, rebarElement, rebarGeometry, productWrapper);
                    }

                    cannotExportRebar = IFCAnyHandleUtil.IsNullOrHasNoValue(rebarEntity);
                }
            }

            return(rebarEntity);
        }
        /// <summary>
        /// Update the local placements of the members of an assembly relative to the assembly.
        /// </summary>
        /// <param name="exporterIFC">The ExporerIFC.</param>
        /// <param name="assemblyPlacement">The assembly local placement handle.</param>
        /// <param name="elementPlacements">The member local placement handles.</param>
        public static void SetLocalPlacementsRelativeToAssembly(ExporterIFC exporterIFC, IFCAnyHandle assemblyPlacement, ICollection <IFCAnyHandle> elementPlacements)
        {
            foreach (IFCAnyHandle elementHandle in elementPlacements)
            {
                IFCAnyHandle elementPlacement = null;
                try
                {
                    // The assembly may contain nested groups, that don't have an object placement.  In this case, continue.
                    elementPlacement = IFCAnyHandleUtil.GetObjectPlacement(elementHandle);
                }
                catch
                {
                    continue;
                }

                Transform relTrf     = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(assemblyPlacement, elementPlacement);
                Transform inverseTrf = relTrf.Inverse;

                IFCFile      file = exporterIFC.GetFile();
                IFCAnyHandle relLocalPlacement = ExporterUtil.CreateAxis2Placement3D(file, inverseTrf.Origin, inverseTrf.BasisZ, inverseTrf.BasisX);

                // NOTE: caution that old IFCAXIS2PLACEMENT3D may be unused as the new one replace it.
                // But we cannot delete it safely yet because we don't know if any handle is referencing it.
                GeometryUtil.SetRelativePlacement(elementPlacement, relLocalPlacement);

                GeometryUtil.SetPlacementRelTo(elementPlacement, assemblyPlacement);
            }
        }
示例#15
0
 /// <summary>
 /// Calculates the reference.
 /// </summary>
 /// <param name="exporterIFC">
 /// The ExporterIFC object.
 /// </param>
 /// <param name="extrusionCreationData">
 /// The IFCExtrusionCreationData.
 /// </param>
 /// <param name="element">
 /// The element to calculate the value.
 /// </param>
 /// <param name="elementType">
 /// The element type.
 /// </param>
 /// <returns>
 /// True if the operation succeed, false otherwise.
 /// </returns>
 public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
 {
     if (elementType == null)
     {
         m_ReferenceName = element.Name;
     }
     else
     {
         if (ExporterCacheManager.ExportOptionsCache.NamingOptions.UseFamilyAndTypeNameForReference || String.IsNullOrEmpty(elementType.Name))
         {
             if (!String.IsNullOrEmpty(elementType.Name))
             {
                 m_ReferenceName = String.Format("{0}:{1}", ExporterIFCUtils.GetFamilyName(elementType), element.Name);
             }
             else
             {
                 m_ReferenceName = ExporterIFCUtils.GetFamilyName(elementType);
             }
         }
         else
         {
             m_ReferenceName = elementType.Name;
         }
     }
     return(true);
 }
示例#16
0
        private static List <Face3D> Profiles_FromElevationProfile(this Wall wall)
        {
            if (wall == null)
            {
                return(null);
            }

            if (!ExporterIFCUtils.HasElevationProfile(wall))
            {
                return(null);
            }

            IList <CurveLoop> curveLoops = ExporterIFCUtils.GetElevationProfile(wall);

            if (curveLoops == null)
            {
                return(null);
            }

            List <Face3D> result = new List <Face3D>();

            foreach (CurveLoop curveLoop in curveLoops)
            {
                Polygon3D polygon3D = curveLoop.ToSAM_Polygon3D();
                if (polygon3D == null)
                {
                    continue;
                }

                result.Add(new Face3D(polygon3D));
            }

            return(result);
        }
示例#17
0
        static IFCAnyHandle CreateLocalPlacementForConnector(ExporterIFC exporterIFC, Connector connector, IFCAnyHandle elementHandle,
                                                             IFCFlowDirection flowDir)
        {
            try
            {
                IFCFile file = exporterIFC.GetFile();

                IFCAnyHandle elementPlacement = IFCAnyHandleUtil.GetObjectPlacement(elementHandle);
                Transform    origTrf          = ExporterIFCUtils.GetUnscaledTransform(exporterIFC, elementPlacement);

                Transform connectorCoordinateSystem = connector.CoordinateSystem;
                if (flowDir == IFCFlowDirection.Sink)
                {
                    // Reverse the direction of the connector.
                    connectorCoordinateSystem.BasisX = -connectorCoordinateSystem.BasisX;
                    connectorCoordinateSystem.BasisZ = -connectorCoordinateSystem.BasisZ;
                }

                Transform relTransform = origTrf.Inverse.Multiply(connectorCoordinateSystem);
                XYZ       scaledOrigin = UnitUtil.ScaleLength(relTransform.Origin);

                IFCAnyHandle relLocalPlacement = ExporterUtil.CreateAxis2Placement3D(file,
                                                                                     scaledOrigin, relTransform.BasisZ, relTransform.BasisX);

                return(IFCInstanceExporter.CreateLocalPlacement(file, elementPlacement, relLocalPlacement));
            }
            catch
            {
            }
            return(null);
        }
示例#18
0
        public void GetWallGrossAreaAndRollBack()
        {
            var    testModel = Utils.GetTestModel("walls.rvt");
            var    doc       = xru.OpenDoc(testModel);
            var    walls     = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements();
            var    wall      = walls[0] as Wall;
            double grossArea = 0;

            var inserts = wall.FindInserts(true, true, true, true);

            xru.Run(() =>
            {
                using (Transaction transaction = new Transaction(doc, "Temporary - only to get gross area"))
                {
                    transaction.Start();
                    foreach (ElementId insertId in inserts)
                    {
                        doc.Delete(insertId);
                    }
                    doc.Regenerate();
                    var wallFaceReference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior);
                    var face          = doc.GetElement(wallFaceReference.First()).GetGeometryObjectFromReference(wallFaceReference.First()) as PlanarFace;
                    var wallFaceEdges = face.GetEdgesAsCurveLoops();
                    grossArea         = ExporterIFCUtils.ComputeAreaOfCurveLoops(wallFaceEdges);
                    transaction.RollBack();
                }
            }, doc).Wait();



            Assert.True(grossArea > 0);
        }
示例#19
0
 /// <summary>
 /// Create a sub-element GUID for a given element, or a random GUID if element is null, or subindex is nonpositive.
 /// </summary>
 /// <param name="element">The element - null allowed.</param>
 /// <param name="subIndex">The index value - should be greater than 0.</param>
 /// <returns></returns>
 static public string CreateSubElementGUID(Element element, int subIndex)
 {
     if (element == null || subIndex <= 0)
     {
         return(CreateGUID());
     }
     return(ExporterIFCUtils.CreateSubElementGUID(element, subIndex));
 }
示例#20
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);
        }
示例#21
0
        private WallCollection GetWallInformation(UIDocument uidoc, Document revitDoc, Application app, Wall wall, WallType WallType)
        {
            Autodesk.Revit.Creation.Document    credoc = revitDoc.Create;
            Autodesk.Revit.Creation.Application creapp = app.Create;
            View view = revitDoc.ActiveView;

            ElementType type  = WallType as ElementType;
            Parameter   b     = type.get_Parameter((BuiltInParameter.WALL_ATTR_WIDTH_PARAM));
            double      width = b.AsDouble() / 2;

            IList <Reference> sideFaces = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior);

            Element e2 = revitDoc.GetElement(sideFaces[0]);

            Face face = e2.GetGeometryObjectFromReference(sideFaces[0]) as Face;

            // The normal of the wall external face.
            XYZ normal = face.ComputeNormal(new UV(0, 0));

            // Offset curve copies for visibility.
            Transform offset = Transform.CreateTranslation(width * normal);

            // If the curve loop direction is counter-
            // clockwise, change its color to RED.


            // Get edge loops as curve loops.
            IList <CurveLoop> curveLoops = face.GetEdgesAsCurveLoops();

            // ExporterIFCUtils class can also be used for
            // non-IFC purposes. The SortCurveLoops method
            // sorts curve loops (edge loops) so that the
            // outer loops come first.
            IList <IList <CurveLoop> > curveLoopLoop = ExporterIFCUtils.SortCurveLoops(curveLoops);
            List <List <Curve> >       Walls         = new List <List <Curve> >();
            WallCollection             WCCC          = new WallCollection();

            foreach (IList <CurveLoop> curveLoops2 in curveLoopLoop)
            {
                foreach (CurveLoop curveLoop2 in curveLoops2)
                {
                    // Check if curve loop is counter-clockwise.

                    CurveArray   curves = creapp.NewCurveArray();
                    List <Curve> CC     = new List <Curve>();
                    foreach (Curve curve in curveLoop2)
                    {
                        curves.Append(curve.CreateTransformed(offset));
                        CC.Add(curve.CreateTransformed(offset));
                    }
                    // Create model lines for an curve loop.
                    Walls.Add(CC);
                    WCCC.AddWall(CC);
                }
            }

            return(WCCC);
        }
示例#22
0
        private static IFCAnyHandle CopyRailingHandle(ExporterIFC exporterIFC, Element elem, ElementId catId, IFCAnyHandle origLocalPlacement,
                                                      IFCAnyHandle origRailing)
        {
            IFCFile file = exporterIFC.GetFile();

            IFCAnyHandle origRailingObjectPlacement = IFCAnyHandleUtil.GetInstanceAttribute(origRailing, "ObjectPlacement");
            IFCAnyHandle railingRelativePlacement   = IFCAnyHandleUtil.GetInstanceAttribute(origRailingObjectPlacement, "RelativePlacement");
            IFCAnyHandle parentRelativePlacement    = IFCAnyHandleUtil.GetInstanceAttribute(origLocalPlacement, "RelativePlacement");

            IFCAnyHandle newRelativePlacement = null;
            IFCAnyHandle parentRelativeOrig   = IFCAnyHandleUtil.GetInstanceAttribute(parentRelativePlacement, "Location");

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(parentRelativeOrig))
            {
                IList <double> parentVec           = IFCAnyHandleUtil.GetCoordinates(parentRelativeOrig);
                IFCAnyHandle   railingRelativeOrig = IFCAnyHandleUtil.GetInstanceAttribute(railingRelativePlacement, "Location");
                if (!IFCAnyHandleUtil.IsNullOrHasNoValue(railingRelativeOrig))
                {
                    IList <double> railingVec = IFCAnyHandleUtil.GetCoordinates(railingRelativeOrig);

                    IList <double> newMeasure = new List <double>();
                    newMeasure.Add(railingVec[0] - parentVec[0]);
                    newMeasure.Add(railingVec[1] - parentVec[1]);
                    newMeasure.Add(railingVec[2]);

                    IFCAnyHandle locPtHnd = ExporterUtil.CreateCartesianPoint(file, newMeasure);
                    newRelativePlacement = IFCInstanceExporter.CreateAxis2Placement3D(file, locPtHnd, null, null);
                }
                else
                {
                    IList <double> railingMeasure = new List <double>();
                    railingMeasure.Add(-parentVec[0]);
                    railingMeasure.Add(-parentVec[1]);
                    railingMeasure.Add(0.0);
                    IFCAnyHandle locPtHnd = ExporterUtil.CreateCartesianPoint(file, railingMeasure);
                    newRelativePlacement = IFCInstanceExporter.CreateAxis2Placement3D(file, locPtHnd, null, null);
                }
            }

            IFCAnyHandle newLocalPlacement = IFCInstanceExporter.CreateLocalPlacement(file, origLocalPlacement, newRelativePlacement);
            IFCAnyHandle origRailingRep    = IFCAnyHandleUtil.GetInstanceAttribute(origRailing, "Representation");
            IFCAnyHandle newProdRep        = ExporterUtil.CopyProductDefinitionShape(exporterIFC, elem, catId, origRailingRep);

            string         ifcEnumTypeAsString = IFCAnyHandleUtil.GetEnumerationAttribute(origRailing, "PredefinedType");
            IFCRailingType railingType         = GetIFCRailingTypeFromString(ifcEnumTypeAsString);

            string       copyGUID         = ExporterIFCUtils.CreateGUID();
            IFCAnyHandle copyOwnerHistory = IFCAnyHandleUtil.GetInstanceAttribute(origRailing, "OwnerHistory");
            string       copyName         = IFCAnyHandleUtil.GetStringAttribute(origRailing, "Name");
            string       copyDescription  = IFCAnyHandleUtil.GetStringAttribute(origRailing, "Description");
            string       copyObjectType   = IFCAnyHandleUtil.GetStringAttribute(origRailing, "ObjectType");
            string       copyElemId       = IFCAnyHandleUtil.GetStringAttribute(origRailing, "Tag");

            return(IFCInstanceExporter.CreateRailing(file, copyGUID, copyOwnerHistory, copyName, copyDescription, copyObjectType,
                                                     newLocalPlacement, newProdRep,
                                                     copyElemId, railingType));
        }
示例#23
0
        /// <summary>
        /// Exports a roof to IfcRoof.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="roof">The roof element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The IFCProductWrapper.</param>
        public static void Export(ExporterIFC exporterIFC, RoofBase roof, GeometryElement geometryElement, IFCProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                // export parts or not
                bool exportParts = PartExporter.CanExportParts(roof);
                bool exportAsExtrusionCurtainRoof = false;
                bool exportAsFootprintCurtainRoof = false;
                if (roof is ExtrusionRoof)
                {
                    ExtrusionRoof extrusionRoof = roof as ExtrusionRoof;
                    exportAsExtrusionCurtainRoof = ((extrusionRoof.CurtainGrids != null) && (extrusionRoof.CurtainGrids.Size != 0));
                }
                else if (roof is FootPrintRoof)
                {
                    FootPrintRoof footprintRoof = roof as FootPrintRoof;
                    exportAsFootprintCurtainRoof = ((footprintRoof.CurtainGrids != null) && (footprintRoof.CurtainGrids.Size != 0));
                }

                if (exportParts)
                {
                    if (!PartExporter.CanExportElementInPartExport(roof, roof.Level.Id, false))
                    {
                        return;
                    }
                    ExportRoofAsParts(exporterIFC, roof, geometryElement, productWrapper); // Right now, only flat roof could have parts.
                }
                else if (exportAsExtrusionCurtainRoof)
                {
                    CurtainSystemExporter.ExportExtrusionRoof(exporterIFC, roof as ExtrusionRoof, productWrapper);
                }
                else if (exportAsFootprintCurtainRoof)
                {
                    CurtainSystemExporter.ExportFootPrintRoof(exporterIFC, roof as FootPrintRoof, productWrapper);
                }
                else
                {
                    string ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, roof);

                    IFCAnyHandle roofHnd = ExporterIFCUtils.ExportRoofAsContainer(exporterIFC, ifcEnumType, roof,
                                                                                  geometryElement, productWrapper);
                    if (IFCAnyHandleUtil.IsNullOrHasNoValue(roofHnd))
                    {
                        ExportRoof(exporterIFC, ifcEnumType, roof, geometryElement, productWrapper);
                    }

                    PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, roof, productWrapper);

                    // call for host objects; curtain roofs excused from call (no material information)
                    HostObjectExporter.ExportHostObjectMaterials(exporterIFC, roof, productWrapper.GetAnElement(),
                                                                 geometryElement, productWrapper, ElementId.InvalidElementId, IFCLayerSetDirection.Axis3);
                }
                tr.Commit();
            }
        }
示例#24
0
        /// <summary>
        /// Creates a Project, Site, or Building GUID.  If a shared parameter is set with a valid IFC GUID value,
        /// that value will override the default one.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="guidType">The GUID being created.</param>
        /// <returns>The IFC GUID value.</returns>
        /// <remarks>For Sites, the user should only use this routine if there is no Site element in the file.  Otherwise, they
        /// should use CreateSiteGUID below, which takes an Element pointer.</remarks>
        static public string CreateProjectLevelGUID(Document document, IFCProjectLevelGUIDType guidType)
        {
            string      parameterName = "Ifc" + guidType.ToString() + " GUID";
            ProjectInfo projectInfo   = document.ProjectInformation;

            BuiltInParameter parameterId = BuiltInParameter.INVALID;

            switch (guidType)
            {
            case IFCProjectLevelGUIDType.Building:
                parameterId = BuiltInParameter.IFC_BUILDING_GUID;
                break;

            case IFCProjectLevelGUIDType.Project:
                parameterId = BuiltInParameter.IFC_PROJECT_GUID;
                break;

            case IFCProjectLevelGUIDType.Site:
                parameterId = BuiltInParameter.IFC_SITE_GUID;
                break;

            default:
                // This should eventually log an error.
                return(null);
            }

            if (projectInfo != null)
            {
                string paramValue = null;
                ParameterUtil.GetStringValueFromElement(projectInfo, parameterName, out paramValue);
                if (!IsValidIFCGUID(paramValue) && parameterId != BuiltInParameter.INVALID)
                {
                    ParameterUtil.GetStringValueFromElement(projectInfo, parameterId, out paramValue);
                }

                if (IsValidIFCGUID(paramValue))
                {
                    return(paramValue);
                }
            }

            // Only for 2022
            //ElementId projectLevelElementId = new ElementId((int)guidType);
            //System.Guid guid = ExportUtils.GetExportId(document, projectLevelElementId);
            //string ifcGUID = ConvertToIFCGuid(guid);
            string ifcGUID = ExporterIFCUtils.CreateProjectLevelGUID(document, guidType);

            if ((projectInfo != null) && ExporterCacheManager.ExportOptionsCache.GUIDOptions.StoreIFCGUID)
            {
                if (parameterId != BuiltInParameter.INVALID)
                {
                    ExporterCacheManager.GUIDsToStoreCache[new KeyValuePair <ElementId, BuiltInParameter>(projectInfo.Id, parameterId)] = ifcGUID;
                }
            }
            return(ifcGUID);
        }
        /// <summary>
        /// Calculates number of risers for a stair.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType, EntryMap entryMap)
        {
            bool valid = true;

            if (StairsExporter.IsLegacyStairs(element))
            {
                double riserHeight, treadLength, nosingLength, waistThickness = 0;
                int    numberOfRisers, numberOfTreads = 0;
                ExporterIFCUtils.GetLegacyStairsProperties(exporterIFC, element,
                                                           out numberOfRisers, out numberOfTreads,
                                                           out riserHeight, out treadLength, out m_TreadLengthAtInnerSide,
                                                           out nosingLength, out waistThickness);
            }
            else if (element is Stairs || element is StairsRun)
            {
                Stairs stairs;
                if (element is StairsRun)
                {
                    StairsRun stairsRun = element as StairsRun;
                    stairs = stairsRun.GetStairs();
                }
                else
                {
                    stairs = element as Stairs;
                }

                StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;

                double treadLengthAtInnerSide;
                if (ParameterUtil.GetDoubleValueFromElement(stairsType,
                                                            BuiltInParameter.STAIRSTYPE_MINIMUM_TREAD_WIDTH_INSIDE_BOUNDARY, out treadLengthAtInnerSide) != null)
                {
                    m_TreadLengthAtInnerSide = UnitUtil.ScaleLength(treadLengthAtInnerSide);
                }

                if (m_TreadLengthAtInnerSide <= 0)
                {
                    m_TreadLengthAtInnerSide = UnitUtil.ScaleLength(stairs.ActualTreadDepth);
                }
            }
            else
            {
                valid = false;
            }

            // Get override from parameter
            double treadLengthAtInnerSideOverride = 0.0;

            if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, entryMap.RevitParameterName, out treadLengthAtInnerSideOverride) != null ||
                ParameterUtil.GetDoubleValueFromElementOrSymbol(element, entryMap.CompatibleRevitParameterName, out treadLengthAtInnerSideOverride) != null)
            {
                m_TreadLengthAtInnerSide = UnitUtil.ScaleArea(treadLengthAtInnerSideOverride);
            }

            return(valid);
        }
示例#26
0
        /// <summary>
        /// Gets the GUID for the IFC entity type handle associated with an element.
        /// </summary>
        /// <param name="familyInstance">The family instance, if it exists.</param>
        /// <param name="elementType">The element type to use for GUID generation if the family instance is null.</param>
        /// <returns>The GUID.</returns>
        public static string GetGUIDForFamilySymbol(FamilyInstance familyInstance, ElementType elementType)
        {
            if (familyInstance != null)
            {
                FamilySymbol originalFamilySymbol = ExporterIFCUtils.GetOriginalSymbol(familyInstance);
                return(GUIDUtil.CreateGUID(originalFamilySymbol));
            }

            return(GUIDUtil.CreateGUID(elementType));
        }
示例#27
0
        /// <summary>
        /// Calculates extend to structure value for a wall.
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element,">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            Wall wall = element as Wall;

            if (wall != null)
            {
                m_ExtendToStructure = ExporterIFCUtils.IsWallJoinedToTop(wall);
            }
            return(true);
        }
示例#28
0
        /// <summary>
        ///    Obtains the handle to an alternate local placement for a room-related element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="placementToUse">The handle to the IfcLocalPlacement to use for the given room-related element.</param>
        /// <returns>
        ///    The id of the spatial element related to the element.  InvalidElementId if the element
        ///    is not room-related, in which case the output will contain the placement handle from
        ///    LocalPlacement.
        /// </returns>
        public ElementId UpdateRoomRelativeCoordinates(Element elem, out IFCAnyHandle placement)
        {
            placement = m_LocalPlacement;
            FamilyInstance famInst = elem as FamilyInstance;

            if (famInst == null)
            {
                return(ElementId.InvalidElementId);
            }

            Element roomOrSpace = null;

            if (roomOrSpace == null)
            {
                try
                {
                    roomOrSpace = ExporterCacheManager.SpaceInfoCache.ContainsRooms ? famInst.get_Room(ExporterCacheManager.ExportOptionsCache.ActivePhaseElement) : null;
                }
                catch
                {
                    roomOrSpace = null;
                }
            }

            if (roomOrSpace == null)
            {
                try
                {
                    roomOrSpace = ExporterCacheManager.SpaceInfoCache.ContainsSpaces ? famInst.get_Space(ExporterCacheManager.ExportOptionsCache.ActivePhaseElement) : null;
                }
                catch
                {
                    roomOrSpace = null;
                }
            }

            if (roomOrSpace == null || roomOrSpace.Location == null)
            {
                return(ElementId.InvalidElementId);
            }

            ElementId    roomId  = roomOrSpace.Id;
            IFCAnyHandle roomHnd = ExporterCacheManager.SpaceInfoCache.FindSpaceHandle(roomId);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(roomHnd))
            {
                return(ElementId.InvalidElementId);
            }

            IFCAnyHandle roomPlacementHnd = IFCAnyHandleUtil.GetObjectPlacement(roomHnd);
            Transform    trf = ExporterIFCUtils.GetRelativeLocalPlacementOffsetTransform(placement, roomPlacementHnd);

            placement = ExporterUtil.CreateLocalPlacement(m_ExporterIFC.GetFile(), roomPlacementHnd, trf.Origin, trf.BasisZ, trf.BasisX);
            return(roomId);
        }
        /// <summary>
        /// Calculates total area for a roof
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            ParameterUtil.GetDoubleValueFromElementOrSymbol(element, "ProjectedArea", out m_Area);
            if (m_Area > MathUtil.Eps() * MathUtil.Eps())
            {
                return(true);
            }

            m_Area = UnitUtil.ScaleArea(ExporterIFCUtils.ComputeRoofProjectedArea(element));
            return(m_Area > MathUtil.Eps() * MathUtil.Eps());
        }
示例#30
0
 /// <summary>
 /// Returns the GUID for a storey level, depending on whether we are using R2009 GUIDs or current GUIDs.
 /// </summary>
 /// <param name="level">
 /// The level.
 /// </param>
 /// <returns>
 /// The GUID.
 /// </returns>
 public static string GetLevelGUID(Level level)
 {
     if (!ExporterCacheManager.ExportOptionsCache.Use2009BuildingStoreyGUIDs)
     {
         return(ExporterIFCUtils.CreateAlternateGUID(level));
     }
     else
     {
         return(ExporterIFCUtils.CreateGUID(level));
     }
 }