Esempio n. 1
0
        /// <summary>
        /// Exports a Rebar, AreaReinforcement or PathReinforcement to IFC ReinforcingBar.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The product wrapper.</param>
        public static void Export(ExporterIFC exporterIFC, Element element, ProductWrapper productWrapper)
        {
            ISet <IFCAnyHandle> createdRebars = null;

            if (element is Rebar)
            {
                ExportRebar(exporterIFC, element, productWrapper);
            }
            else if (element is AreaReinforcement)
            {
                AreaReinforcement areaReinforcement = element as AreaReinforcement;
                IList <ElementId> rebarIds          = areaReinforcement.GetRebarInSystemIds();

                Document doc = areaReinforcement.Document;
                foreach (ElementId id in rebarIds)
                {
                    Element rebarInSystem = doc.GetElement(id);
                    createdRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper);
                }
            }
            else if (element is PathReinforcement)
            {
                PathReinforcement pathReinforcement = element as PathReinforcement;
                IList <ElementId> rebarIds          = pathReinforcement.GetRebarInSystemIds();

                Document doc = pathReinforcement.Document;
                foreach (ElementId id in rebarIds)
                {
                    Element rebarInSystem = doc.GetElement(id);
                    createdRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper);
                }
            }

            if (createdRebars != null && createdRebars.Count > 1)
            {
                IFCFile file = exporterIFC.GetFile();
                using (IFCTransaction tr = new IFCTransaction(file))
                {
                    string       guid            = GUIDUtil.CreateGUID(element);
                    IFCAnyHandle ownerHistory    = exporterIFC.GetOwnerHistoryHandle();
                    string       revitObjectType = exporterIFC.GetFamilyName();
                    string       name            = NamingUtil.GetNameOverride(element, revitObjectType);
                    string       description     = NamingUtil.GetDescriptionOverride(element, null);
                    string       objectType      = NamingUtil.GetObjectTypeOverride(element, revitObjectType);

                    IFCAnyHandle rebarGroup = IFCInstanceExporter.CreateGroup(file, guid,
                                                                              ownerHistory, name, description, objectType);

                    productWrapper.AddElement(element, rebarGroup);

                    IFCInstanceExporter.CreateRelAssignsToGroup(file, GUIDUtil.CreateGUID(), ownerHistory,
                                                                null, null, createdRebars, null, rebarGroup);

                    tr.Commit();
                }
            }
        }
        /// <summary>
        /// Exports a Rebar, AreaReinforcement or PathReinforcement to IFC ReinforcingBar.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The product wrapper.</param>
        public static void Export(ExporterIFC exporterIFC, Element element, ProductWrapper productWrapper)
        {
            ISet <DelayedProductWrapper> createdRebars = new HashSet <DelayedProductWrapper>();

            if (element is Rebar)
            {
                createdRebars = ExportRebar(exporterIFC, element, productWrapper);
            }
            else if (element is AreaReinforcement)
            {
                AreaReinforcement areaReinforcement = element as AreaReinforcement;
                IList <ElementId> rebarIds          = areaReinforcement.GetRebarInSystemIds();

                Document doc = areaReinforcement.Document;
                foreach (ElementId id in rebarIds)
                {
                    Element rebarInSystem = doc.GetElement(id);
                    ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper);
                    if (newlyCreatedRebars != null)
                    {
                        createdRebars.UnionWith(newlyCreatedRebars);
                    }
                }
            }
            else if (element is PathReinforcement)
            {
                PathReinforcement pathReinforcement = element as PathReinforcement;
                IList <ElementId> rebarIds          = pathReinforcement.GetRebarInSystemIds();

                Document doc = pathReinforcement.Document;
                foreach (ElementId id in rebarIds)
                {
                    Element rebarInSystem = doc.GetElement(id);
                    ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper);
                    if (newlyCreatedRebars != null)
                    {
                        createdRebars.UnionWith(newlyCreatedRebars);
                    }
                }
            }
            else if (element is RebarContainer)
            {
                int            itemIndex      = 1;
                RebarContainer rebarContainer = element as RebarContainer;
                foreach (RebarContainerItem rebarContainerItem in rebarContainer)
                {
                    ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarContainerItem, rebarContainer, itemIndex, productWrapper);
                    if (newlyCreatedRebars != null)
                    {
                        itemIndex += createdRebars.Count;
                        createdRebars.UnionWith(newlyCreatedRebars);
                    }
                }
            }

            if (createdRebars != null && createdRebars.Count != 0)
            {
                string guid = GUIDUtil.CreateGUID(element);

                // Create a group to hold all of the created IFC entities, if the rebars aren't already in an assembly or a group.
                // We want to avoid nested groups of groups of rebars.
                bool relateToLevel     = true;
                bool groupRebarHandles = (createdRebars.Count != 1);
                foreach (DelayedProductWrapper delayedProductWrapper in createdRebars)
                {
                    if (ElementIsContainedInAssembly(delayedProductWrapper.RebarElement))
                    {
                        groupRebarHandles = false;
                        relateToLevel     = false;
                        break;
                    }
                }

                ISet <IFCAnyHandle> createdRebarHandles = new HashSet <IFCAnyHandle>();
                foreach (DelayedProductWrapper delayedProductWrapper in createdRebars)
                {
                    IFCAnyHandle currentRebarHandle = delayedProductWrapper.ElementHandle;
                    productWrapper.AddElement(delayedProductWrapper.RebarElement, currentRebarHandle, delayedProductWrapper.LevelInfo, null, relateToLevel);
                    createdRebarHandles.Add(currentRebarHandle);
                }

                if (createdRebars.Count > 1)
                {
                    if (groupRebarHandles)
                    {
                        // Check the intended IFC entity or type name is in the exclude list specified in the UI
                        Common.Enums.IFCEntityType elementClassTypeEnum;
                        if (Enum.TryParse <Common.Enums.IFCEntityType>("IfcGroup", out elementClassTypeEnum))
                        {
                            if (!ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                            {
                                IFCFile file = exporterIFC.GetFile();
                                using (IFCTransaction tr = new IFCTransaction(file))
                                {
                                    IFCAnyHandle ownerHistory    = ExporterCacheManager.OwnerHistoryHandle;
                                    string       revitObjectType = exporterIFC.GetFamilyName();
                                    string       name            = NamingUtil.GetNameOverride(element, revitObjectType);
                                    string       description     = NamingUtil.GetDescriptionOverride(element, null);
                                    string       objectType      = NamingUtil.GetObjectTypeOverride(element, revitObjectType);

                                    IFCAnyHandle rebarGroup = IFCInstanceExporter.CreateGroup(file, guid,
                                                                                              ownerHistory, name, description, objectType);

                                    productWrapper.AddElement(element, rebarGroup);

                                    IFCInstanceExporter.CreateRelAssignsToGroup(file, GUIDUtil.CreateGUID(), ownerHistory,
                                                                                null, null, createdRebarHandles, null, rebarGroup);

                                    tr.Commit();
                                }
                            }
                        }
                    }
                }
                else
                {
                    // We will update the GUID of the one created IfcReinforcingElement to be the element GUID.
                    // This will allow the IfcGUID parameter to be use/set if appropriate.
                    ExporterUtil.SetGlobalId(createdRebarHandles.ElementAt(0), guid);
                }
            }
        }
