Esempio n. 1
0
        private Base BeamToSpeckle(DB.FamilyInstance revitBeam)
        {
            var baseGeometry = LocationToSpeckle(revitBeam);
            var baseLine     = baseGeometry as ICurve;

            if (baseLine == null)
            {
                Report.Log($"Beam has no valid baseline, converting as generic element {revitBeam.Id}");
                return(RevitElementToSpeckle(revitBeam));
            }
            var symbol = Doc.GetElement(revitBeam.GetTypeId()) as FamilySymbol;

            var speckleBeam = new RevitBeam();

            speckleBeam.family      = symbol.FamilyName;
            speckleBeam.type        = Doc.GetElement(revitBeam.GetTypeId()).Name;
            speckleBeam.baseLine    = baseLine;
            speckleBeam.level       = ConvertAndCacheLevel(revitBeam, BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);
            speckleBeam.displayMesh = GetElementMesh(revitBeam);

            GetAllRevitParamsAndIds(speckleBeam, revitBeam);

            //Report.Log($"Converted Beam {revitBeam.Id}");
            return(speckleBeam);
        }
        public Base ColumnToSpeckle(DB.FamilyInstance revitColumn)
        {
            var symbol = Doc.GetElement(revitColumn.GetTypeId()) as FamilySymbol;

            var speckleColumn = new RevitColumn();

            speckleColumn.family        = symbol.FamilyName;
            speckleColumn.type          = Doc.GetElement(revitColumn.GetTypeId()).Name;
            speckleColumn.level         = ConvertAndCacheLevel(revitColumn, BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);
            speckleColumn.topLevel      = ConvertAndCacheLevel(revitColumn, BuiltInParameter.FAMILY_TOP_LEVEL_PARAM);
            speckleColumn.baseOffset    = GetParamValue <double>(revitColumn, BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM);
            speckleColumn.topOffset     = GetParamValue <double>(revitColumn, BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM);
            speckleColumn.facingFlipped = revitColumn.FacingFlipped;
            speckleColumn.handFlipped   = revitColumn.HandFlipped;
            speckleColumn.isSlanted     = revitColumn.IsSlantedColumn;
            //speckleColumn.structural = revitColumn.StructuralType == StructuralType.Column;

            //geometry
            var baseGeometry = LocationToSpeckle(revitColumn);
            var baseLine     = baseGeometry as ICurve;

            //make line from point and height
            if (baseLine == null && baseGeometry is Point basePoint)
            {
                var elevation = ConvertAndCacheLevel(revitColumn, BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).elevation;
                baseLine = new Line(basePoint, new Point(basePoint.x, basePoint.y, elevation + speckleColumn.topOffset, ModelUnits), ModelUnits);
            }

            if (baseLine == null)
            {
                return(RevitElementToSpeckle(revitColumn));
            }

            speckleColumn.baseLine = baseLine; //all speckle columns should be line based

            GetAllRevitParamsAndIds(speckleColumn, revitColumn,
                                    new List <string> {
                "FAMILY_BASE_LEVEL_PARAM", "FAMILY_TOP_LEVEL_PARAM", "FAMILY_BASE_LEVEL_OFFSET_PARAM", "FAMILY_TOP_LEVEL_OFFSET_PARAM", "SCHEDULE_BASE_LEVEL_OFFSET_PARAM", "SCHEDULE_TOP_LEVEL_OFFSET_PARAM"
            });

            if (revitColumn.Location is LocationPoint)
            {
                speckleColumn.rotation = ((LocationPoint)revitColumn.Location).Rotation;
            }

            speckleColumn.displayMesh = GetElementMesh(revitColumn);

            return(speckleColumn);
        }
