コード例 #1
0
        /// <summary>
        /// Initialize a floor element
        /// </summary>
        private void InitFloor(CurveArray curveArray, Autodesk.Revit.DB.FloorType floorType, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Line slopeArrow, double slope, bool structural)
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);

            if (!SessionVariables.ParametersCreated)
            {
                UtilsObjectsLocation.CheckParameters(doc);
            }

            Autodesk.Revit.DB.Floor floor = null;

            if (floorType.IsFoundationSlab)
            {
                // Foundation Slabs require that the profile curves are planar and horizontal
                // The normal must be orthogonal to the profile, hence the only possible normal is the Z Axis
                floor = doc.Create.NewFoundationSlab(curveArray, floorType, level, structural, XYZ.BasisZ);
            }
            else
            {
                // we assume the floor is not structural here, this may be a bad assumption
                floor = doc.Create.NewSlab(curveArray, level, slopeArrow, slope, structural);
                floor.ChangeTypeId(floorType.Id);
            }

            InternalSetFloor(floor);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(doc, InternalFloor);
        }
コード例 #2
0
        public static SpeckleElementsClasses.Floor ToSpeckle(this Autodesk.Revit.DB.Floor myFloor)
        {
            var speckleFloor = new SpeckleElementsClasses.Floor();

            speckleFloor.parameters = GetElementParams(myFloor);

            var geo = myFloor.get_Geometry(new Options()
            {
                DetailLevel = ViewDetailLevel.Medium
            });

            speckleFloor.floorType = myFloor.FloorType.Name;
            speckleFloor.baseCurve = getFloorOutline(myFloor);

            speckleFloor.ApplicationId = myFloor.UniqueId;
            speckleFloor.elementId     = myFloor.Id.ToString();
            speckleFloor.GenerateHash();

            (speckleFloor.Faces, speckleFloor.Vertices) = GetFaceVertexArrayFromElement(myFloor, new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
            });

            return(speckleFloor);
        }
コード例 #3
0
        public static SpecklePolycurve getFloorOutline(Autodesk.Revit.DB.Floor myFloor)
        {
            var geometry = myFloor.get_Geometry(new Options()
            {
                DetailLevel = ViewDetailLevel.Medium
            });
            var poly = new SpecklePolycurve();

            poly.Segments = new List <SpeckleObject>();

            foreach (Solid solid in geometry) // let's hope it's only one?
            {
                if (solid == null)
                {
                    continue;
                }
                var f        = GetLowestFace(solid);
                var crvLoops = f.GetEdgesAsCurveLoops();
                foreach (var crvloop in crvLoops)
                {
                    foreach (var curve in crvloop)
                    {
                        var c = curve as Autodesk.Revit.DB.Curve;

                        if (c == null)
                        {
                            continue;
                        }
                        poly.Segments.Add(SpeckleCore.Converter.Serialise(c) as SpeckleObject);
                    }
                }
            }
            return(poly);
        }
コード例 #4
0
ファイル: Floor.cs プロジェクト: Revitcivil/DynamoRevit
 /// <summary>
 /// Create a Floor from a user selected Element.
 /// </summary>
 /// <param name="floor"></param>
 /// <param name="isRevitOwned"></param>
 /// <returns></returns>
 internal static Floor FromExisting(Autodesk.Revit.DB.Floor floor, bool isRevitOwned)
 {
     return(new Floor(floor)
     {
         IsRevitOwned = isRevitOwned
     });
 }
コード例 #5
0
ファイル: Create.Floor.cs プロジェクト: kubim/Elements
        public static Elements.Floor[] FloorsFromRevitFloor(ADSK.Document doc, ADSK.Floor revitFloor)
        {
            var profiles  = GetProfilesOfTopFacesOfFloor(doc, revitFloor);
            var thickness = revitFloor.LookupParameter("Thickness")?.AsDouble();

            var floors = new List <Elements.Floor>();

            foreach (var profile in profiles)
            {
                var zMove     = profile.Perimeter.Vertices.Max(v => v.Z);
                var transform = new ElemGeom.Transform(0, 0, -zMove);

                var zeroedProfile = transform.OfProfile(profile);

                transform.Invert();
                var floorThickness = thickness.HasValue ? Elements.Units.FeetToMeters(thickness.Value) : Elements.Units.FeetToMeters(1);
                // Revit floors are extrusions down, and currently Hypar floors are extrusions up, so we also must move by the floor thickness
                transform.Move(new Vector3(0, 0, -floorThickness));
                var floor = new Elements.Floor(zeroedProfile,
                                               floorThickness,
                                               transform);
                floors.Add(floor);
            }
            return(floors.ToArray());
        }