Esempio n. 3
0
        private void Stream( ArrayList data, PathReinforcement pathReinf )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( PathReinforcement ) ) );

              data.Add( new Snoop.Data.Object( "Path reinforcement type", pathReinf.PathReinforcementType ) );
              data.Add( new Snoop.Data.Enumerable( "Curves", pathReinf.GetCurveElementIds(), pathReinf.Document ) );

              data.Add( new Snoop.Data.CategorySeparator( "Bar Descriptions" ) );
              System.Collections.Generic.IList<ElementId> rebarIds = pathReinf.GetRebarInSystemIds();
              data.Add( new Snoop.Data.Int( "Number of RebarInSystem", rebarIds.Count ) );
              for( int i = 0; i < rebarIds.Count; i++ )
              {
            data.Add( new Snoop.Data.Object( string.Format( "RebarInSystem [{0:d}]", i ), pathReinf.Document.GetElement( rebarIds[i] ) ) );
              }
        }
Esempio n. 4
0
        /// <summary>
        /// Exports a Rebar, AreaReinforcement or PathReinforcement to IFC ReinforcingBar.
        /// </summary>
        /// <param name="exporterIFC">The exporter.</param>
        /// <param name="element">The element.</param>
        /// <param name="productWrapper">The product wrapper.</param>
        public static void Export(ExporterIFC exporterIFC, Element element, ProductWrapper productWrapper)
        {
            ISet <DelayedProductWrapper> createdRebars = new HashSet <DelayedProductWrapper>();

            // First, we will create individual rebars based on the Revit element.
            if (element is Rebar)
            {
                createdRebars = ExportRebar(exporterIFC, element, productWrapper);
            }
            else if (element is AreaReinforcement)
            {
                AreaReinforcement areaReinforcement = element as AreaReinforcement;
                IList <ElementId> rebarIds          = areaReinforcement.GetRebarInSystemIds();

                Document doc = areaReinforcement.Document;
                foreach (ElementId id in rebarIds)
                {
                    Element rebarInSystem = doc.GetElement(id);
                    ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper);
                    if (newlyCreatedRebars != null)
                    {
                        createdRebars.UnionWith(newlyCreatedRebars);
                    }
                }
            }
            else if (element is PathReinforcement)
            {
                PathReinforcement pathReinforcement = element as PathReinforcement;
                IList <ElementId> rebarIds          = pathReinforcement.GetRebarInSystemIds();

                Document doc = pathReinforcement.Document;
                foreach (ElementId id in rebarIds)
                {
                    Element rebarInSystem = doc.GetElement(id);
                    ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarInSystem, productWrapper);
                    if (newlyCreatedRebars != null)
                    {
                        createdRebars.UnionWith(newlyCreatedRebars);
                    }
                }
            }
            else if (element is RebarContainer)
            {
                int            itemIndex      = 1;
                RebarContainer rebarContainer = element as RebarContainer;
                foreach (RebarContainerItem rebarContainerItem in rebarContainer)
                {
                    ISet <DelayedProductWrapper> newlyCreatedRebars = ExportRebar(exporterIFC, rebarContainerItem, rebarContainer, itemIndex, productWrapper);
                    if (newlyCreatedRebars != null)
                    {
                        itemIndex += createdRebars.Count;
                        createdRebars.UnionWith(newlyCreatedRebars);
                    }
                }
            }

            // If we've created any rebar, we will group them below into three conceptual groups:
            // 1. One rebar that shouldn't be grouped or be in an assembly,
            //    but be directly contained in a building story.
            // 2. Rebar that are in assemblies, where the assembly is contained in a building story.
            // 3. Multiple rebar that aren't in assembles, which should both be in a group and
            //    directly contained in a building story.
            //
            // The reason for the cases above:
            // 1. Nested groups/assemblies aren't allow in IFC.  So we can only have one level.
            // 2. IfcGroups don't have level assignment.  So the individual components inside have
            //    to be directly contained in a building story.
            // 3. IfcAssemblies do have level assignment, so individual components can't be directly
            //    contained in a building story.   This does mean that rebars in assemblies may
            //    be associated with the wrong level, but that is an IFC limitation.
            if (createdRebars != null && createdRebars.Count != 0)
            {
                // Only one created element can have the consistent GUID of the main element.
                // This will be either the first created assembly or the first rebar element.
                string guid = GUIDUtil.CreateGUID(element);

                // While it seems likely that all of the rebar would have the same assembly id,
                // there's no need to assume this.  Make a map of assembly id to created rebar.
                IDictionary <ElementId, ISet <DelayedProductWrapper> > relatedRebar =
                    new Dictionary <ElementId, ISet <DelayedProductWrapper> >();
                relatedRebar[ElementId.InvalidElementId] = new HashSet <DelayedProductWrapper>();

                // Go through the created rebar and sort into buckets by assembly id.
                foreach (DelayedProductWrapper delayedProductWrapper in createdRebars)
                {
                    Element rebarElement = delayedProductWrapper.RebarElement;
                    if (rebarElement == null)
                    {
                        continue;
                    }

                    ElementId rebarAssemblyInstanceId            = rebarElement.AssemblyInstanceId;
                    ISet <DelayedProductWrapper> currentRebarSet = null;
                    if (!relatedRebar.TryGetValue(rebarAssemblyInstanceId, out currentRebarSet))
                    {
                        currentRebarSet = new HashSet <DelayedProductWrapper>();
                        relatedRebar[rebarAssemblyInstanceId] = currentRebarSet;
                    }
                    currentRebarSet.Add(delayedProductWrapper);
                }

                foreach (KeyValuePair <ElementId, ISet <DelayedProductWrapper> > relatedToAssembly in relatedRebar)
                {
                    // Ignore buckets with no items in them.
                    if (relatedToAssembly.Value.Count == 0)
                    {
                        continue;
                    }

                    // We will attach rebar to an assembly for rebar belonging to an assembly;
                    // otherwise we will create a group, assuming there are at least 2 rebar to group.
                    ElementId assemblyId    = relatedToAssembly.Key;
                    bool      hasAssemblyId = (assemblyId != ElementId.InvalidElementId);
                    bool      attachToLevel = !hasAssemblyId;

                    ISet <IFCAnyHandle> createdRebarHandles = new HashSet <IFCAnyHandle>();
                    foreach (DelayedProductWrapper delayedProductWrapper in relatedToAssembly.Value)
                    {
                        IFCAnyHandle currentRebarHandle = delayedProductWrapper.ElementHandle;
                        productWrapper.AddElement(delayedProductWrapper.RebarElement, currentRebarHandle,
                                                  delayedProductWrapper.LevelInfo, null, attachToLevel, delayedProductWrapper.ExportInfo);
                        createdRebarHandles.Add(currentRebarHandle);
                    }

                    if (hasAssemblyId)
                    {
                        ExporterCacheManager.AssemblyInstanceCache.RegisterElements(assemblyId, productWrapper);
                    }
                    else if (createdRebarHandles.Count > 1)
                    {
                        // Check the intended IFC entity or type name is in the exclude list specified in the UI
                        string rebarGUID = (guid != null) ? guid : GUIDUtil.CreateGUID();
                        CreateRebarGroup(exporterIFC, element, rebarGUID, productWrapper, createdRebarHandles);
                        guid = null;
                    }
                }

                // We will update the GUID of the one created IfcReinforcingElement to be the element GUID.
                // This will allow the IfcGUID parameter to be use/set if appropriate.
                if (createdRebars.Count == 1 && guid != null)
                {
                    ExporterUtil.SetGlobalId(createdRebars.ElementAt(0).ElementHandle, guid);
                }
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("AreeRebarMark"));
            Debug.WriteLine("Start area rebar mark");
            double offset = 0; //мм

            //собираю все элементы армирования по площади и траектории
            Document doc = commandData.Application.ActiveUIDocument.Document;
            FilteredElementCollector areas = new FilteredElementCollector(doc)
                                             .OfClass(typeof(Autodesk.Revit.DB.Structure.AreaReinforcement))
                                             .WhereElementIsNotElementType();
            FilteredElementCollector paths = new FilteredElementCollector(doc)
                                             .OfClass(typeof(Autodesk.Revit.DB.Structure.PathReinforcement))
                                             .WhereElementIsNotElementType();
            List <Element> col   = areas.Concat(paths).ToList();
            int            count = 0;

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Area rebar mark");
                //и Path, и Area попытаюсь обрабатываю в одном цикле, чтобы компактнее было
                foreach (Element rebarAreaPath in col)
                {
                    //благодаря hashset можно собрать только уникальный марки стержней
                    HashSet <string> marks           = new HashSet <string>();
                    string           rebarSystemMark = "";

                    List <ElementId> rebarIds = null;
                    List <ElementId> curveIds = null;

                    double maxZ = 0;
                    double minZ = 0;

                    if (rebarAreaPath is AreaReinforcement)
                    {
                        AreaReinforcement ar = rebarAreaPath as AreaReinforcement;
                        rebarIds = ar.GetRebarInSystemIds().ToList();
                        curveIds = ar.GetBoundaryCurveIds().ToList();

                        //определяю нижнюю и верзнюю точку зоны
                        List <double> zs = new List <double>();
                        foreach (ElementId curveId in curveIds)
                        {
                            AreaReinforcementCurve curve =
                                doc.GetElement(curveId) as AreaReinforcementCurve;

                            XYZ    start = curve.Curve.GetEndPoint(0);
                            double z1    = start.Z;
                            zs.Add(z1);

                            XYZ    end = curve.Curve.GetEndPoint(1);
                            double z2  = end.Z;
                            zs.Add(z2);
                        }

                        maxZ  = zs.Max();
                        maxZ += offset / 304.8;
                        minZ  = zs.Min();
                        minZ += offset / 304.8;
                    }

                    if (rebarAreaPath is PathReinforcement)
                    {
                        PathReinforcement pr = rebarAreaPath as PathReinforcement;
                        rebarIds = pr.GetRebarInSystemIds().ToList();

                        maxZ = pr.get_BoundingBox(doc.ActiveView).Max.Z;
                        minZ = pr.get_BoundingBox(doc.ActiveView).Min.Z;
                    }

                    //получаю общие параметры, в которые буду записывать отметку верха и низа, они должны быть заранее добавлены
                    Parameter topelev = rebarAreaPath.LookupParameter("АрмПлощ.ОтмВерха");
                    Parameter botelev = rebarAreaPath.LookupParameter("АрмПлощ.ОтмНиза");

                    if (topelev == null)
                    {
                        topelev = rebarAreaPath.LookupParameter("Рзм.ОтмВерха");
                    }
                    if (botelev == null)
                    {
                        botelev = rebarAreaPath.LookupParameter("Рзм.ОтмНиза");
                    }

                    if (topelev != null && botelev != null)
                    {
                        topelev.Set(maxZ);
                        botelev.Set(minZ);
                    }

                    //еще хочу записать в зону длину самого длинного арматурного стержня в ней
                    double length = 0;

                    //обрабатываю арматурные стержни в составе зоны
                    foreach (ElementId rebarId in rebarIds)
                    {
                        Element rebar     = doc.GetElement(rebarId);
                        string  rebarMark = rebar.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString();
                        marks.Add(rebarMark);
                        double tempLength = rebar.get_Parameter(BuiltInParameter.REBAR_ELEM_LENGTH).AsDouble();
                        if (tempLength > length)
                        {
                            length = tempLength;
                        }
                    }

                    //сортирую марки и записываю через запятую
                    List <string> marksList = marks.ToList();
                    marksList.Sort();
                    for (int i = 0; i < marks.Count; i++)
                    {
                        rebarSystemMark += marksList[i];
                        if (i < marks.Count - 1)
                        {
                            rebarSystemMark += ", ";
                        }
                    }
                    rebarAreaPath.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).Set(rebarSystemMark);

                    //записываю длину арматуры а зону
                    Parameter lengthParam = rebarAreaPath.LookupParameter("Рзм.Длина");
                    if (lengthParam != null)
                    {
                        lengthParam.Set(length);
                    }

                    count++;
                }
                t.Commit();
            }

            BalloonTip.Show("Успешно!", "Обработано зон: " + count.ToString());
            Debug.WriteLine("Success, elements: " + count.ToString());

            return(Result.Succeeded);
        }