Esempio n. 3
0
        public static SpeckleObject BeamToSpeckle(Autodesk.Revit.DB.FamilyInstance myFamily)
        {
            // Generate Beam
            var myBeam    = new Beam();
            var allSolids = GetElementSolids(myFamily, opt: new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = true
            });

            (myBeam.Faces, myBeam.Vertices) = GetFaceVertexArrFromSolids(allSolids);
            var baseCurve = myFamily.Location as LocationCurve;

            myBeam.baseLine = (SpeckleObject)Converter.Serialise(baseCurve.Curve);

            myBeam.beamFamily = myFamily.Symbol.FamilyName;
            myBeam.beamType   = Doc.GetElement(myFamily.GetTypeId()).Name;

            myBeam.parameters     = GetElementParams(myFamily);
            myBeam.typeParameters = GetElementTypeParams(myFamily);

            //myFamily.just

            myBeam.GenerateHash();
            myBeam.ApplicationId = myFamily.UniqueId;
            myBeam.elementId     = myFamily.Id.ToString();

            //var analyticalModel = AnalyticalStickToSpeckle(myFamily);

            return(myBeam);//.Concat(analyticalModel).ToList();
        }
Esempio n. 4
0
        private AdaptiveComponent AdaptiveComponentToSpeckle(DB.FamilyInstance revitAc)
        {
            var speckleAc = new AdaptiveComponent();

            speckleAc.type        = Doc.GetElement(revitAc.GetTypeId()).Name;
            speckleAc.basePoints  = GetAdaptivePoints(revitAc);
            speckleAc.flipped     = AdaptiveComponentInstanceUtils.IsInstanceFlipped(revitAc);
            speckleAc.displayMesh = GetElementMesh(revitAc);

            GetAllRevitParamsAndIds(speckleAc, revitAc);

            return(speckleAc);
        }
Esempio n. 5
0
        public RevitColumn ColumnToSpeckle(DB.FamilyInstance revitColumn)
        {
            var speckleColumn = new RevitColumn();

            speckleColumn.type          = Doc.GetElement(revitColumn.GetTypeId()).Name;
            speckleColumn.level         = ConvertAndCacheLevel(revitColumn, BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);
            speckleColumn.topLevel      = ConvertAndCacheLevel(revitColumn, BuiltInParameter.FAMILY_TOP_LEVEL_PARAM);
            speckleColumn.baseOffset    = GetParamValue <double>(revitColumn, BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM);
            speckleColumn.topOffset     = GetParamValue <double>(revitColumn, BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM);
            speckleColumn.facingFlipped = revitColumn.FacingFlipped;
            speckleColumn.handFlipped   = revitColumn.HandFlipped;
            speckleColumn.isSlanted     = revitColumn.IsSlantedColumn;
            speckleColumn.structural    = revitColumn.StructuralType == StructuralType.Column;

            //geometry
            var baseGeometry = LocationToSpeckle(revitColumn);
            var baseLine     = baseGeometry as ICurve;

            //make line from point and height
            if (baseLine == null && baseGeometry is Point basePoint)
            {
                var topLevelParam = revitColumn.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM);
                var elevation     = (double)((RevitLevel)ParameterToSpeckle(topLevelParam).value).elevation;
                baseLine = new Line(basePoint, new Point(basePoint.x, basePoint.y, elevation + speckleColumn.topOffset, ModelUnits), ModelUnits);
            }

            if (baseLine == null)
            {
                throw new Speckle.Core.Logging.SpeckleException("Only line based Columns are currently supported.");
            }

            speckleColumn.baseLine = baseLine; //all speckle columns should be line based

            GetAllRevitParamsAndIds(speckleColumn, revitColumn,
                                    new List <string> {
                "FAMILY_BASE_LEVEL_PARAM", "FAMILY_TOP_LEVEL_PARAM", "FAMILY_BASE_LEVEL_OFFSET_PARAM", "FAMILY_TOP_LEVEL_OFFSET_PARAM"
            });

            if (revitColumn.Location is LocationPoint)
            {
                speckleColumn.rotation = ((LocationPoint)revitColumn.Location).Rotation;
            }

            speckleColumn["@displayMesh"] = GetElementMesh(revitColumn);

            return(speckleColumn);
        }
