public MapDutToUt()
        {
            IList <DisplayUnitType> duts;

            Array a = Enum.GetValues(typeof(UnitType));

            foreach (UnitType ut in a)
            {
                // Skip the UT_Undefined and UT_Custom entries;
                // GetValidDisplayUnits throws ArgumentException
                // on them, saying "unitType is an invalid unit
                // type.  See UnitUtils.IsValidUnitType() and
                // UnitUtils.GetValidUnitTypes()."

                if (UnitType.UT_Undefined == ut ||
                    UnitType.UT_Custom == ut)
                {
                    continue;
                }

                duts = UnitUtils.GetValidDisplayUnits(ut);

                foreach (DisplayUnitType dut in duts)
                {
                    //Debug.Assert( !ContainsKey( dut ),
                    //  "unexpected duplicate DisplayUnitType key" );

                    if (!ContainsKey(dut))
                    {
                        Add(dut, new List <UnitType>(1));
                    }
                    this[dut].Add(ut);
                }
            }
        }
Example #2
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static DisplayUnitType BHoMUnitType(this UnitType unitType)
        {
            // Check if any display unit type applicable to given unit type is acceptable BHoM unit type.
            IEnumerable <DisplayUnitType> duts = UnitUtils.GetValidDisplayUnits(unitType);

            foreach (DisplayUnitType dut in duts)
            {
                if (BHoMUnits.Contains(dut))
                {
                    return(dut);
                }
            }

            // Check if any display unit type applicable to given unit type has acceptable BHoM equivalent unit type.
            foreach (DisplayUnitType dut in duts)
            {
                if (BHoMEquivalents.ContainsKey(dut))
                {
                    return(BHoMEquivalents[dut]);
                }
            }

            // Find any SI display unit types.
            List <DisplayUnitType> acceptable = duts.Where(x =>
            {
                string lower = x.ToString().ToLower();
                return(!NonSIUnitNames.Any(y => lower.Contains(y)));
            }).ToList();

            // Return first SI display unit type or record error.
            if (acceptable.Count != 0)
            {
                DisplayUnitType dut = acceptable.First();
                BH.Engine.Reflection.Compute.RecordWarning(String.Format("Unit type {0} does not have a unitless SI convert - instead, it has been converted to {1}.", LabelUtils.GetLabelFor(unitType), LabelUtils.GetLabelFor(dut)));
                return(dut);
            }
            else
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Unit type {0} has not been recognized and has not been converted - as a result, the output value can be wrong.", LabelUtils.GetLabelFor(unitType)));
                return(DisplayUnitType.DUT_GENERAL);
            }
        }
        private void StreamEntityFieldValue(Field field)
        {
            try
            {
                var getEntityValueMehod = GetEntityFieldValueMethod(field);

                var valueType = GetFieldValueType(field);

                var genericGet = getEntityValueMehod.MakeGenericMethod(valueType);

                var parameters = getEntityValueMehod.GetParameters().Length == 1
          ? new object[] { field }
          : new object[] { field, UnitUtils.GetValidDisplayUnits(field.UnitType).First() };

                var value = genericGet.Invoke(entity, parameters);

                AddFieldValue(field, value);
            }
            catch (Exception ex)
            {
                data.Add(new Snoop.Data.Exception(field.FieldName, ex));
            }
        }
Example #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="revit">The revit application.</param>
        public STLExportForm(Autodesk.Revit.UI.UIApplication revit)
        {
            InitializeComponent();
            m_Revit = revit;

            // get new data generator
            m_Generator = new DataGenerator(m_Revit.Application, m_Revit.ActiveUIDocument.Document, m_Revit.ActiveUIDocument.Document.ActiveView);

            // scan for categories to populate category list
            m_CategoryList = m_Generator.ScanCategories(true);

            foreach (Category category in m_CategoryList.Values)
            {
                TreeNode treeNode = GetChildNode(category, m_Revit.ActiveUIDocument.Document.ActiveView);
                if (treeNode != null)
                {
                    tvCategories.Nodes.Add(treeNode);
                }
            }

            string unitName = "Use Internal: Feet";

            m_DisplayUnits.Add(unitName, DisplayUnitType.DUT_UNDEFINED);
            int selectedIndex = comboBox_DUT.Items.Add(unitName);

            if (m_SelectedDUT == DisplayUnitType.DUT_UNDEFINED)
            {
                comboBox_DUT.SelectedIndex = selectedIndex;
            }

            Units           currentUnits = m_Revit.ActiveUIDocument.Document.GetUnits();
            DisplayUnitType currentDut   = currentUnits.GetFormatOptions(UnitType.UT_Length).DisplayUnits;

            unitName = "Use Current: " + LabelUtils.GetLabelFor(currentDut);
            m_DisplayUnits.Add(unitName, currentDut);
            selectedIndex = comboBox_DUT.Items.Add(unitName);
            if (m_SelectedDUT == currentDut)
            {
                comboBox_DUT.SelectedIndex = selectedIndex;
            }

            foreach (DisplayUnitType dut in UnitUtils.GetValidDisplayUnits(UnitType.UT_Length))
            {
                if (currentDut == dut)
                {
                    continue;
                }
                unitName = LabelUtils.GetLabelFor(dut);
                m_DisplayUnits.Add(unitName, dut);
                selectedIndex = comboBox_DUT.Items.Add(unitName);
                if (m_SelectedDUT == dut)
                {
                    comboBox_DUT.SelectedIndex = selectedIndex;
                }
            }

            // initialize the UI differently for Families
            if (revit.ActiveUIDocument.Document.IsFamilyDocument)
            {
                cbIncludeLinked.Enabled = false;
                tvCategories.Enabled    = false;
                btnCheckAll.Enabled     = false;
                btnCheckNone.Enabled    = false;
            }
        }
Example #5
0
        public static DisplayUnitType DisplayUnitType(this UnitType unitType)
        {
            if (unitType == UnitType.UT_Number)
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_UNDEFINED);
            }

            IEnumerable <DisplayUnitType> displayUnitTypes = UnitUtils.GetValidDisplayUnits(unitType);

            if (displayUnitTypes == null || displayUnitTypes.Count() == 0)
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_UNDEFINED);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_UNDEFINED))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_UNDEFINED);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_METERS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_METERS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_KILOGRAMS_MASS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_KILOGRAMS_MASS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_CELSIUS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_CELSIUS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_AMPERES))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_AMPERES);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_WATTS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_WATTS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_WATTS_PER_CUBIC_METER))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_WATTS_PER_CUBIC_METER);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_CUBIC_METERS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_CUBIC_METERS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_SQUARE_METERS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_SQUARE_METERS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_CUBIC_METERS_PER_SECOND))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_CUBIC_METERS_PER_SECOND);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_WATTS_PER_SQUARE_METER))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_WATTS_PER_SQUARE_METER);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_VOLTS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_VOLTS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_KILOGRAMS_FORCE))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_KILOGRAMS_FORCE);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_LUX))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_LUX);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_LUMENS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_LUMENS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_LUMENS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_LUMENS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_PASCALS))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_PASCALS);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_PASCALS_PER_METER))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_PASCALS_PER_METER);
            }

            if (displayUnitTypes.Contains(Autodesk.Revit.DB.DisplayUnitType.DUT_KILOGRAMS_PER_CUBIC_METER))
            {
                return(Autodesk.Revit.DB.DisplayUnitType.DUT_KILOGRAMS_PER_CUBIC_METER);
            }

            return(Autodesk.Revit.DB.DisplayUnitType.DUT_UNDEFINED);
        }