コード例 #6
0
        private RevitFloor FloorToSpeckle(DB.Floor revitFloor)
        {
            var profiles = GetProfiles(revitFloor);

            var speckleFloor = new RevitFloor();

            speckleFloor.type    = Doc.GetElement(revitFloor.GetTypeId()).Name;
            speckleFloor.outline = profiles[0];
            if (profiles.Count > 1)
            {
                speckleFloor.voids = profiles.Skip(1).ToList();
            }

            speckleFloor.level      = ConvertAndCacheLevel(revitFloor, BuiltInParameter.LEVEL_PARAM);
            speckleFloor.structural = GetParamValue <bool>(revitFloor, BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL);

            GetAllRevitParamsAndIds(speckleFloor, revitFloor, new List <string> {
                "LEVEL_PARAM", "FLOOR_PARAM_IS_STRUCTURAL"
            });

            speckleFloor.displayMesh = GetElementDisplayMesh(revitFloor, new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
            });

            GetHostedElements(speckleFloor, revitFloor);
            //Report.Log($"Converted Floor {revitFloor.Id}");
            return(speckleFloor);
        }
コード例 #7
0
        private void AssertFloorEqual(DB.Floor sourceElem, DB.Floor destElem)
        {
            Assert.NotNull(destElem);
            Assert.Equal(sourceElem.Name, sourceElem.Name);

            AssertEqualParam(sourceElem, destElem, BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM);
            //AssertEqualParam(sourceElem, destElem, BuiltInParameter.HOST_PERIMETER_COMPUTED);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL);
            AssertEqualParam(sourceElem, destElem, BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM);
        }
コード例 #8
0
        void ReconstructFloorByOutline
        (
            DB.Document doc,
            ref DB.Floor element,

            Rhino.Geometry.Curve boundary,
            Optional <DB.FloorType> type,
            Optional <DB.Level> level,
            [Optional] bool structural
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            if
            (
                ((boundary = boundary.ChangeUnits(scaleFactor)) is null) ||
                !boundary.IsClosed ||
                !boundary.TryGetPlane(out var boundaryPlane, Revit.VertexTolerance) ||
                boundaryPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
            )
            {
                ThrowArgumentException(nameof(boundary), "Boundary must be an horizontal planar closed curve.");
            }

            SolveOptionalType(ref type, doc, DB.ElementTypeGroup.FloorType, nameof(type));

            SolveOptionalLevel(doc, boundary, ref level, out var bbox);

            var curveArray = boundary.ToHostMultiple().ToCurveArray();

            var parametersMask = new DB.BuiltInParameter[]
            {
                DB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM,
                DB.BuiltInParameter.ELEM_FAMILY_PARAM,
                DB.BuiltInParameter.ELEM_TYPE_PARAM,
                DB.BuiltInParameter.LEVEL_PARAM,
                DB.BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL
            };

            if (type.Value.IsFoundationSlab)
            {
                ReplaceElement(ref element, doc.Create.NewFoundationSlab(curveArray, type.Value, level.Value, structural, DB.XYZ.BasisZ), parametersMask);
            }
            else
            {
                ReplaceElement(ref element, doc.Create.NewFloor(curveArray, type.Value, level.Value, structural, DB.XYZ.BasisZ), parametersMask);
            }

            if (element != null)
            {
                var boundaryBBox = boundary.GetBoundingBox(true);
                element.get_Parameter(DB.BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).Set(boundaryBBox.Min.Z - level.Value.Elevation);
            }
        }
