Ejemplo n.º 1
0
        public static string AddSplitLineWithElevation(global::Revit.Elements.Element roof, Curve curve, double elevation)
        {
            Autodesk.Revit.DB.Document doc          = DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.RoofBase internalRoof = (Autodesk.Revit.DB.RoofBase)roof.InternalElement;

            Point startPoint = Point.ByCoordinates(curve.StartPoint.X, curve.StartPoint.Y, elevation);
            Point endPoint   = Point.ByCoordinates(curve.EndPoint.X, curve.EndPoint.Y, elevation);

            string result;

            try
            {
                TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
                internalRoof.SlabShapeEditor.Enable();
                SlabShapeVertex vertex1 = internalRoof.SlabShapeEditor.DrawPoint(startPoint.ToXyz());
                SlabShapeVertex vertex2 = internalRoof.SlabShapeEditor.DrawPoint(endPoint.ToXyz());
                internalRoof.SlabShapeEditor.DrawSplitLine(vertex1, vertex2);
                TransactionManager.Instance.TransactionTaskDone();
                result = "Success.";
            }
            catch (Exception)
            {
                result = "not so success.";
            }

            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a Roof from a user selected Element.
 /// </summary>
 /// <param name="roof"></param>
 /// <param name="isRevitOwned"></param>
 /// <returns></returns>
 internal static Roof FromExisting(Autodesk.Revit.DB.RoofBase roof, bool isRevitOwned)
 {
     return(new Roof(roof)
     {
         IsRevitOwned = isRevitOwned
     });
 }
Ejemplo n.º 3
0
        //Nesting the various profiles into a polycurve segments
        private List <ICurve> GetProfiles(DB.RoofBase roof)
        {
            // TODO handle case if not one of our supported roofs
            var profiles = new List <ICurve>();

            switch (roof)
            {
            case FootPrintRoof footprint:
            {
                ModelCurveArrArray crvLoops = footprint.GetProfiles();

                for (var i = 0; i < crvLoops.Size; i++)
                {
                    var crvLoop = crvLoops.get_Item(i);
                    var poly    = new Polycurve(ModelUnits);
                    foreach (DB.ModelCurve curve in crvLoop)
                    {
                        if (curve == null)
                        {
                            continue;
                        }

                        var segment = CurveToSpeckle(curve.GeometryCurve) as Base; //it's a safe casting
                        segment["slopeAngle"] = GetParamValue <double>(curve, BuiltInParameter.ROOF_SLOPE);
                        segment["isSloped"]   = GetParamValue <bool>(curve, BuiltInParameter.ROOF_CURVE_IS_SLOPE_DEFINING);
                        segment["offset"]     = GetParamValue <double>(curve, BuiltInParameter.ROOF_CURVE_HEIGHT_OFFSET);
                        poly.segments.Add(segment as ICurve);

                        //roud profiles are returned duplicated!
                        if (curve is ModelArc arc && RevitVersionHelper.IsCurveClosed(arc.GeometryCurve))
                        {
                            break;
                        }
                    }
                    profiles.Add(poly);
                }

                break;
            }

            case ExtrusionRoof extrusion:
            {
                var crvloop = extrusion.GetProfile();
                var poly    = new Polycurve(ModelUnits);
                foreach (DB.ModelCurve curve in crvloop)
                {
                    if (curve == null)
                    {
                        continue;
                    }

                    poly.segments.Add(CurveToSpeckle(curve.GeometryCurve));
                }
                profiles.Add(poly);
                break;
            }
            }
            return(profiles);
        }
Ejemplo n.º 4
0
        private void AssertRoofEqual(DB.RoofBase sourceElem, DB.RoofBase destElem)
        {
            Assert.NotNull(destElem);
            Assert.Equal(sourceElem.Name, destElem.Name);

            AssertEqualParam(sourceElem, destElem, BuiltInParameter.ROOF_SLOPE);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.ROOF_BASE_LEVEL_PARAM);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The construct of the RoofItem class.
        /// </summary>
        /// <param name="roof"></param>
        public RoofItem(Autodesk.Revit.DB.RoofBase roof) : base(roof.Id.IntegerValue.ToString())
        {
            m_roof = roof;
            this.SubItems.Add(roof.Name);

            if (m_roof is Autodesk.Revit.DB.FootPrintRoof)
            {
                Parameter para = roof.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOF_BASE_LEVEL_PARAM);
                this.SubItems.Add(LevelConverter.GetLevelByID(para.AsElementId().IntegerValue).Name);
            }
            else if (m_roof is Autodesk.Revit.DB.ExtrusionRoof)
            {
                Parameter para = roof.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM);
                this.SubItems.Add(LevelConverter.GetLevelByID(para.AsElementId().IntegerValue).Name);
            }

            this.SubItems.Add(roof.RoofType.Name);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The construct of the RoofItem class.
        /// </summary>
        /// <param name="roof"></param>
        public RoofItem(Autodesk.Revit.DB.RoofBase roof)
            : base(roof.Id.IntegerValue.ToString())
        {
            m_roof = roof;
            this.SubItems.Add(roof.Name);

            if (m_roof is Autodesk.Revit.DB.FootPrintRoof)
            {
                Parameter para = roof.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOF_BASE_LEVEL_PARAM);
                this.SubItems.Add(LevelConverter.GetLevelByID(para.AsElementId().IntegerValue).Name);
            }
            else if (m_roof is Autodesk.Revit.DB.ExtrusionRoof)
            {
                Parameter para = roof.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM);
                this.SubItems.Add(LevelConverter.GetLevelByID(para.AsElementId().IntegerValue).Name);
            }

            this.SubItems.Add(roof.RoofType.Name);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initialize a roof element
        /// </summary>
        private void InitRoof(CurveArray curves, Autodesk.Revit.DB.ReferencePlane reference, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.RoofType roofType, double extrusionStart, double extrusionEnd)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            Autodesk.Revit.DB.RoofBase roof = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.RoofBase>(Document);
            if (roof == null)
            {
                roof = Document.Create.NewExtrusionRoof(curves, reference, level, roofType, extrusionStart, extrusionEnd);
            }
            else
            {
                roof = Document.Create.NewExtrusionRoof(curves, reference, level, roofType, extrusionStart, extrusionEnd);
            }

            InternalSetRoof(roof);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, InternalRoof);
        }