Esempio n. 6
0
        private RevitBeam BeamToSpeckle(DB.FamilyInstance revitBeam)
        {
            var baseGeometry = LocationToSpeckle(revitBeam);
            var baseLine     = baseGeometry as ICurve;

            if (baseLine == null)
            {
                throw new Exception("Only line based Beams are currently supported.");
            }

            var speckleBeam = new RevitBeam();

            speckleBeam.type            = Doc.GetElement(revitBeam.GetTypeId()).Name;
            speckleBeam.baseLine        = baseLine;
            speckleBeam.level           = ConvertAndCacheLevel(revitBeam, BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);
            speckleBeam["@displayMesh"] = GetElementMesh(revitBeam);

            GetAllRevitParamsAndIds(speckleBeam, revitBeam);

            return(speckleBeam);
        }
Esempio n. 7
0
        private Base BeamToSpeckle(DB.FamilyInstance revitBeam)
        {
            var baseGeometry = LocationToSpeckle(revitBeam);
            var baseLine     = baseGeometry as ICurve;

            if (baseLine == null)
            {
                return(RevitElementToSpeckle(revitBeam));
            }

            var speckleBeam = new RevitBeam();

            speckleBeam.type        = Doc.GetElement(revitBeam.GetTypeId()).Name;
            speckleBeam.baseLine    = baseLine;
            speckleBeam.level       = ConvertAndCacheLevel(revitBeam, BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);
            speckleBeam.displayMesh = GetElementMesh(revitBeam);

            GetAllRevitParamsAndIds(speckleBeam, revitBeam);

            return(speckleBeam);
        }
Esempio n. 8
0
        /// <summary>
        /// Entry point for all revit family conversions. TODO: Check for Beams and Columns and any other "dedicated" speckle elements and convert them as such rather than to the generic "family instance" object.
        /// </summary>
        /// <param name="myElement"></param>
        /// <returns></returns>
        public Base FamilyInstanceToSpeckle(DB.FamilyInstance revitFi)
        {
            if (!ShouldConvertHostedElement(revitFi, revitFi.Host))
            {
                return(null);
            }

            //adaptive components
            if (AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(revitFi))
            {
                return(AdaptiveComponentToSpeckle(revitFi));
            }

            //these elements come when the curtain wall is generated
            //let's not send them to speckle unless we realize they are needed!
            if (Categories.curtainWallSubElements.Contains(revitFi.Category))
            {
                return(null);
            }

            //beams & braces
            if (Categories.beamCategories.Contains(revitFi.Category))
            {
                if (revitFi.StructuralType == StructuralType.Beam)
                {
                    return(BeamToSpeckle(revitFi));
                }
                else if (revitFi.StructuralType == StructuralType.Brace)
                {
                    return(BraceToSpeckle(revitFi));
                }
            }

            //columns
            if (Categories.columnCategories.Contains(revitFi.Category) || revitFi.StructuralType == StructuralType.Column)
            {
                return(ColumnToSpeckle(revitFi));
            }

            var baseGeometry = LocationToSpeckle(revitFi);
            var basePoint    = baseGeometry as Point;

            if (basePoint == null)
            {
                return(RevitElementToSpeckle(revitFi));
            }

            var lev1 = ConvertAndCacheLevel(revitFi, BuiltInParameter.FAMILY_LEVEL_PARAM);
            var lev2 = ConvertAndCacheLevel(revitFi, BuiltInParameter.FAMILY_BASE_LEVEL_PARAM);

            var symbol = Doc.GetElement(revitFi.GetTypeId()) as FamilySymbol;

            var speckleFi = new BuiltElements.Revit.FamilyInstance();

            speckleFi.basePoint     = basePoint;
            speckleFi.family        = symbol.FamilyName;
            speckleFi.type          = symbol.Name;
            speckleFi.category      = revitFi.Category.Name;
            speckleFi.facingFlipped = revitFi.FacingFlipped;
            speckleFi.handFlipped   = revitFi.HandFlipped;
            speckleFi.level         = lev1 != null ? lev1 : lev2;

            if (revitFi.Location is LocationPoint)
            {
                speckleFi.rotation = ((LocationPoint)revitFi.Location).Rotation;
            }

            speckleFi.displayMesh = GetElementMesh(revitFi, GetAllFamSubElements(revitFi));

            GetAllRevitParamsAndIds(speckleFi, revitFi);

            #region sub elements capture

            var subElementIds        = revitFi.GetSubComponentIds();
            var convertedSubElements = new List <Base>();

            foreach (var elemId in subElementIds)
            {
                var subElem = Doc.GetElement(elemId);
                if (CanConvertToSpeckle(subElem))
                {
                    var obj = ConvertToSpeckle(subElem);

                    if (obj != null)
                    {
                        convertedSubElements.Add(obj);
                        ConvertedObjectsList.Add(obj.applicationId);
                    }
                }
            }

            if (convertedSubElements.Any())
            {
                speckleFi.elements = convertedSubElements;
            }

            #endregion

            // TODO:
            // revitFi.GetSubelements();
            //Report.Log($"Converted FamilyInstance {revitFi.Id}");
            return(speckleFi);
        }