コード例 #9
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication revit = commandData.Application;

            // Get the selected floor
            UIDocument project    = revit.ActiveUIDocument;
            Selection  choices    = project.Selection;
            ElementSet collection = new ElementSet();

            foreach (ElementId elementId in choices.GetElementIds())
            {
                collection.Insert(project.Document.GetElement(elementId));
            }

            // Only allow to select one floor, or else report the failure
            if (1 != collection.Size)
            {
                message = "Please select a floor.";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            foreach (Element e in collection)
            {
                m_slab = e as Autodesk.Revit.DB.Floor;
                if (null == m_slab)
                {
                    message = "Please select a floor.";
                    return(Autodesk.Revit.UI.Result.Failed);
                }
            }

            // Get the function of each of its structural layers
            foreach (CompoundStructureLayer e in m_slab.FloorType.GetCompoundStructure().GetLayers())
            {
                // With the selected floor, judge if the function of each of its structural layers
                // is exist, if it's not exist, there should be zero.
                if (0 == e.Function)
                {
                    m_functions.Add("No function");
                }
                else
                {
                    m_functions.Add(e.Function.ToString());
                }
            }

            // Display them in a form
            StructuralLayerFunctionForm displayForm = new StructuralLayerFunctionForm(this);

            displayForm.ShowDialog();

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
コード例 #10
0
ファイル: Floor.cs プロジェクト: Revitcivil/DynamoRevit
        /// <summary>
        /// Initialize a floor element
        /// </summary>
        private void InitFloor(List <CurveLoop> profiles, Autodesk.Revit.DB.FloorType floorType, Autodesk.Revit.DB.Level level)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            // we assume the floor is not structural here, this may be a bad assumption
            Autodesk.Revit.DB.Floor floor = Autodesk.Revit.DB.Floor.Create(Document, profiles, floorType.Id, level.Id);

            InternalSetFloor(floor);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, InternalFloor);
        }
コード例 #11
0
ファイル: Command.cs プロジェクト: karthi1015/apidocs.samples
        /// <summary>
        /// Run this sample now
        /// </summary>
        public void Run()
        {
            //
            // Get the selected floor
            Selection  choices    = m_doc.Selection;
            ElementSet collection = new ElementSet();

            foreach (var elementid in  choices.GetElementIds())
            {
                collection.Insert(m_doc.Document.GetElement(elementid));
            }

            //
            // Only allow to select one floor, or else report the failure
            if (1 != collection.Size)
            {
                MessageBox.Show("Please select a floor firstly.");
                return;
            }
            foreach (Element e in collection)
            {
                m_slab = e as Autodesk.Revit.DB.Floor;
                if (null == m_slab)
                {
                    MessageBox.Show("Please select a floor firstly.");
                    return;
                }
            }
            //
            // Get the function of each of its structural layers
            foreach (CompoundStructureLayer e in m_slab.FloorType.GetCompoundStructure().GetLayers())
            {
                // With the selected floor, judge if the function of each of its structural layers
                // is exist, if it's not exist, there should be zero.
                if (0 == e.Function)
                {
                    m_functions.Add("No function");
                }
                else
                {
                    m_functions.Add(e.Function.ToString());
                }
            }
            //
            // Display them in a form
            StructuralLayerFunctionForm displayForm = new StructuralLayerFunctionForm(this);

            displayForm.ShowDialog();
        }
コード例 #12
0
        public static List <SlabEdge> ByReferenceArray(Revit.Elements.Element Floor, Revit.Elements.Element SlabEdgeType)
        {
            var             doc            = DocumentManager.Instance.CurrentDBDocument;
            List <SlabEdge> slab           = new List <SlabEdge>();
            ElementId       id             = Elements.UnwrapElement(SlabEdgeType);
            SlabEdgeType    unwrapSlabEdge = doc.GetElement(id) as SlabEdgeType;

            Console.WriteLine(id);
            ElementId floorId = Elements.UnwrapElement(Floor);

            Autodesk.Revit.DB.Floor elem = doc.GetElement(floorId) as Autodesk.Revit.DB.Floor;
            Options         geomOptions  = new Options();
            GeometryElement solid        = elem.get_Geometry(geomOptions);

            try
            {
                foreach (GeometryElement k in solid)
                {
                    ReferenceArray referenceArray = new ReferenceArray();
                    referenceArray.Clear();
                    //IEnumerable<ReferenceArray> reference = Line as IEnumerable<ReferenceArray>;
                    //foreach (Autodesk.DesignScript.Geometry.Curve host in k)
                    //{
                    //    //var curve = host.ToRevitType();
                    //    //var host = curve.ToProtoType();
                    //    //Reference j = host as Reference;
                    //    Curve curve = host.ToRevitType();
                    //    Reference refc = curve.Reference;
                    //    referenceArray.Append(refc);
                    //}
                    TransactionManager.Instance.EnsureInTransaction(doc);
                    SlabEdge slabcreator = doc.Create.NewSlabEdge(unwrapSlabEdge, referenceArray);
                    slabcreator.ToDSType(true);
                    slab.Add(slabcreator);
                    TransactionManager.Instance.TransactionTaskDone();
                }
                return(slab);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #13
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()
     });
