static double InHostUnits(double value, DB.ParameterType type, RhinoDoc rhinoDoc)
        {
            if (rhinoDoc is null)
            {
                return(double.NaN);
            }

            switch (type)
            {
            case DB.ParameterType.Length:
                return(value * RhinoMath.UnitScale(rhinoDoc.ModelUnitSystem, UnitSystem.Feet));

            //value *= Math.Pow(RhinoMath.UnitScale(rhinoDoc.ModelUnitSystem, UnitSystem.Millimeters), 1.0);
            //return DB.UnitUtils.ConvertToInternalUnits(value, DB.DisplayUnitType.DUT_MILLIMETERS);

            case DB.ParameterType.Area:
                return(value * Math.Pow(RhinoMath.UnitScale(rhinoDoc.ModelUnitSystem, UnitSystem.Feet), 1.0));

            //value *= Math.Pow(RhinoMath.UnitScale(rhinoDoc.ModelUnitSystem, UnitSystem.Millimeters), 2.0);
            //return DB.UnitUtils.ConvertToInternalUnits(value, DB.DisplayUnitType.DUT_SQUARE_MILLIMETERS);

            case DB.ParameterType.Volume:
                return(value * Math.Pow(RhinoMath.UnitScale(rhinoDoc.ModelUnitSystem, UnitSystem.Feet), 1.0));

            //value *= Math.Pow(RhinoMath.UnitScale(rhinoDoc.ModelUnitSystem, UnitSystem.Millimeters), 3.0);
            //return DB.UnitUtils.ConvertToInternalUnits(value, DB.DisplayUnitType.DUT_CUBIC_MILLIMETERS);

            default:
                Debug.WriteLine(false, $"{nameof(InHostUnits)} do not implement conversion for {type}");
                break;
            }

            return(value);
        }
示例#2
0
        static double InHostUnits(double value, DB.ParameterType type, RhinoDoc rhinoDoc)
        {
            if (rhinoDoc is null)
            {
                return(double.NaN);
            }

            return(InOtherUnits(value, type, rhinoDoc.ModelUnitSystem, UnitSystem.Feet));
        }
示例#3
0
        double ToRhino(double value, DB.ParameterType type)
        {
            switch (type)
            {
            case DB.ParameterType.Length: return(value * Math.Pow(Revit.ModelUnits, 1.0));

            case DB.ParameterType.Area:   return(value * Math.Pow(Revit.ModelUnits, 2.0));

            case DB.ParameterType.Volume: return(value * Math.Pow(Revit.ModelUnits, 3.0));
            }

            return(value);
        }
        static double ToHost(double value, DB.ParameterType parameterType)
        {
            switch (parameterType)
            {
            case DB.ParameterType.Length:  return(value / Math.Pow(Revit.ModelUnits, 1.0));

            case DB.ParameterType.Area:    return(value / Math.Pow(Revit.ModelUnits, 2.0));

            case DB.ParameterType.Volume:  return(value / Math.Pow(Revit.ModelUnits, 3.0));
            }

            return(value);
        }
        static bool TryGetParameterDefinition(DB.Document doc, DB.ElementId id, out DB.StorageType storageType, out DB.ParameterType parameterType)
        {
            if (id.TryGetBuiltInParameter(out var builtInParameter))
            {
                storageType = doc.get_TypeOfStorage(builtInParameter);

                if (storageType == DB.StorageType.ElementId)
                {
                    if (builtInParameter == DB.BuiltInParameter.ELEM_TYPE_PARAM)
                    {
                        parameterType = DB.ParameterType.FamilyType;
                        return(true);
                    }

                    if (builtInParameter == DB.BuiltInParameter.ELEM_CATEGORY_PARAM || builtInParameter == DB.BuiltInParameter.ELEM_CATEGORY_PARAM_MT)
                    {
                        parameterType = (DB.ParameterType) int.MaxValue;
                        return(true);
                    }
                }

                if (storageType == DB.StorageType.Double)
                {
                    if (BuiltInParametersTypes.TryGetValue(builtInParameter, out parameterType))
                    {
                        return(true);
                    }

                    var categoriesWhereDefined = doc.GetBuiltInCategoriesWithParameters().
                                                 Select(bic => new DB.ElementId(bic)).
                                                 Where(cid => DB.TableView.GetAvailableParameters(doc, cid).Contains(id)).
                                                 ToArray();

                    using (var collector = new DB.FilteredElementCollector(doc))
                    {
                        using
                        (
                            var filteredCollector = categoriesWhereDefined.Length == 0 ?
                                                    collector.WherePasses(new DB.ElementClassFilter(typeof(DB.ParameterElement), false)) :
                                                    categoriesWhereDefined.Length > 1 ?
                                                    collector.WherePasses(new DB.ElementMulticategoryFilter(categoriesWhereDefined)) :
                                                    collector.WherePasses(new DB.ElementCategoryFilter(categoriesWhereDefined[0]))
                        )
                        {
                            foreach (var element in filteredCollector)
                            {
                                var parameter = element.get_Parameter(builtInParameter);
                                if (parameter is null)
                                {
                                    continue;
                                }

                                parameterType = parameter.Definition.ParameterType;
                                BuiltInParametersTypes.Add(builtInParameter, parameterType);
                                return(true);
                            }
                        }
                    }

                    parameterType = DB.ParameterType.Invalid;
                    return(false);
                }

                parameterType = DB.ParameterType.Invalid;
                return(true);
            }
            else
            {
                try
                {
                    if (doc.GetElement(id) is DB.ParameterElement parameter)
                    {
                        storageType   = parameter.GetDefinition().ParameterType.ToStorageType();
                        parameterType = parameter.GetDefinition().ParameterType;
                        return(true);
                    }
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException) { }
            }

            storageType   = DB.StorageType.None;
            parameterType = DB.ParameterType.Invalid;
            return(false);
        }
 public static double InHostUnits(double value, DB.ParameterType type) =>
 InHostUnits(value, type, RhinoDoc.ActiveDoc);