Ejemplo n.º 8
0
 public bool CanConvertToSpeckle(object @object)
 {
     return(@object
            switch
     {
         DB.DetailCurve _ => true,
         DB.DirectShape _ => true,
         DB.FamilyInstance _ => true,
         DB.Floor _ => true,
         DB.Level _ => true,
         DB.View _ => true,
         DB.ModelCurve _ => true,
         DB.Opening _ => true,
         DB.RoofBase _ => true,
         DB.Area _ => true,
         DB.Architecture.Room _ => true,
         DB.Architecture.TopographySurface _ => true,
         DB.Wall _ => true,
         DB.Mechanical.Duct _ => true,
         DB.Mechanical.Space _ => true,
         DB.Plumbing.Pipe _ => true,
         DB.Electrical.Wire _ => true,
         DB.CurtainGridLine _ => true, //these should be handled by curtain walls
         DB.Architecture.BuildingPad _ => true,
         DB.Architecture.Stairs _ => true,
         DB.Architecture.StairsRun _ => true,
         DB.Architecture.StairsLanding _ => true,
         DB.Architecture.Railing _ => true,
         DB.Architecture.TopRail _ => true,
         DB.Ceiling _ => true,
         DB.PointCloudInstance _ => true,
         DB.Group _ => true,
         DB.ProjectInfo _ => true,
         DB.ElementType _ => true,
         DB.Grid _ => true,
         DB.ReferencePoint _ => true,
         DB.Structure.AnalyticalModelStick _ => true,
         DB.Structure.AnalyticalModelSurface _ => true,
         DB.Structure.BoundaryConditions _ => true,
         _ => (@object as Element).IsElementSupported()
     });
Ejemplo n.º 9
0
        /// <summary>
        /// Initialize a roof element
        /// </summary>
        private void InitRoof(CurveArray curves, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.RoofType roofType)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            Autodesk.Revit.DB.RoofBase roof = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.RoofBase>(Document);
            if (roof == null)
            {
                ModelCurveArray footprint = new ModelCurveArray();
                roof = Document.Create.NewFootPrintRoof(curves, level, roofType, out footprint);
            }
            else
            {
                ModelCurveArray footprint = new ModelCurveArray();
                roof = Document.Create.NewFootPrintRoof(curves, level, roofType, out footprint);
            }

            InternalSetRoof(roof);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, InternalRoof);
        }