コード例 #14
0
        /// <summary>
        /// Initialize a floor element
        /// </summary>
        private void InitFloor(CurveArray curveArray, Autodesk.Revit.DB.FloorType floorType, Autodesk.Revit.DB.Level level)
        {
            TransactionManager.Instance.EnsureInTransaction(Document);

            Autodesk.Revit.DB.Floor floor = null;
            if (floorType.IsFoundationSlab)
            {
                floor = Document.Create.NewFoundationSlab(curveArray, floorType, level, false, XYZ.BasisZ);
            }
            else
            {
                // we assume the floor is not structural here, this may be a bad assumption
                floor = Document.Create.NewFloor(curveArray, floorType, level, false);
            }

            InternalSetFloor(floor);

            TransactionManager.Instance.TransactionTaskDone();

            ElementBinder.CleanupAndSetElementForTrace(Document, InternalFloor);
        }
コード例 #15
0
ファイル: Floor.cs プロジェクト: l2obin/Dynamo
        public override FScheme.Value Evaluate(Microsoft.FSharp.Collections.FSharpList <FScheme.Value> args)
        {
            //if we're in a family document, don't even try to add a floor
            if (dynRevitSettings.Doc.Document.IsFamilyDocument)
            {
                throw new Exception("Floors can not be created in family documents.");
            }

            var edges     = ((Value.List)args[0]).Item;
            var floorType = (FloorType)((Value.Container)args[1]).Item;
            var level     = (Autodesk.Revit.DB.Level)((Value.Container)args[2]).Item;

            Autodesk.Revit.DB.Floor floor = null;

            //convert the edges to a curveArray
            if (edges.Count() < 3)
            {
                throw new Exception("The edge list provided does not have an adequate number of edges to create a floor.");
            }

            if (this.Elements.Any())
            {
                if (dynUtils.TryGetElement(this.Elements[0], out floor))
                {
                    //Delete the existing floor. Revit API does not allow update of floor sketch.
                    dynRevitSettings.Doc.Document.Delete(floor.Id);
                }

                floor            = CreateFloor(edges, floorType, level);
                this.Elements[0] = floor.Id;
            }
            else
            {
                floor = CreateFloor(edges, floorType, level);
                Elements.Add(floor.Id);
            }

            return(Value.NewContainer(floor));
        }
コード例 #16
0
 public static Floor Wrap(Autodesk.Revit.DB.Floor ele, bool isRevitOwned)
 {
     return(Floor.FromExisting(ele, isRevitOwned));
 }
コード例 #17
0
ファイル: Floor.cs プロジェクト: Revitcivil/DynamoRevit
 /// <summary>
 /// Set the InternalFloor property and the associated element id and unique id
 /// </summary>
 /// <param name="floor"></param>
 private void InternalSetFloor(Autodesk.Revit.DB.Floor floor)
 {
     InternalFloor     = floor;
     InternalElementId = floor.Id;
     InternalUniqueId  = floor.UniqueId;
 }
