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()
     });
Beispiel #2
0
        void ReconstructRailingByCurve
        (
            DB.Document doc,
            ref DB.Architecture.Railing element,

            Rhino.Geometry.Curve curve,
            Optional <DB.Architecture.RailingType> type,
            Optional <DB.Level> level,
            [Optional] DB.Element host,
            [Optional] bool flipped
        )
        {
            SolveOptionalType(ref type, doc, DB.ElementTypeGroup.StairsRailingType, nameof(type));
            SolveOptionalLevel(doc, curve, ref level, out var bbox);

            // Axis
            var levelPlane = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0.0, 0.0, level.Value.Elevation * Revit.ModelUnits), Rhino.Geometry.Vector3d.ZAxis);

            curve = Rhino.Geometry.Curve.ProjectToPlane(curve, levelPlane);
            curve = curve.Simplify(Rhino.Geometry.CurveSimplifyOptions.All, Revit.VertexTolerance * Revit.ModelUnits, Revit.AngleTolerance) ?? curve;

            // Type
            ChangeElementTypeId(ref element, type.Value.Id);

            DB.Architecture.Railing newRail = null;
            if (element is DB.Architecture.Railing previousRail)
            {
                newRail = previousRail;

                newRail.SetPath(curve.ToCurveLoop());
            }
            else
            {
                newRail = DB.Architecture.Railing.Create
                          (
                    doc,
                    curve.ToCurveLoop(),
                    type.Value.Id,
                    level.Value.Id
                          );

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

                ReplaceElement(ref element, newRail, parametersMask);
            }

            if (newRail is object)
            {
                using (var baseLevel = newRail.get_Parameter(DB.BuiltInParameter.STAIRS_RAILING_BASE_LEVEL_PARAM))
                {
                    if (!baseLevel.IsReadOnly)
                    {
                        baseLevel.Set(level.Value.Id);
                    }
                }
                using (var heightOffset = newRail.get_Parameter(DB.BuiltInParameter.STAIRS_RAILING_HEIGHT_OFFSET))
                {
                    if (!heightOffset.IsReadOnly)
                    {
                        heightOffset.Set(bbox.Min.Z / Revit.ModelUnits - level.Value.Elevation);
                    }
                }

                newRail.HostId = host?.Id ?? DB.ElementId.InvalidElementId;

                if (newRail.Flipped != flipped)
                {
                    newRail.Flip();
                }
            }
        }