Exemple #1
0
        /// <summary>
        /// Converts a list of vectors from the units from an IFC file to the corresponding Revit internal units.
        /// </summary>
        /// <param name="specTypeId">Identifier of the spec for this value.</param>
        /// <param name="inValue">The value to convert.</param>
        /// <returns>The result value in Revit internal units.</returns>
        /// <remarks>Note that the OffsetFactor is ignored.</remarks>
        static public void ProjectScale(ForgeTypeId specTypeId, IList <XYZ> inValues)
        {
            if (inValues == null)
            {
                return;
            }

            IFCUnit projectUnit = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(specTypeId);

            if (projectUnit == null)
            {
                return;
            }

            double factor = projectUnit.ScaleFactor;

            if (MathUtil.IsAlmostEqual(factor, 1.0))
            {
                return;
            }

            int count = inValues.Count;

            for (int ii = 0; ii < count; ii++)
            {
                inValues[ii] *= factor;
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates or populates Revit element params based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        protected override void CreateParametersInternal(Document doc, Element element)
        {
            base.CreateParametersInternal(doc, element);
            string parameterName = "LandTitleNumber";

            // TODO: move this to new shared parameter names override function.
            if (element is ProjectInfo)
            {
                parameterName = "IfcSite " + parameterName;
            }

            if (element != null)
            {
                string landTitleNumber = LandTitleNumber;
                if (!string.IsNullOrWhiteSpace(landTitleNumber))
                {
                    Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);
                    IFCPropertySet.AddParameterString(doc, element, category, this, parameterName, landTitleNumber, Id);
                }
            }

            ForgeTypeId lengthUnits = null;

            if (!Importer.TheProcessor.ScaleValues)
            {
                lengthUnits = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(SpecTypeId.Length)?.Unit;
            }

            Importer.TheProcessor.PostProcessSite(Id, RefLatitude,
                                                  RefLongitude, RefElevation, LandTitleNumber, lengthUnits,
                                                  ObjectLocation?.TotalTransform);
        }
Exemple #3
0
 /// <summary>
 /// Create a new FieldData object
 /// </summary>
 /// <param name="name">The name of the field</param>
 /// <param name="typeIn">The AssemblyQualifiedName of the Field's data type</param>
 /// <param name="spec">The unit type of the Field (set to UT_Undefined for non-floating point types</param>
 /// <param name="subSchema">The SchemaWrapper of the field's subSchema, if the field is of type "Entity"</param>
 public FieldData(string name, string typeIn, ForgeTypeId spec, SchemaWrapper subSchema)
 {
     m_Name      = name;
     m_Type      = typeIn;
     m_Spec      = spec;
     m_SubSchema = subSchema;
 }
        private string UnitsToSpeckle(ForgeTypeId typeId)
        {
            if (typeId == UnitTypeId.Millimeters)
            {
                return(Speckle.Core.Kits.Units.Millimeters);
            }
            else if (typeId == UnitTypeId.Centimeters)
            {
                return(Speckle.Core.Kits.Units.Centimeters);
            }
            else if (typeId == UnitTypeId.Meters)
            {
                return(Speckle.Core.Kits.Units.Meters);
            }
            else if (typeId == UnitTypeId.Inches)
            {
                return(Speckle.Core.Kits.Units.Inches);
            }
            else if (typeId == UnitTypeId.Feet)
            {
                return(Speckle.Core.Kits.Units.Feet);
            }

            throw new Speckle.Core.Logging.SpeckleException("The current Unit System is unsupported.");
        }
Exemple #5
0
        /// <summary>
        /// Processes the metric prefix of a dimension.
        /// </summary>
        /// <param name="prefix">The prefix name.</param>
        /// <param name="specTypeId">The spec identifier.</param>
        /// <returns>True if the prefix is supported, false if not.</returns>
        private bool ProcessMetricPrefix(string prefix, ForgeTypeId specTypeId)
        {
            if (prefix == null)
            {
                prefix = "";
            }

            IDictionary <string, KeyValuePair <ForgeTypeId, ForgeTypeId> > supportedDisplayTypes = GetSupportedDisplayTypes(specTypeId);

            if (!supportedDisplayTypes.ContainsKey(prefix))
            {
                return(false);
            }

            if (m_sPrefixToScaleFactor == null)
            {
                InitPrefixToScaleFactor();
            }

            if (!m_sPrefixToScaleFactor.ContainsKey(prefix))
            {
                return(false);
            }

            KeyValuePair <ForgeTypeId, ForgeTypeId> unitNameAndSymbol = supportedDisplayTypes[prefix];

            Unit         = unitNameAndSymbol.Key;
            Symbol       = unitNameAndSymbol.Value;
            ScaleFactor *= GetScaleFactorForUnitType(prefix, specTypeId);
            return(true);
        }
Exemple #6
0
        /// <summary>
        /// Gets the unit of a type.
        /// </summary>
        /// <param name="specTypeId">Identifier of the spec.</param>
        /// <returns>The Unit object.</returns>
        public IFCUnit GetIFCProjectUnit(ForgeTypeId specTypeId)
        {
            IFCUnit projectUnit = null;

            if (m_ProjectUnitsDictionary.TryGetValue(specTypeId, out projectUnit))
            {
                return(projectUnit);
            }
            else
            {
                //default units
                if (specTypeId.Equals(SpecTypeId.Length))
                {
                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, UnitSystem.Metric, UnitTypeId.Meters, 1.0 / 0.3048);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
                else if (specTypeId.Equals(SpecTypeId.Area))
                {
                    IFCUnit projectLengthUnit = GetIFCProjectUnit(SpecTypeId.Length);

                    UnitSystem  unitSystem = projectLengthUnit.UnitSystem;
                    ForgeTypeId unitName   = unitSystem == UnitSystem.Metric ?
                                             UnitTypeId.SquareMeters : UnitTypeId.SquareFeet;
                    double scaleFactor = unitSystem == UnitSystem.Metric ?
                                         (1.0 / 0.3048) * (1.0 / 0.3048) : 1.0;

                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, unitSystem, unitName, scaleFactor);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
                else if (specTypeId.Equals(SpecTypeId.Volume))
                {
                    IFCUnit projectLengthUnit = GetIFCProjectUnit(SpecTypeId.Length);

                    UnitSystem  unitSystem = projectLengthUnit.UnitSystem;
                    ForgeTypeId unitName   = unitSystem == UnitSystem.Metric ?
                                             UnitTypeId.CubicMeters : UnitTypeId.CubicFeet;
                    double scaleFactor = unitSystem == UnitSystem.Metric ?
                                         (1.0 / 0.3048) * (1.0 / 0.3048) * (1.0 / 0.3048) : 1.0;

                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, unitSystem, unitName, scaleFactor);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
                else if (specTypeId.Equals(SpecTypeId.Angle))
                {
                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, UnitSystem.Metric, UnitTypeId.Degrees, Math.PI / 180);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
                else if (specTypeId.Equals(SpecTypeId.HvacTemperature))
                {
                    IFCUnit unit = IFCUnit.ProcessIFCDefaultUnit(specTypeId, UnitSystem.Metric, UnitTypeId.Kelvin, 1.0);
                    m_ProjectUnitsDictionary[specTypeId] = unit;
                    return(unit);
                }
            }
            return(null);
        }
Exemple #7
0
        public static Definition GetOrCreateSharedParamsDefinition(
            DefinitionGroup defGroup,
            ForgeTypeId forgeTypeId,
            string defName,
            bool visible)
        {
            Definition definition = defGroup.Definitions.get_Item(defName);

            if (null == definition)
            {
                try
                {
                    //definition = defGroup.Definitions.Create(defName, defType, visible);

                    // 'Autodesk.Revit.DB.Definitions.Create(string, Autodesk.Revit.DB.ParameterType, bool)' is obsolete:
                    // 'This method is deprecated in Revit 2015. Use Create(Autodesk.Revit.DB.ExternalDefinitonCreationOptions) instead'

                    // Modified code for Revit 2015
                    // and fixed typo in class name in Revit 2016

                    ExternalDefinitionCreationOptions opt
                        = new ExternalDefinitionCreationOptions(
                              defName, forgeTypeId);
                    opt.Visible = true;
                    definition  = defGroup.Definitions.Create(opt);
                }
                catch (Exception)
                {
                    definition = null;
                }
            }
            return(definition);
        }
Exemple #8
0
        /// <summary>
        /// Processes an IFC unit in the property.
        /// </summary>
        /// <param name="ifcSimpleProperty">The simple property.</param>
        /// <param name="simplePropertyHandle">The simple property handle.</param>
        static protected void ProcessIFCSimplePropertyUnit(IFCSimpleProperty ifcSimpleProperty, IFCAnyHandle simplePropertyHandle)
        {
            IFCAnyHandle ifcUnitHandle = IFCImportHandleUtil.GetOptionalInstanceAttribute(simplePropertyHandle, "Unit");
            IFCUnit      ifcUnit       = (ifcUnitHandle != null) ? IFCUnit.ProcessIFCUnit(ifcUnitHandle) : null;

            if (ifcUnit == null)
            {
                if (ifcSimpleProperty.IFCPropertyValues.Count > 0)
                {
                    IFCPropertyValue propertyValue = ifcSimpleProperty.IFCPropertyValues[0];
                    if (propertyValue != null && propertyValue.HasValue() &&
                        (propertyValue.Type == IFCDataPrimitiveType.Integer) || (propertyValue.Type == IFCDataPrimitiveType.Double))
                    {
                        string      unitTypeName;
                        ForgeTypeId specTypeId = IFCDataUtil.GetUnitTypeFromData(propertyValue.Value, new ForgeTypeId(), out unitTypeName);
                        if (!specTypeId.Empty())
                        {
                            ifcUnit = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(specTypeId);
                        }
                        else
                        {
                            Importer.TheLog.LogWarning(simplePropertyHandle.StepId, "Unhandled unit type: " + unitTypeName, true);
                        }
                    }
                }
            }

            ifcSimpleProperty.m_IFCUnit = ifcUnit;
        }
        // ======================================
        //   (3.1) add parameters
        // ======================================
        void addParameters()
        {
            FamilyManager mgr = _doc.FamilyManager;

            // API parameter group for Dimension is PG_GEOMETRY:
            //
            ForgeTypeId     builtinParamGroup = new ForgeTypeId(GroupTypeId.Geometry.TypeId);
            ForgeTypeId     parametertype     = SpecTypeId.Length;
            FamilyParameter paramTw           = mgr.AddParameter(
                "Tw", builtinParamGroup,
                parametertype, false);

            FamilyParameter paramTd = mgr.AddParameter(
                "Td", builtinParamGroup,
                parametertype, false);

            // set initial values:
            //
            double tw = mmToFeet(150.0);
            double td = mmToFeet(150.0);

            mgr.Set(paramTw, tw);
            mgr.Set(paramTd, td);

            // (2)  add a parameter for material finish
            // we are adding material arameter in addMaterials function.
            // See addMaterials for the actual implementation.
            //
        }
Exemple #10
0
        /// <summary>
        /// Add a double parameter to an element.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element.</param>
        /// <param name="category">The category of the element.</param>
        /// <param name="parameterName">The parameter name.</param>
        /// <param name="specTypeId">Identifier of the parameter spec (e.g. length)</param>
        /// <param name="unitsTypeId">Identifier of the unscaled parameter units (e.g. mm)</param>
        /// <param name="parameterValue">The parameter value, scaled into document units.</param>
        /// <param name="parameterSetId">The id of the containing parameter set, for reporting errors.</param>
        /// <returns>True if the parameter was successfully added, false otherwise.</returns>
        public static bool AddParameterDouble(Document doc, Element element, Category category,
                                              IFCObjectDefinition objDef, string parameterName, ForgeTypeId specTypeId,
                                              ForgeTypeId unitsTypeId, double parameterValue, int parameterSetId)
        {
            if (doc == null || element == null || category == null)
            {
                return(false);
            }

            unitsTypeId = CalculateUnitsTypeId(unitsTypeId, specTypeId);
            bool?processedParameter = Importer.TheProcessor.ProcessParameter(objDef.Id,
                                                                             specTypeId, unitsTypeId, parameterSetId, parameterName, parameterValue);

            if (processedParameter.HasValue)
            {
                return(processedParameter.Value);
            }

            Parameter parameter = AddParameterBase(doc, element, category, parameterName, parameterSetId, specTypeId);

            if (parameter == null)
            {
                return(false);
            }

            parameter.Set(parameterValue);
            return(true);
        }
        object Process(ExpectedValueEnum expectedValueType)
        {
            object                 val    = null;
            AntlrInputStream       input  = new AntlrInputStream(paramExprContent);
            ParamExprGrammarLexer  lexer  = new ParamExprGrammarLexer(input);
            CommonTokenStream      tokens = new CommonTokenStream(lexer);
            ParamExprGrammarParser parser = new ParamExprGrammarParser(tokens);

            parser.RemoveErrorListeners();
            ParamExprLogger.resetStream();
            parser.AddErrorListener(new ParamExprErrorListener());
            IParseTree        tree   = parser.param_expr();
            ParseTreeWalker   walker = new ParseTreeWalker();
            ParamExprListener eval   = new ParamExprListener(tokens);

            eval.RevitElement       = _element;
            eval.RevitParameterName = _paramName;

            try
            {
                walker.Walk(eval, tree);
                if (eval.HasValue)
                {
                    val      = eval.Value;
                    UnitType = eval.UnitType;
                }
            }
            catch
            {
            }
            return(val);
        }
        // ======================================
        //   (3.1) add parameters
        // ======================================
        void addParameters()
        {
            FamilyManager mgr = _doc.FamilyManager;

            // API parameter group for Dimension is PG_GEOMETRY:
            //
            ForgeTypeId builtinParamGroup = new ForgeTypeId(GroupTypeId.Geometry.TypeId);
            ForgeTypeId parameterTypeId   = SpecTypeId.Length;

            FamilyParameter paramTw = mgr.AddParameter(
                "Tw", builtinParamGroup,
                parameterTypeId, false);

            FamilyParameter paramTd = mgr.AddParameter(
                "Td", builtinParamGroup,
                parameterTypeId, false);

            // set initial values:
            //
            double tw = mmToFeet(150.0);
            double td = mmToFeet(150.0);

            mgr.Set(paramTw, tw);
            mgr.Set(paramTd, td);
        }
Exemple #13
0
        /// <summary>
        /// Create a property set for a given element.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="element">The element being created.</param>
        /// <param name="parameterGroupMap">The parameters of the element.  Cached for performance.</param>
        /// <returns>The name of the property set created, if it was created, and a Boolean value if it should be added to the property set list.</returns>
        public override Tuple <string, bool> CreatePropertySet(Document doc, Element element, IFCObjectDefinition objDef, IFCParameterSetByGroup parameterGroupMap)
        {
            IDictionary <string, IFCData> parametersToAdd = new Dictionary <string, IFCData>();
            Category category = IFCPropertySet.GetCategoryForParameterIfValid(element, Id);

            foreach (KeyValuePair <Tuple <string, ForgeTypeId, AllowedValues>, double> property in DoubleProperties)
            {
                string    name = property.Key.Item1;
                Parameter existingParameter = null;
                if (!parameterGroupMap.TryFindParameter(name, out existingParameter))
                {
                    ForgeTypeId valueType = property.Key.Item2;
                    // If we aren't scaling values, all length values have come from Attributes
                    // and so will always be in feet.
                    ForgeTypeId unitType = (!Importer.TheProcessor.ScaleValues && valueType == SpecTypeId.Length) ?
                                           UnitTypeId.Feet : null;
                    IFCPropertySet.AddParameterDouble(doc, element, category, objDef, name, valueType, unitType, property.Value, Id);
                    continue;
                }

                switch (existingParameter.StorageType)
                {
                case StorageType.String:
                    existingParameter.Set(property.Value.ToString());
                    break;

                case StorageType.Double:
                    existingParameter.Set(property.Value);
                    break;

                default:
                    Importer.TheLog.LogError(Id, "couldn't create parameter: " + name + " of storage type: " + existingParameter.StorageType.ToString(), false);
                    break;
                }
            }

            foreach (KeyValuePair <string, string> property in StringProperties)
            {
                string    name = property.Key;
                Parameter existingParameter = null;
                if (!parameterGroupMap.TryFindParameter(name, out existingParameter))
                {
                    IFCPropertySet.AddParameterString(doc, element, category, objDef, property.Key, property.Value, Id);
                    continue;
                }

                switch (existingParameter.StorageType)
                {
                case StorageType.String:
                    existingParameter.Set(property.Value);
                    break;

                default:
                    Importer.TheLog.LogError(Id, "couldn't create parameter: " + name + " of storage type: " + existingParameter.StorageType.ToString(), false);
                    break;
                }
            }

            return(Tuple.Create("\"" + EntityType.ToString() + "\"", false));
        }
        public void PostProcessSite(int siteId, double?refLatitude, double?refLongitude,
                                    double refElevation, string landTitleNumber, ForgeTypeId baseLengthUnits,
                                    Transform lcs)
        {
            var ele = GetElementFromStepId(siteId);

            if (refLatitude.HasValue)
            {
                ele.AddParameter(-1, "Latitude", refLatitude.Value, SpecTypeId.Angle, UnitTypeId.Degrees);
            }
            if (refLongitude.HasValue)
            {
                ele.AddParameter(-1, "Longitude", refLongitude.Value, SpecTypeId.Angle, UnitTypeId.Degrees);
            }

            // refElevation comes from an attribute so will be in feet
            ele.AddParameter(-1, "Elevation", refElevation, SpecTypeId.Length, UnitTypeId.Feet);
            ele.AddParameter(-1, "LandTitleNumber", landTitleNumber);

            if (lcs != null)
            {
                // If we are reporting Latitude and Longitude, then we need a transform, to know
                // where this survey point is, in our world space.
                ele.SetTransform(lcs);
            }
        }
 public bool?ProcessParameter(int objDefId, ForgeTypeId specTypeId,
                              ForgeTypeId unitsTypeId,
                              int parameterSetId, string parameterName, double parameterValue)
 {
     GetElementFromStepId(objDefId).AddParameter(parameterSetId, parameterName, parameterValue, specTypeId, unitsTypeId);
     return(true);
 }
 private static string GetDiameter(Rebar rebar)
 {
     Parameter diameterParam = rebar.get_Parameter(BuiltInParameter.REBAR_BAR_DIAMETER);
     ForgeTypeId unitType = diameterParam.GetUnitTypeId();
     double diameter = diameterParam.AsDouble();
     diameter = UnitUtils.ConvertFromInternalUnits(diameter, unitType);
     return "ø" + diameter.ToString();
 }
 /// <summary>
 /// Constructor with display unit type
 /// </summary>
 /// <param name="application">Revit application</param>
 /// <param name="labels">All existing labels in Revit's document</param>
 /// <param name="unit">Current length display unit type</param>
 public CreateGridsData(UIApplication application, ArrayList labels, ForgeTypeId unit)
 {
     m_revitDoc   = application.ActiveUIDocument.Document;
     m_appCreator = application.Application.Create;
     m_docCreator = application.ActiveUIDocument.Document.Create;
     m_labelsList = labels;
     m_unit       = unit;
 }
 /// <summary>
 /// constructor which exposes for invoking
 /// </summary>
 /// <param name="name">
 /// parameter name
 /// </param>
 /// <param name="group">
 /// indicate which group the parameter belongs to
 /// </param>
 /// <param name="type">
 /// the type of the parameter
 /// </param>
 /// <param name="isInstance">
 /// indicate whethe the parameter is an instance parameter
 /// </param>
 /// <param name="line">
 /// record the location of this parameter in the family parameter file
 /// </param>
 public FamilyParam(string name, ForgeTypeId group, ForgeTypeId type, bool isInstance, int line)
 {
     m_name       = name;
     m_group      = group;
     m_type       = type;
     m_isInstance = isInstance;
     m_line       = line;
 }
        /// <summary>
        /// Converts to internal units by using the speckle parameter applicationUnit
        /// </summary>
        /// <param name="parameter">Speckle parameter</param>
        /// <returns></returns>
        public static double ConvertToInternalUnits(Objects.BuiltElements.Revit.Parameter parameter)
        {
#if !(REVIT2022)
            Enum.TryParse(parameter.applicationUnit, out DisplayUnitType sourceUnit);
            return(UnitUtils.ConvertToInternalUnits(Convert.ToDouble(parameter.value), sourceUnit));
#else
            var sourceUnit = new ForgeTypeId(parameter.applicationUnit);
            return(UnitUtils.ConvertToInternalUnits(Convert.ToDouble(parameter.value), sourceUnit));
#endif
        }
Exemple #20
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="saveFormat">The file format.</param>
 /// <param name="exportRange">The export range.</param>
 public Settings(SaveFormat saveFormat, ElementsExportRange exportRange)
 {
     m_SaveFormat              = saveFormat;
     m_ExportRange             = exportRange;
     m_IncludeLinkedModels     = false;
     m_exportColor             = false;
     m_exportSharedCoordinates = false;
     m_SelectedCategories      = new List <Category>();
     m_Units = new ForgeTypeId();
 }
Exemple #21
0
        /*public static void SetValue(Parameter param, string value)
         * {
         *  switch (param.StorageType)
         *  {
         *      case StorageType.None:
         *          break;
         *      case StorageType.Integer:
         *          param.Set(int.Parse(value));
         *          break;
         *      case StorageType.Double:
         *          param.Set(double.Parse(value) / 304.8);
         *          break;
         *      case StorageType.String:
         *          param.Set(value);
         *          break;
         *      case StorageType.ElementId:
         *          int intval = int.Parse(value);
         *          ElementId newId = new ElementId(intval);
         *          param.Set(newId);
         *          break;
         *      default:
         *          break;
         *  }
         * }*/

        /*public static string GetAsString(Parameter param)
         * {
         *  switch (param.StorageType)
         *  {
         *      case StorageType.None:
         *          return "";
         *      case StorageType.Integer:
         *          return param.AsInteger().ToString();
         *      case StorageType.Double:
         *          double doubleval = param.AsDouble();
         *          double mm = ConvertFromInternal(doubleval, param);
         *          return mm.ToString("F1");
         *      case StorageType.String:
         *          return param.AsString();
         *      case StorageType.ElementId:
         *          int intval = param.AsElementId().IntegerValue;
         *          return intval.ToString();
         *      default:
         *          return "";
         *  }
         * }*/

        public static double ConvertFromInternal(double val, Parameter param)
        {
#if R2017 || R2018 || R2019 || R2020 || R2021
            double val2 = UnitUtils.ConvertFromInternalUnits(val, param.DisplayUnitType);
#else
            ForgeTypeId forgeType = param.GetUnitTypeId();
            double      val2      = UnitUtils.ConvertFromInternalUnits(val, forgeType);
#endif
            return(val2);
        }
Exemple #22
0
        /// <summary>
        /// Convert from Revit internal units to Revit display units.
        /// </summary>
        /// <param name="specTypeId">Identifier of the spec.</param>
        /// <param name="unscaledValue">The value in Revit internal units.</param>
        /// <returns>The value in Revit display units.</returns>
        /// <remarks>Ignores the offset component.</remarks>
        public UV Scale(ForgeTypeId specTypeId, UV unscaledValue)
        {
            Tuple <IFCAnyHandle, double, double> scale;

            if (m_UnitConversionTable.TryGetValue(specTypeId, out scale))
            {
                return(unscaledValue * scale.Item2);
            }
            return(unscaledValue);
        }
Exemple #23
0
        /// <summary>
        /// Convert from Revit display units to Revit internal units.
        /// </summary>
        /// <param name="specTypeId">Identifier of the spec.</param>
        /// <param name="scaledValue">The value in Revit display units.</param>
        /// <returns>The value in Revit internal units.</returns>
        public double Unscale(ForgeTypeId specTypeId, double scaledValue)
        {
            Tuple <IFCAnyHandle, double, double> scale;

            if (m_UnitConversionTable.TryGetValue(specTypeId, out scale))
            {
                return((scaledValue - scale.Item3) / scale.Item2);
            }
            return(scaledValue);
        }
 public SharedParameterBindingManager()
 {
     Name           = "Invalid";
     Type           = new ForgeTypeId {
     };
     UserModifiable = true;
     Description    = "";
     Instance       = true;
     Definition     = null;
     ParameterGroup = BuiltInParameterGroup.PG_IDENTITY_DATA;
 }
Exemple #25
0
        /// <summary>
        /// Converts a value from the units from an IFC file to the corresponding Revit internal units.
        /// </summary>
        /// <param name="specTypeId">Identifier of the spec for this value.</param>
        /// <param name="inValue">The value to convert.</param>
        /// Some units we really always want in the standard document units.
        /// For example, angles in Radians.
        /// </param>
        /// <returns>The result value in Revit internal units.</returns>
        static private double ProjectScale(ForgeTypeId specTypeId, double inValue)
        {
            IFCUnit projectUnit = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(specTypeId);

            if (projectUnit != null)
            {
                return(inValue * projectUnit.ScaleFactor - projectUnit.OffsetFactor);
            }

            return(inValue);
        }
Exemple #26
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="saveFormat">The file format.</param>
 /// <param name="exportRange">The export range.</param>
 /// <param name="includeLinkedModels">True to include linked models, false otherwise.</param>
 /// <param name="selectedCategories">The selected categories to be included.</param>
 public Settings(SaveFormat saveFormat, ElementsExportRange exportRange, bool includeLinkedModels, bool exportColor, bool exportSharedCoordinates,
                 List <Category> selectedCategories, ForgeTypeId units)
 {
     m_SaveFormat              = saveFormat;
     m_ExportRange             = exportRange;
     m_IncludeLinkedModels     = includeLinkedModels;
     m_exportColor             = exportColor;
     m_exportSharedCoordinates = exportSharedCoordinates;
     m_SelectedCategories      = selectedCategories;
     m_Units = units;
 }
Exemple #27
0
        /// <summary>
        /// Compute the Eastings, Northings, OrthogonalHeight from the selected SiteTransformationBasis and scale values
        /// </summary>
        /// <param name="doc">The document</param>
        /// <param name="wcsBasis">The selected coordinate base</param>
        /// <returns>A Tuple of scaled values for Eastings, Northings, and OrthogonalHeight</returns>
        public static (double eastings, double northings, double orthogonalHeight) ScaledGeoReferenceInformation(Document doc, SiteTransformBasis wcsBasis)
        {
            (double eastings, double northings, double orthogonalHeight)geoRef = GeoReferenceInformation(doc, wcsBasis);
            FormatOptions lenFormatOptions = doc.GetUnits().GetFormatOptions(SpecTypeId.Length);
            ForgeTypeId   lengthUnit       = lenFormatOptions.GetUnitTypeId();

            geoRef.eastings         = UnitUtils.ConvertFromInternalUnits(geoRef.eastings, lengthUnit);
            geoRef.northings        = UnitUtils.ConvertFromInternalUnits(geoRef.northings, lengthUnit);
            geoRef.orthogonalHeight = UnitUtils.ConvertFromInternalUnits(geoRef.orthogonalHeight, lengthUnit);
            return(geoRef);
        }
Exemple #28
0
        public static double DynamoToHostFactor(ForgeTypeId specTypeId)
        {
            var unitTypeId =
                DocumentManager.Instance.CurrentDBDocument.GetUnits()
                .GetFormatOptions(specTypeId)
                .GetUnitTypeId();

            // Here we use the Revit API to return the conversion
            // factor between the display units in Revit and the internal
            // units (decimal feet). We are not converting a value, so
            // we simply supply 1 to return the converstion factor.
            return(UnitUtils.ConvertToInternalUnits(1, unitTypeId));
        }
Exemple #29
0
        private static ForgeTypeId CalculateUnitsTypeId(ForgeTypeId unitsTypeId,
                                                        ForgeTypeId specTypeId)
        {
            if (unitsTypeId != null || Importer.TheProcessor.ScaleValues)
            {
                return(unitsTypeId);
            }

            // We can look up the units when the values are not scaled.
            var units = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(specTypeId);

            return((units != null) ? units.Unit : UnitTypeId.General);
        }
 private static string GetSpacing(Rebar rebar)
 {
     Parameter layoutParam = rebar.get_Parameter(BuiltInParameter.REBAR_ELEM_LAYOUT_RULE);
     if (layoutParam.AsInteger() == 0)
     {
         return "";
     }
     Parameter spacingParam = rebar.get_Parameter(BuiltInParameter.REBAR_ELEM_BAR_SPACING);
     ForgeTypeId unitType = spacingParam.GetUnitTypeId();
     double spacing = spacingParam.AsDouble();
      spacing =  UnitUtils.ConvertFromInternalUnits(spacing, unitType);
     return "c" + spacing.ToString("0");
 }