Ejemplo n.º 10
0
        public static string AddPoint(global::Revit.Elements.Element roof, Point point)
        {
            Autodesk.Revit.DB.Document doc          = DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.RoofBase internalRoof = (Autodesk.Revit.DB.RoofBase)roof.InternalElement;

            string result;

            try
            {
                TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);
                internalRoof.SlabShapeEditor.Enable();
                SlabShapeVertex vertex1 = internalRoof.SlabShapeEditor.DrawPoint(point.ToXyz());
                TransactionManager.Instance.TransactionTaskDone();
                result = "Success.";
            }
            catch (Exception)
            {
                result = "not so success.";
            }

            return(result);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Build Revit Model from a Grevit Component Collection
        /// Make sure the Component Collection has update, delete and scale properties set
        /// </summary>
        /// <param name="components">Grevit Component Collection</param>
        /// <returns></returns>
        public Result BuildModel(Grevit.Types.ComponentCollection components)
        {
            bool delete = false;

            // if components collection hasn't been supplied
            // open the Grevit UI and retrieve components from a Grevit Server
            if (components == null)
            {
                // Create new Grevit Client sending existing Families
                Grevit.Client.ClientWindow grevitClientDialog = new Grevit.Client.ClientWindow(document.GetFamilies());

                // Show Client Dialog
                grevitClientDialog.ShowWindow();

                // Set the received component collection
                components = grevitClientDialog.componentCollection;
            }

            // set element deletion flag and scale factor from collection
            delete = components.delete;
            Scale  = components.scale;


            RoofShapePoints = new List <Tuple <ElementId, CurveArray> >();


            // Set up a List for stalled components (with References)
            List <Component> componentsWithReferences = new List <Component>();

            // Get all existing Grevit Elements from the Document
            // If Update is false this will just be an empty List
            existing_Elements = document.GetExistingGrevitElements(components.update);

            // Set up an empty List for created Elements
            created_Elements = new Dictionary <string, ElementId>();


            #region createComponents

            // using one transaction for all elements
            // this way a Grevit import is one simple UNDO step in Revit
            Transaction trans = new Transaction(GrevitBuildModel.document, "GrevitCreate");
            trans.Start();

            // Walk thru all received components
            foreach (Component component in components.Items)
            {
                // If they are not reference dependent, create them directly
                // Otherwise add the component to a List of stalled elements
                if (!component.stalledForReference)
                {
                    try
                    {
                        component.Build(false);
                    }
                    catch (Exception e) { Grevit.Reporting.MessageBox.Show(component.GetType().Name + " Error", e.InnerException.Message); }
                }
                else
                {
                    componentsWithReferences.Add(component);
                }
            }

            // Walk thru all elements which are stalled because they are depending on
            // an Element which needed to be created first


            foreach (Component component in componentsWithReferences)
            {
                try
                {
                    component.Build(true);
                }
                catch (Exception e) { Grevit.Reporting.MessageBox.Show(component.GetType().Name + " Error", e.InnerException.Message); }
            }

            trans.Commit();
            trans.Dispose();



            foreach (Tuple <ElementId, CurveArray> rsp in RoofShapePoints)
            {
                if (rsp.Item1 != ElementId.InvalidElementId)
                {
                    Autodesk.Revit.DB.RoofBase roof = (Autodesk.Revit.DB.RoofBase)document.GetElement(rsp.Item1);
                    if (roof != null)
                    {
                        if (roof.SlabShapeEditor != null)
                        {
                            if (roof.SlabShapeEditor.IsEnabled)
                            {
                                Transaction pp = new Transaction(GrevitBuildModel.document, "GrevitPostProcessing");
                                pp.Start();
                                roof.SlabShapeEditor.Enable();
                                pp.Commit();
                                pp.Dispose();
                            }

                            List <XYZ> points = new List <XYZ>();
                            foreach (Curve c in rsp.Item2)
                            {
                                points.Add(c.GetEndPoint(0));
                            }

                            Transaction ppx = new Transaction(GrevitBuildModel.document, "GrevitPostProcessing");
                            ppx.Start();

                            foreach (SlabShapeVertex v in roof.SlabShapeEditor.SlabShapeVertices)
                            {
                                double Zdiff = 0;

                                foreach (XYZ pt in points)
                                {
                                    if (Math.Abs(v.Position.X - pt.X) < double.Epsilon &&
                                        Math.Abs(v.Position.Y - pt.Y) < double.Epsilon &&
                                        Math.Abs(v.Position.Z - pt.Z) > double.Epsilon)
                                    {
                                        Zdiff = pt.Z;
                                    }
                                }

                                if (Zdiff != 0)
                                {
                                    roof.SlabShapeEditor.ModifySubElement(v, Zdiff);
                                }
                            }

                            ppx.Commit();
                            ppx.Dispose();
                        }
                    }
                }
            }



            #endregion


            // If Delete Setting is activated
            if (delete)
            {
                // Create a new transaction
                Transaction transaction = new Transaction(document, "GrevitDelete");
                transaction.Start();

                // get the Difference between existing and new elements to erase them
                IEnumerable <KeyValuePair <string, ElementId> > unused =
                    existing_Elements.Except(created_Elements).Concat(created_Elements.Except(existing_Elements));

                // Delete those elements from the document
                foreach (KeyValuePair <string, ElementId> element in unused)
                {
                    document.Delete(element.Value);
                }

                // commit and dispose the transaction
                transaction.Commit();
                transaction.Dispose();
            }



            return(Result.Succeeded);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Initialize a roof element
 /// </summary>
 private void InitRoof(Autodesk.Revit.DB.RoofBase roof)
 {
     InternalSetRoof(roof);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Private constructor
 /// </summary>
 private Roof(Autodesk.Revit.DB.RoofBase roof)
 {
     SafeInit(() => InitRoof(roof));
 }
Ejemplo n.º 14
0
        private Roof RoofToSpeckle(DB.RoofBase revitRoof)
        {
            var profiles = GetProfiles(revitRoof);

            var speckleRoof = new RevitRoof();

            switch (revitRoof)
            {
            //assigning correct type for when going back in Revit
            case FootPrintRoof footPrintRoof:
            {
                var speckleFootprintRoof = new RevitFootprintRoof
                {
                    level       = ConvertAndCacheLevel(footPrintRoof, BuiltInParameter.ROOF_BASE_LEVEL_PARAM),
                    cutOffLevel = ConvertAndCacheLevel(footPrintRoof, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM),
                    slope       = GetParamValue <double?>(footPrintRoof, BuiltInParameter.ROOF_SLOPE) //NOTE: can be null if the sides have different slopes
                };

                speckleRoof = speckleFootprintRoof;
                break;
            }

            case ExtrusionRoof revitExtrusionRoof:
            {
                var speckleExtrusionRoof = new RevitExtrusionRoof
                {
                    start = GetParamValue <double>(revitExtrusionRoof, BuiltInParameter.EXTRUSION_START_PARAM),

                    end = GetParamValue <double>(revitExtrusionRoof, BuiltInParameter.EXTRUSION_END_PARAM)
                };
                var plane = revitExtrusionRoof.GetProfile().get_Item(0).SketchPlane.GetPlane();
                speckleExtrusionRoof.referenceLine =
                    new Line(PointToSpeckle(plane.Origin.Add(plane.XVec.Normalize().Negate())), PointToSpeckle(plane.Origin), ModelUnits); //TODO: test!
                speckleExtrusionRoof.level = ConvertAndCacheLevel(revitExtrusionRoof, BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM);
                speckleRoof = speckleExtrusionRoof;
                break;
            }
            }

            speckleRoof.type = Doc.GetElement(revitRoof.GetTypeId()).Name;

            // TODO handle case if not one of our supported roofs
            if (profiles.Any())
            {
                speckleRoof.outline = profiles[0];
                if (profiles.Count > 1)
                {
                    speckleRoof.voids = profiles.Skip(1).ToList();
                }
            }

            GetAllRevitParamsAndIds(speckleRoof, revitRoof,
                                    new List <string> {
                "ROOF_CONSTRAINT_LEVEL_PARAM", "ROOF_BASE_LEVEL_PARAM", "ROOF_UPTO_LEVEL_PARAM", "EXTRUSION_START_PARAM", "EXTRUSION_END_PARAM"
            });

            var displayMesh = new Geometry.Mesh();

            (displayMesh.faces, displayMesh.vertices) = GetFaceVertexArrayFromElement(revitRoof, new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
            });
            speckleRoof["@displayMesh"] = displayMesh;

            GetHostedElements(speckleRoof, revitRoof);

            return(speckleRoof);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Set the InternalRoof property and the associated element id and unique id
 /// </summary>
 /// <param name="Roof"></param>
 private void InternalSetRoof(Autodesk.Revit.DB.RoofBase roof)
 {
     InternalRoof      = roof;
     InternalElementId = roof.Id;
     InternalUniqueId  = roof.UniqueId;
 }
Ejemplo n.º 16
0
        public List <ApplicationPlaceholderObject> RoofToNative(Roof speckleRoof)
        {
            if (speckleRoof.outline == null)
            {
                throw new Speckle.Core.Logging.SpeckleException("Only outline based Floor are currently supported.");
            }

            DB.RoofBase revitRoof = null;
            DB.Level    level     = null;
            var         outline   = CurveToNative(speckleRoof.outline);

            var speckleRevitRoof = speckleRoof as RevitRoof;

            if (speckleRevitRoof != null)
            {
                level = LevelToNative(speckleRevitRoof.level);
            }
            else
            {
                level = LevelToNative(LevelFromCurve(outline.get_Item(0)));
            }

            var roofType = GetElementType <RoofType>((Base)speckleRoof);

            var docObj = GetExistingElementByApplicationId(((Base)speckleRoof).applicationId);

            if (docObj != null)
            {
                Doc.Delete(docObj.Id);
            }

            switch (speckleRoof)
            {
            case RevitExtrusionRoof speckleExtrusionRoof:
            {
                var            referenceLine = LineToNative(speckleExtrusionRoof.referenceLine);
                var            norm          = GetPerpendicular(referenceLine.GetEndPoint(0) - referenceLine.GetEndPoint(1)).Negate();
                ReferencePlane plane         = Doc.Create.NewReferencePlane(referenceLine.GetEndPoint(0),
                                                                            referenceLine.GetEndPoint(1),
                                                                            norm,
                                                                            Doc.ActiveView);
                //create floor without a type
                var start = ScaleToNative(speckleExtrusionRoof.start, speckleExtrusionRoof.units);
                var end   = ScaleToNative(speckleExtrusionRoof.end, speckleExtrusionRoof.units);
                revitRoof = Doc.Create.NewExtrusionRoof(outline, plane, level, roofType, start, end);
                break;
            }

            case RevitFootprintRoof speckleFootprintRoof:
            {
                ModelCurveArray curveArray         = new ModelCurveArray();
                var             revitFootprintRoof = Doc.Create.NewFootPrintRoof(outline, level, roofType, out curveArray);
                var             poly          = speckleFootprintRoof.outline as Polycurve;
                bool            hasSlopedSide = false;
                if (poly != null)
                {
                    for (var i = 0; i < curveArray.Size; i++)
                    {
                        var isSloped   = ((Base)poly.segments[i])["isSloped"] as bool?;
                        var slopeAngle = ((Base)poly.segments[i])["slopeAngle"] as double?;
                        var offset     = ((Base)poly.segments[i])["offset"] as double?;

                        if (isSloped != null)
                        {
                            revitFootprintRoof.set_DefinesSlope(curveArray.get_Item(i), isSloped == true);
                            if (slopeAngle != null && isSloped == true)
                            {
                                revitFootprintRoof.set_SlopeAngle(curveArray.get_Item(i), (double)slopeAngle);
                                hasSlopedSide = true;
                            }
                        }

                        if (offset != null)
                        {
                            revitFootprintRoof.set_Offset(curveArray.get_Item(i), (double)offset);
                        }
                    }
                }

                //this is for schema builder specifically
                //if no roof edge has a slope defined but a slope angle is defined on the roof
                //set each edge to have that slope
                if (!hasSlopedSide && speckleFootprintRoof.slope != null)
                {
                    for (var i = 0; i < curveArray.Size; i++)
                    {
                        revitFootprintRoof.set_DefinesSlope(curveArray.get_Item(i), true);
                    }
                    TrySetParam(revitFootprintRoof, BuiltInParameter.ROOF_SLOPE, (double)speckleFootprintRoof.slope);
                }

                if (speckleFootprintRoof.cutOffLevel != null)
                {
                    var cutOffLevel = LevelToNative(speckleFootprintRoof.cutOffLevel);
                    TrySetParam(revitFootprintRoof, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM, cutOffLevel);
                }

                revitRoof = revitFootprintRoof;
                break;
            }

            default:
                ConversionErrors.Add(new Error("Cannot create Roof", "Roof type not supported"));
                throw new Speckle.Core.Logging.SpeckleException("Roof type not supported");
            }

            Doc.Regenerate();

            try
            {
                CreateVoids(revitRoof, speckleRoof);
            }
            catch (Exception ex)
            {
                ConversionErrors.Add(new Error($"Could not create openings in roof {speckleRoof.applicationId}", ex.Message));
            }

            if (speckleRevitRoof != null)
            {
                SetInstanceParameters(revitRoof, speckleRevitRoof);
            }

            var placeholders = new List <ApplicationPlaceholderObject>()
            {
                new ApplicationPlaceholderObject {
                    applicationId = speckleRevitRoof.applicationId, ApplicationGeneratedId = revitRoof.UniqueId, NativeObject = revitRoof
                }
            };

            var hostedElements = SetHostedElements(speckleRoof, revitRoof);

            placeholders.AddRange(hostedElements);

            return(placeholders);
        }
Ejemplo n.º 17
0
 public Roof(DB.RoofBase roof) : base(roof)
 {
 }