Esempio n. 1
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected override void Create(Document doc)
        {
            DirectShapeType shapeType = Importer.TheCache.UseElementByGUID <DirectShapeType>(doc, GlobalId);

            if (shapeType == null)
            {
                shapeType = IFCElementUtil.CreateElementType(doc, GetVisibleName(), CategoryId, Id, GlobalId, EntityType);
            }
            else
            {
                // If we used the element from the cache, we want to make sure that the IFCRepresentationMap can access it
                // instead of creating a new element.
                Importer.TheCache.CreatedDirectShapeTypes[Id] = shapeType.Id;
                shapeType.SetShape(new List <GeometryObject>());
            }

            if (shapeType == null)
            {
                throw new InvalidOperationException("Couldn't create DirectShapeType for IfcTypeObject.");
            }

            CreatedElementId = shapeType.Id;

            base.Create(doc);

            TraverseSubElements(doc);
        }
Esempio n. 2
0
 /// <summary>
 /// Set the plan view representation of the given DirectShape or DirectShapeType given the information created by AddPlanViewCurves.
 /// </summary>
 /// <param name="shape">The DirectShape or DirectShapeType.</param>
 public void SetPlanViewRep(Element shape)
 {
     if (m_ViewShapeBuilder != null)
     {
         if (shape is DirectShape)
         {
             DirectShape ds = shape as DirectShape;
             ds.SetShape(m_ViewShapeBuilder);
         }
         else if (shape is DirectShapeType)
         {
             DirectShapeType dst = shape as DirectShapeType;
             dst.SetShape(m_ViewShapeBuilder);
         }
         else
         {
             throw new ArgumentException("SetPlanViewRep only works on DirectShape and DirectShapeType.");
         }
     }
 }
Esempio n. 3
0
        private static void CreateDirectShape(Document doc, IList <GeometryObject> geometry)
        {
            DirectShapeLibrary directShapeLibrary = DirectShapeLibrary.GetDirectShapeLibrary(doc);
            DirectShapeType    directShapeType    = DirectShapeType.Create(doc, "NavisWorksShape", new ElementId(BuiltInCategory.OST_GenericModel));

            directShapeType.SetShape(geometry);
            directShapeLibrary.AddDefinitionType("NavisWorksShape", directShapeType.Id);

            DirectShape ds = DirectShape.CreateElementInstance(doc, directShapeType.Id, directShapeType.Category.Id, "NavisWorksShape", Transform.Identity);

            ds.SetTypeId(directShapeType.Id);
            ds.ApplicationId     = Assembly.GetExecutingAssembly().GetType().GUID.ToString();
            ds.ApplicationDataId = Guid.NewGuid().ToString();

            DirectShapeOptions dsOptions = ds.GetOptions();

            dsOptions.ReferencingOption = DirectShapeReferencingOption.Referenceable;
            ds.SetOptions(dsOptions);

            ds.SetShape(geometry);
        }