Esempio n. 9
0
        public static SpeckleObject ColumnToSpeckle(Autodesk.Revit.DB.FamilyInstance myFamily)
        {
            var myColumn = new Column();

            var baseLevel = (Autodesk.Revit.DB.Level)Doc.GetElement(myFamily.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).AsElementId());
            var topLevel  = (Autodesk.Revit.DB.Level)Doc.GetElement(myFamily.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).AsElementId());

            myColumn.baseLevel = baseLevel?.ToSpeckle();
            myColumn.topLevel  = topLevel?.ToSpeckle();

            try
            {
                myColumn.baseLine = (SpeckleCoreGeometryClasses.SpeckleLine)SpeckleCore.Converter.Serialise(myFamily.GetAnalyticalModel().GetCurve());
            }
            catch
            {
                var basePt = (myFamily.Location as LocationPoint).Point;
                var topPt  = new XYZ(basePt.X, basePt.Y, topLevel.Elevation);
                myColumn.baseLine = (SpeckleCoreGeometryClasses.SpeckleLine)SpeckleCore.Converter.Serialise(Autodesk.Revit.DB.Line.CreateBound(basePt, topPt));
            }

            myColumn.columnFamily = myFamily.Symbol.FamilyName;
            myColumn.columnType   = Doc.GetElement(myFamily.GetTypeId()).Name;

            myColumn.parameters = GetElementParams(myFamily);



            // TODO: Maybe move this column properties in the class defintion
            myColumn.Properties["__facingFlipped"] = myFamily.FacingFlipped;
            myColumn.Properties["__handFlipped"]   = myFamily.HandFlipped;

            if (myFamily.Location is LocationPoint)
            {
                myColumn.Properties["__rotation"] = ((LocationPoint)myFamily.Location).Rotation;
            }
            else if (myFamily.Location is LocationCurve)
            {
                var myAngle = myFamily.get_Parameter(BuiltInParameter.STRUCTURAL_BEND_DIR_ANGLE).AsDouble(); // Stands for cross-section rotation!
                var rads    = UnitUtils.ConvertFromInternalUnits(myAngle, DisplayUnitType.DUT_RADIANS);
                myColumn.Properties["__rotation"] = rads;

                // TODO: Figure this column rotation shit out.
                // For now... Do nothing??
                //var t = myFamily.GetTotalTransform();
            }


            myColumn.GenerateHash();
            myColumn.ApplicationId = myFamily.UniqueId;
            myColumn.elementId     = myFamily.Id.ToString();

            // leaving the mesh out of the hashing process might address the randomatic hash generation we're getting
            // and hence the nuking the usability of local caching and diffing
            var allSolids = GetElementSolids(myFamily, opt: new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = true
            });

            (myColumn.Faces, myColumn.Vertices) = GetFaceVertexArrFromSolids(allSolids);

            return(myColumn);
        }