예제 #1
0
        /// <summary>
        /// Create one or more elements
        /// </summary>
        /// <param name="doc">The document being populated.</param>
        /// <returns>The primary element associated with the IFCObjectDefinition, or InvalidElementId if it failed.</returns>
        public static ElementId CreateElement(Document doc, IFCObjectDefinition objDef)
        {
            // This would be a good place to check 'objDef.GlobalId'.

            ElementId createdElementId = objDef.CreatedElementId;

            try
            {
                if ((createdElementId == ElementId.InvalidElementId) && objDef.IsValidForCreation)
                {
                    ElementId gstyleId;
                    objDef.CategoryId        = IFCCategoryUtil.GetCategoryIdForEntity(doc, objDef, out gstyleId);
                    objDef.m_GraphicsStyleId = gstyleId;

                    if (objDef is IFCObject)
                    {
                        IFCObject asObject = objDef as IFCObject;
                        foreach (IFCTypeObject typeObject in asObject.TypeObjects)
                        {
                            IFCObjectDefinition.CreateElement(doc, typeObject);
                        }
                    }

                    objDef.Create(doc);
                    objDef.CreateParameters(doc);
                    createdElementId = objDef.CreatedElementId;
                    IFCImportFile.TheLog.AddCreatedEntity(doc, objDef);

                    if (IFCImportFile.CleanEntitiesAfterCreate)
                    {
                        objDef.CleanEntity();
                    }
                }
            }
            catch (Exception ex)
            {
                if (objDef != null)
                {
                    objDef.IsValidForCreation = false;
                    IFCImportFile.TheLog.LogCreationError(objDef, ex.Message, false);
                }
            }
            return(createdElementId);
        }
예제 #2
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected virtual void TraverseSubElements(Document doc)
        {
            IList <ElementId> subElementIds = new List <ElementId>();

            if (ComposedObjectDefinitions != null)
            {
                foreach (IFCObjectDefinition objectDefinition in ComposedObjectDefinitions)
                {
                    IFCObjectDefinition.CreateElement(doc, objectDefinition);
                    if (objectDefinition.CreatedElementId != ElementId.InvalidElementId)
                    {
                        subElementIds.Add(objectDefinition.CreatedElementId);
                    }
                }
            }

            if (GroupSubElements())
            {
                if (subElementIds.Count > 0)
                {
                    if (CreatedElementId != ElementId.InvalidElementId)
                    {
                        subElementIds.Add(CreatedElementId);
                    }

                    // We aren't yet actually grouping the elements.  DirectShape doesn't support grouping, and
                    // the Group element doesn't support adding parameters.  For now, we will create a DirectShape that "forgets"
                    // the association, which is good enough for link.
                    DirectShape directShape = IFCElementUtil.CreateElement(doc, CategoryId, Importer.ImportAppGUID(), GlobalId);
                    //Group group = doc.Create.NewGroup(subElementIds);
                    if (directShape != null)
                    {
                        CreatedElementId = directShape.Id;
                    }
                    else
                    {
                        IFCImportFile.TheLog.LogCreationError(this, null, false);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected virtual void TraverseSubElements(Document doc)
        {
            IList <ElementId> subElementIds = new List <ElementId>();

            // These two should only be populated if GroupSubElements() is true and we are duplicating geometry for containers.
            List <GeometryObject> groupedSubElementGeometries      = new List <GeometryObject>();
            List <Curve>          groupedSubElementFootprintCurves = new List <Curve>();

            if (ComposedObjectDefinitions != null)
            {
                foreach (IFCObjectDefinition objectDefinition in ComposedObjectDefinitions)
                {
                    IFCObjectDefinition.CreateElement(doc, objectDefinition);
                    if (objectDefinition.CreatedElementId != ElementId.InvalidElementId)
                    {
                        subElementIds.Add(objectDefinition.CreatedElementId);

                        // CreateDuplicateContainerGeometry is currently an API-only option (no UI), set to true by default.
                        if (GroupSubElements() && Importer.TheOptions.CreateDuplicateContainerGeometry)
                        {
                            IList <GeometryObject> subGeometries = GetOrCloneGeometry(doc, objectDefinition);
                            if (subGeometries != null)
                            {
                                groupedSubElementGeometries.AddRange(subGeometries);
                            }

                            if (objectDefinition is IFCProduct)
                            {
                                groupedSubElementFootprintCurves.AddRange((objectDefinition as IFCProduct).FootprintCurves);
                            }
                        }
                    }
                }
            }

            if (GroupSubElements())
            {
                if (subElementIds.Count > 0)
                {
                    if (CreatedElementId != ElementId.InvalidElementId)
                    {
                        subElementIds.Add(CreatedElementId);
                    }

                    // We aren't yet actually grouping the elements.  DirectShape doesn't support grouping, and
                    // the Group element doesn't support adding parameters.  For now, we will create a DirectShape that "forgets"
                    // the association, which is good enough for link.
                    DirectShape directShape = IFCElementUtil.CreateElement(doc, CategoryId, GlobalId, groupedSubElementGeometries);
                    //Group group = doc.Create.NewGroup(subElementIds);

                    if (directShape != null)
                    {
                        CreatedElementId = directShape.Id;
                        CreatedGeometry  = groupedSubElementGeometries;

                        if (groupedSubElementFootprintCurves.Count != 0 && this is IFCProduct)
                        {
                            using (IFCImportShapeEditScope planViewScope = IFCImportShapeEditScope.Create(doc, this as IFCProduct))
                            {
                                planViewScope.AddPlanViewCurves(groupedSubElementFootprintCurves, Id);
                                planViewScope.SetPlanViewRep(directShape);
                            }
                        }
                    }
                    else
                    {
                        Importer.TheLog.LogCreationError(this, null, false);
                    }
                }
            }
        }