コード例 #18
0
ファイル: Command.cs プロジェクト: AMEE/revit
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication revit = commandData.Application;

            // Get the selected floor
            UIDocument project = revit.ActiveUIDocument;
            Selection choices = project.Selection;
            ElementSet collection = choices.Elements;

            // Only allow to select one floor, or else report the failure
            if (1 != collection.Size)
            {
                message = "Please select a floor.";
                return Autodesk.Revit.UI.Result.Failed;
            }
            foreach (Element e in collection)
            {
                m_slab = e as Autodesk.Revit.DB.Floor;
                if (null == m_slab)
                {
                    message = "Please select a floor.";
                    return Autodesk.Revit.UI.Result.Failed;
                }
            }

            // Get the function of each of its structural layers
            foreach (CompoundStructureLayer e in m_slab.FloorType.GetCompoundStructure().GetLayers())
            {
                // With the selected floor, judge if the function of each of its structural layers
                // is exist, if it's not exist, there should be zero.
                if (0 == e.Function)
                {
                    m_functions.Add("No function");
                }
                else
                {
                    m_functions.Add(e.Function.ToString());
                }

            }

            // Display them in a form
            StructuralLayerFunctionForm displayForm = new StructuralLayerFunctionForm(this);
            displayForm.ShowDialog();

            return Autodesk.Revit.UI.Result.Succeeded;
        }
コード例 #19
0
ファイル: Floor.cs プロジェクト: Revitcivil/DynamoRevit
 /// <summary>
 /// Initialize a floor element
 /// </summary>
 private void InitFloor(Autodesk.Revit.DB.Floor floor)
 {
     InternalSetFloor(floor);
 }
コード例 #20
0
ファイル: Floor.cs プロジェクト: Revitcivil/DynamoRevit
 /// <summary>
 /// Private constructor
 /// </summary>
 private Floor(Autodesk.Revit.DB.Floor floor)
 {
     SafeInit(() => InitFloor(floor));
 }
コード例 #21
0
ファイル: Floor.cs プロジェクト: TheChosen0ne/Dynamo
 /// <summary>
 /// Set the InternalFloor property and the associated element id and unique id
 /// </summary>
 /// <param name="floor"></param>
 private void InternalSetFloor(Autodesk.Revit.DB.Floor floor)
 {
     this.InternalFloor = floor;
     this.InternalElementId = floor.Id;
     this.InternalUniqueId = floor.UniqueId;
 }
コード例 #22
0
        public List <ApplicationPlaceholderObject> FloorToNative(BuiltElements.Floor speckleFloor)
        {
            if (speckleFloor.outline == null)
            {
                throw new Speckle.Core.Logging.SpeckleException("Floor is missing an outline.");
            }

            bool structural = false;
            var  outline    = CurveToNative(speckleFloor.outline);

            DB.Level level;
            double   slope = 0;

            DB.Line slopeDirection = null;
            if (speckleFloor is RevitFloor speckleRevitFloor)
            {
                level          = LevelToNative(speckleRevitFloor.level);
                structural     = speckleRevitFloor.structural;
                slope          = speckleRevitFloor.slope;
                slopeDirection = (speckleRevitFloor.slopeDirection != null) ? LineToNative(speckleRevitFloor.slopeDirection) : null;
            }
            else
            {
                level = LevelToNative(LevelFromCurve(outline.get_Item(0)));
            }

            var floorType = GetElementType <FloorType>(speckleFloor);

            // NOTE: I have not found a way to edit a slab outline properly, so whenever we bake, we renew the element. The closest thing would be:
            // https://adndevbConversionLog.Add.typepad.com/aec/2013/10/change-the-boundary-of-floorsslabs.html
            // This would only work if the floors have the same number (and type!!!) of outline curves.
            var docObj = GetExistingElementByApplicationId(speckleFloor.applicationId);

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

            DB.Floor revitFloor = null;
            if (floorType == null)
            {
                if (slope != 0 && slopeDirection != null)
                {
                    revitFloor = Doc.Create.NewSlab(outline, level, slopeDirection, slope, structural);
                }
                if (revitFloor == null)
                {
                    revitFloor = Doc.Create.NewFloor(outline, structural);
                }
            }
            else
            {
                if (slope != 0 && slopeDirection != null)
                {
                    revitFloor = Doc.Create.NewSlab(outline, level, slopeDirection, slope, structural);
                }
                if (revitFloor == null)
                {
                    revitFloor = Doc.Create.NewFloor(outline, floorType, level, structural);
                }
            }

            Doc.Regenerate();

            try
            {
                CreateVoids(revitFloor, speckleFloor);
            }
            catch (Exception ex)
            {
                Report.LogConversionError(new Exception($"Could not create openings in floor {speckleFloor.applicationId}", ex));
            }

            SetInstanceParameters(revitFloor, speckleFloor);

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

            var hostedElements = SetHostedElements(speckleFloor, revitFloor);

            placeholders.AddRange(hostedElements);
            //Report.Log($"Created Floor {revitFloor.Id}");
            return(placeholders);
        }