Esempio n. 4
0
        /// <summary>
        /// Create geometry for a particular representation map.
        /// </summary>
        /// <param name="shapeEditScope">The geometry creation scope.</param>
        /// <param name="lcs">Local coordinate system for the geometry, without scale.</param>
        /// <param name="scaledLcs">Local coordinate system for the geometry, including scale, potentially non-uniform.</param>
        /// <remarks>For this function, if lcs is null, we will create a library item for the geometry.</remarks>
        public void CreateShape(IFCImportShapeEditScope shapeEditScope, Transform lcs, Transform scaledLcs, string guid)
        {
            bool creatingLibraryDefinition = (lcs == null);

            if (MappedRepresentation != null)
            {
                // Look for cached shape; if found, return.
                if (creatingLibraryDefinition)
                {
                    if (IFCImportFile.TheFile.ShapeLibrary.FindDefinitionType(Id.ToString()) != ElementId.InvalidElementId)
                    {
                        return;
                    }
                }

                Transform mappingTransform = null;
                if (lcs == null)
                {
                    mappingTransform = MappingOrigin;
                }
                else
                {
                    if (MappingOrigin == null)
                    {
                        mappingTransform = lcs;
                    }
                    else
                    {
                        mappingTransform = lcs.Multiply(MappingOrigin);
                    }
                }

                Transform scaledMappingTransform = null;
                if (scaledLcs == null)
                {
                    scaledMappingTransform = mappingTransform;
                }
                else
                {
                    if (MappingOrigin == null)
                    {
                        scaledMappingTransform = scaledLcs;
                    }
                    else
                    {
                        scaledMappingTransform = scaledLcs.Multiply(MappingOrigin);
                    }
                }

                int numExistingSolids = shapeEditScope.Creator.Solids.Count;
                int numExistingCurves = shapeEditScope.Creator.FootprintCurves.Count;

                MappedRepresentation.CreateShape(shapeEditScope, mappingTransform, scaledMappingTransform, guid);

                if (creatingLibraryDefinition)
                {
                    int numNewSolids = shapeEditScope.Creator.Solids.Count;
                    int numNewCurves = shapeEditScope.Creator.FootprintCurves.Count;

                    if ((numExistingSolids != numNewSolids) || (numExistingCurves != numNewCurves))
                    {
                        IList <GeometryObject> mappedSolids = new List <GeometryObject>();
                        for (int ii = numExistingSolids; ii < numNewSolids; ii++)
                        {
                            mappedSolids.Add(shapeEditScope.Creator.Solids[numExistingSolids].GeometryObject);
                            shapeEditScope.Creator.Solids.RemoveAt(numExistingSolids);
                        }

                        IList <Curve> mappedCurves = new List <Curve>();
                        for (int ii = numExistingCurves; ii < numNewCurves; ii++)
                        {
                            mappedCurves.Add(shapeEditScope.Creator.FootprintCurves[numExistingCurves]);
                            shapeEditScope.Creator.FootprintCurves.RemoveAt(numExistingCurves);
                        }
                        shapeEditScope.AddPlanViewCurves(mappedCurves, Id);

                        //IFCImportFile.TheFile.ShapeLibrary.AddDefinition(Id.ToString(), mappedItems);

                        Document        doc             = IFCImportFile.TheFile.Document;
                        DirectShapeType directShapeType = DirectShapeType.Create(doc, Id.ToString(), shapeEditScope.CategoryId);
                        directShapeType.SetShape(mappedSolids);
                        shapeEditScope.SetPlanViewRep(directShapeType);

                        IFCImportFile.TheFile.ShapeLibrary.AddDefinitionType(Id.ToString(), directShapeType.Id);
                    }
                }
            }
        }
Esempio n. 5
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp      = commandData.Application;
            UIDocument    uidoc      = uiapp.ActiveUIDocument;
            Application   app        = uiapp.Application;
            Document      doc        = uidoc.Document;
            View          activeView = doc.ActiveView;

            List <Element> col = new List <Element>();

            Reference r = uidoc.Selection.PickObject(ObjectType.Element, "Select Element");

            col.Add(doc.GetElement(r));

            Options geometryOptions = new Options();

            ElementId cat1Id = new ElementId(BuiltInCategory.OST_Walls);


            DirectShapeLibrary dsLib = DirectShapeLibrary.GetDirectShapeLibrary(doc);

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Convert elements to DirectShapes");

                foreach (Element e in col)
                {
                    GeometryElement gelt = e.get_Geometry(
                        geometryOptions);

                    if (null != gelt)
                    {
                        string appDataGUID = e.Id.ToString();

                        try
                        {
                            string          familyName = "MyFamily";
                            DirectShapeType dsType1    = DirectShapeType.Create(doc, familyName, cat1Id);
                            dsType1.SetShape(new List <GeometryObject>(gelt));
                            dsLib.AddDefinitionType(familyName, dsType1.Id);

                            Transform trs = Transform.Identity;

                            DirectShape ds1 = DirectShape.CreateElementInstance(doc, dsType1.Id, cat1Id, familyName, trs);

                            doc.Delete(e.Id);

                            TaskDialog.Show("Result", "Element Flattened");
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("Error", ex.Message);
                        }
                    }
                }
                tx.Commit();
            }

            return(Result.Succeeded);
        }