示例#7
0
        static double InOtherUnits(double value, DB.ParameterType type, UnitSystem from, UnitSystem to)
        {
            switch (type)
            {
                #region Length

            case DB.ParameterType.Length:
            case DB.ParameterType.ForceLengthPerAngle:
            case DB.ParameterType.LinearForceLengthPerAngle:
            case DB.ParameterType.ReinforcementLength:

            case DB.ParameterType.AreaForcePerLength:
            case DB.ParameterType.ReinforcementAreaPerUnitLength:

                return(value * RhinoMath.UnitScale(from, to));

            case DB.ParameterType.ForcePerLength:
            case DB.ParameterType.LinearForcePerLength:
            case DB.ParameterType.MassPerUnitLength:
            case DB.ParameterType.WeightPerUnitLength:
            case DB.ParameterType.PipeMassPerUnitLength:

                return(value / RhinoMath.UnitScale(from, to));

                #endregion

                #region Area

            case DB.ParameterType.Area:
            case DB.ParameterType.AreaForce:
            case DB.ParameterType.HVACAreaDividedByCoolingLoad:
            case DB.ParameterType.HVACAreaDividedByHeatingLoad:
            case DB.ParameterType.SurfaceArea:
            case DB.ParameterType.ReinforcementArea:
            case DB.ParameterType.SectionArea:

                return(value * Math.Pow(RhinoMath.UnitScale(from, to), 2.0));

            case DB.ParameterType.HVACCoolingLoadDividedByArea:
            case DB.ParameterType.HVACHeatingLoadDividedByArea:
            case DB.ParameterType.MassPerUnitArea:

                return(value / Math.Pow(RhinoMath.UnitScale(from, to), 2.0));

                #endregion

                #region Volume

            case DB.ParameterType.Volume:
            case DB.ParameterType.PipingVolume:
            case DB.ParameterType.ReinforcementVolume:

                return(value * Math.Pow(RhinoMath.UnitScale(from, to), 3.0));

            case DB.ParameterType.HVACCoolingLoadDividedByVolume:
            case DB.ParameterType.HVACHeatingLoadDividedByVolume:
            case DB.ParameterType.HVACAirflowDividedByVolume:

                return(value * Math.Pow(RhinoMath.UnitScale(from, to), 3.0));

                #endregion

            default:
                Debug.WriteLine($"{nameof(InOtherUnits)} do not implement conversion for {type}");
                break;
            }

            return(value);
        }