コード例 #23
0
 public Floor(DB.Floor floor) : base(floor)
 {
 }
コード例 #24
0
ファイル: HostObject.cs プロジェクト: HoareLea/SAM_Revit
        public static HostObject ToRevit(this Panel panel, Document document, Core.Revit.ConvertSettings convertSettings)
        {
            Geometry.Spatial.Face3D face3D = panel?.GetFace3D();
            if (face3D == null)
            {
                return(null);
            }

            HostObject result = convertSettings?.GetObject <HostObject>(panel.Guid);

            if (result != null)
            {
                return(result);
            }

            PanelType panelType = panel.PanelType;

            Geometry.Spatial.Vector3D normal = panel.Normal;

            HostObjAttributes hostObjAttributes = panel.Construction.ToRevit(document, panelType, normal, convertSettings);

            if (hostObjAttributes == null)
            {
                hostObjAttributes = Analytical.Query.DefaultConstruction(panelType)?.ToRevit(document, panelType, normal, convertSettings); //Default Construction
            }
            BuiltInParameter[] builtInParameters = null;
            if (hostObjAttributes is Autodesk.Revit.DB.WallType)
            {
                double lowElevation = panel.LowElevation();

                Level level = document.LowLevel(lowElevation);

                Autodesk.Revit.DB.Wall wall = ToRevit_Wall(face3D, document, (Autodesk.Revit.DB.WallType)hostObjAttributes, level);
                if (wall == null)
                {
                    return(result);
                }

                //List<Curve> curveList = new List<Curve>();
                //foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D in face3D.GetEdge3Ds())
                //{
                //    if (Geometry.Spatial.Query.Clockwise(closedPlanar3D))
                //        closedPlanar3D.Reverse();

                //    List<Line> lines = closedPlanar3D.ToRevit();
                //    if (lines == null)
                //        continue;

                //    curveList.AddRange(lines);
                //}

                //if (curveList == null || curveList.Count == 0)
                //    return null;

                //double lowElevation = panel.LowElevation();

                //Level level = document.LowLevel(lowElevation);
                //if (level == null)
                //    return null;

                //Wall wall = Wall.Create(document, curveList, hostObjAttributes.Id, level.Id, false, panel.Normal.ToRevit(false));

                Parameter parameter = null;

                parameter = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE);
                if (parameter != null)
                {
                    parameter.Set(ElementId.InvalidElementId);
                }

                parameter = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
                if (parameter != null)
                {
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                    double height = UnitUtils.ConvertToInternalUnits((panel.HighElevation() - lowElevation), DisplayUnitType.DUT_METERS);
#else
                    double height = UnitUtils.ConvertToInternalUnits((panel.HighElevation() - lowElevation), UnitTypeId.Meters);
#endif


                    parameter.Set(height);
                }

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                double levelElevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, DisplayUnitType.DUT_METERS);
#else
                double levelElevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, UnitTypeId.Meters);
#endif

                if (Math.Abs(lowElevation - levelElevation) > Core.Tolerance.MacroDistance)
                {
                    parameter = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
                    if (parameter != null)
                    {
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                        parameter.Set(UnitUtils.ConvertToInternalUnits(lowElevation - levelElevation, DisplayUnitType.DUT_METERS));
#else
                        parameter.Set(UnitUtils.ConvertToInternalUnits(lowElevation - levelElevation, UnitTypeId.Meters));
#endif
                    }
                }

                builtInParameters = new BuiltInParameter[] { BuiltInParameter.WALL_BASE_CONSTRAINT, BuiltInParameter.WALL_BASE_OFFSET, BuiltInParameter.WALL_HEIGHT_TYPE, BuiltInParameter.WALL_USER_HEIGHT_PARAM, BuiltInParameter.WALL_KEY_REF_PARAM };
                result            = wall;
            }
            else if (hostObjAttributes is Autodesk.Revit.DB.FloorType)
            {
                Geometry.Spatial.IClosedPlanar3D closedPlanar3D_External = face3D.GetExternalEdge3D();
                if (!(closedPlanar3D_External is Geometry.Spatial.ICurvable3D))
                {
                    return(null);
                }

                double elevation = panel.LowElevation();
                Level  level     = document.HighLevel(elevation);

                Geometry.Spatial.Plane plane = new Geometry.Spatial.Plane(new Geometry.Spatial.Point3D(0, 0, elevation), Geometry.Spatial.Vector3D.WorldZ);

                CurveArray curveArray_Sloped = new CurveArray();
                CurveArray curveArray_Plane  = new CurveArray();

                Geometry.Spatial.IClosedPlanar3D closedPlanar3D = face3D.GetExternalEdge3D();
                if (!(closedPlanar3D is Geometry.Spatial.ICurvable3D))
                {
                    return(null);
                }

                List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Query.Segment3Ds(closedPlanar3D);
                if (segment3Ds == null || segment3Ds.Count == 0)
                {
                    return(null);
                }

                foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds)
                {
                    curveArray_Sloped.Append(segment3D.ToRevit_Line());

                    Geometry.Spatial.Segment3D segment3D_Temp = Geometry.Spatial.Query.Project(plane, segment3D);
                    if (segment3D_Temp == null)
                    {
                        continue;
                    }

                    curveArray_Plane.Append(segment3D_Temp.ToRevit_Line());
                }

#if Revit2017 || Revit2018 || Revit2019 || Revit2020 || Revit2021
                Autodesk.Revit.DB.Floor floor = document.Create.NewFloor(curveArray_Plane, hostObjAttributes as Autodesk.Revit.DB.FloorType, level, false);
#else
                CurveLoop curveLoop = new CurveLoop();
                foreach (Curve curve in curveArray_Plane)
                {
                    curveLoop.Append(curve);
                }

                Autodesk.Revit.DB.Floor floor = Autodesk.Revit.DB.Floor.Create(document, new CurveLoop[] { curveLoop }, hostObjAttributes.Id, level.Id);
#endif

                if (floor != null)
                {
                    floor.ChangeTypeId(hostObjAttributes.Id);

                    List <Geometry.Spatial.IClosedPlanar3D> closedPlanar3Ds_Internal = face3D.GetInternalEdge3Ds();
                    if (closedPlanar3Ds_Internal != null && closedPlanar3Ds_Internal.Count > 0)
                    {
                        //Requires to be regenerated before inserting openings
                        //https://thebuildingcoder.typepad.com/blog/2013/07/create-a-floor-with-an-opening-or-complex-boundary.html
                        document.Regenerate();

                        foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D_Internal in face3D.GetInternalEdge3Ds())
                        {
                            List <Geometry.Spatial.Segment3D> segment3Ds_Internal = Geometry.Revit.Query.Segment3Ds(closedPlanar3D_Internal);
                            if (segment3Ds_Internal == null || segment3Ds_Internal.Count == 0)
                            {
                                continue;
                            }

                            curveArray_Plane = new CurveArray();
                            //foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds)
                            foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds_Internal)
                            {
                                curveArray_Sloped.Append(segment3D.ToRevit_Line());

                                Geometry.Spatial.Segment3D segment3D_Temp = Geometry.Spatial.Query.Project(plane, segment3D);
                                if (segment3D_Temp == null)
                                {
                                    continue;
                                }

                                curveArray_Plane.Append(segment3D_Temp.ToRevit_Line());
                            }

                            Opening opening = document.Create.NewOpening(floor, curveArray_Plane, true);
                        }
                    }
                }

                if (floor != null)
                {
                    document.Regenerate();

                    SlabShapeEditor slabShapeEditor = floor.SlabShapeEditor;
                    if (slabShapeEditor != null)
                    {
                        slabShapeEditor.ResetSlabShape();

                        foreach (Curve curve in curveArray_Sloped)
                        {
                            XYZ xYZ = curve.GetEndPoint(0);
                            slabShapeEditor.DrawPoint(xYZ);
                        }
                    }
                }

                builtInParameters = new BuiltInParameter[] { BuiltInParameter.LEVEL_PARAM };
                result            = floor;
            }
            else if (hostObjAttributes is Autodesk.Revit.DB.RoofType)
            {
                CurveArray curveArray = new CurveArray();
                foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D in face3D.GetEdge3Ds())
                {
                    List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Query.Segment3Ds(closedPlanar3D);
                    if (segment3Ds == null || segment3Ds.Count == 0)
                    {
                        return(null);
                    }

                    segment3Ds.ForEach(x => curveArray.Append(x.ToRevit_Line()));
                }

                Level  level          = document.HighLevel(panel.LowElevation());
                double levelElevation = level.Elevation;

                ModelCurveArray modelCurveArray = new ModelCurveArray();
                RoofBase        roofBase        = document.Create.NewFootPrintRoof(curveArray, level, hostObjAttributes as Autodesk.Revit.DB.RoofType, out modelCurveArray);

                Parameter parameter = roofBase.get_Parameter(BuiltInParameter.ROOF_UPTO_LEVEL_PARAM);
                if (parameter != null)
                {
                    parameter.Set(ElementId.InvalidElementId);
                }

                SlabShapeEditor slabShapeEditor = roofBase.SlabShapeEditor;
                if (slabShapeEditor != null)
                {
                    slabShapeEditor.ResetSlabShape();

                    foreach (Curve curve in curveArray)
                    {
                        XYZ xYZ = curve.GetEndPoint(0);
                        //if (Math.Abs(xYZ.Z - levelElevation) > Core.Tolerance.MicroDistance)
                        slabShapeEditor.DrawPoint(xYZ);
                    }
                }

                builtInParameters = new BuiltInParameter[] { BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM, BuiltInParameter.ROOF_BASE_LEVEL_PARAM, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM };
                result            = roofBase;
            }

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

            List <Aperture> apertures = panel.Apertures;
            if (apertures != null)
            {
                if (result is Autodesk.Revit.DB.Wall && ((Autodesk.Revit.DB.Wall)result).WallType.Kind == WallKind.Curtain)
                {
                }
                else
                {
                    foreach (Aperture aperture in apertures)
                    {
                        Geometry.Spatial.Plane plane_Aperture = aperture?.PlanarBoundary3D?.Plane;
                        if (plane_Aperture == null)
                        {
                            continue;
                        }

                        //bool flipHand = !plane_Panel.AxisX.SameHalf(plane_Aperture.AxisX);
                        //bool flipFacing = !plane_Panel.Normal.SameHalf(plane_Aperture.Normal);

                        FamilyInstance failyInstance_Aperture = aperture.ToRevit(document, result, convertSettings);
                    }
                }
            }

            if (convertSettings.ConvertParameters)
            {
                Core.Revit.Modify.SetValues(result, panel, builtInParameters);
                Core.Revit.Modify.SetValues(result, panel, ActiveSetting.Setting);

                Core.Revit.Modify.SetJson(result, panel.ToJObject()?.ToString());
            }
            //TODO: Implement proper log
            //System.IO.File.AppendAllText(@"C:\Users\DengusiakM\Desktop\SAM\2020-04-16 floorbug\LOG.txt", string.Format("{0}\t{1}\t{2}\n", DateTime.Now.ToString(), panel.Guid, panel.Name));

            convertSettings?.Add(panel.Guid, result);

            return(result);
        }
コード例 #25
-1
ファイル: SlabProfile.cs プロジェクト: AMEE/revit
        Matrix4 m_transformMatrix = null; // store the Matrix used to transform Revit coordinate to window UI

        #endregion Fields

        #region Constructors

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="floor">Floor object in Revit</param>
        /// <param name="commandData">contains reference of Revit Application</param>
        public SlabProfile(Autodesk.Revit.DB.Floor floor, ExternalCommandData commandData)
        {
            m_floor = floor;
            m_commandData = commandData;
            m_slabShapeEditor = floor.SlabShapeEditor;
            GetSlabProfileInfo();
        }
コード例 #26
-1
        double m_rotateAngleY = 0;               //rotate angle in Y direction

        #endregion

        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="floor">Floor object in Revit</param>
        /// <param name="commandData">contains reference of Revit Application</param>
        public SlabProfile(Autodesk.Revit.DB.Floor floor, ExternalCommandData commandData)
        {
            m_floor           = floor;
            m_commandData     = commandData;
            m_slabShapeEditor = floor.SlabShapeEditor;
            GetSlabProfileInfo();
        }