Пример #1
0
        /// <summary>
        /// Calculates the distance to the next level if the UpToLevel parameter is set.
        /// If the parameter is not set, or the distance is negative, 0 is returned.
        /// This is not set in IFCLevelInfo as we want this calculation to be done in .NET code.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="levelId">The element id of the level.</param>
        /// <param name="levelInfo">The associated level information object.</param>
        public static double CalculateDistanceToNextLevel(Document doc, ElementId levelId, IFCLevelInfo levelInfo)
        {
            double height = 0.0;
             Level level = doc.GetElement(levelId) as Level;
             ElementId nextLevelId = ElementId.InvalidElementId;

             if (level != null)
             {
            Parameter nextLevelParameter = level.get_Parameter(BuiltInParameter.LEVEL_UP_TO_LEVEL);
            if (nextLevelParameter != null)
            {
               Element nextLevelAsElement = doc.GetElement(nextLevelParameter.AsElementId());
               if (nextLevelAsElement != null)
               {
                  Level possibleNextLevel = nextLevelAsElement as Level;
                  if (possibleNextLevel != null && IsBuildingStory(possibleNextLevel))
                  {
                     double nextLevelElevation = possibleNextLevel.Elevation;
                     double netElevation = nextLevelElevation - level.Elevation;
                     if (netElevation > 0.0)
                     {
                        height = netElevation;
                        nextLevelId = nextLevelParameter.AsElementId();
                     }
                  }
               }
            }
             }

             if ((height <= 0.0) && (levelInfo != null))
            height = levelInfo.DistanceToNextLevel;

             ExporterCacheManager.LevelInfoCache.Register(levelId, nextLevelId, height);
             return height;
        }
Пример #2
0
        string GetParamValueAsStr(Parameter parameter)
        {
            switch (parameter.StorageType)
            {
            case StorageType.String:
                return(parameter.AsString());

            case StorageType.Integer:
                return(parameter.AsInteger().ToString());

            case StorageType.Double:
                return(parameter.AsValueString());

            case StorageType.ElementId:
                ElementId eid = parameter.AsElementId();
                if (eid.IntegerValue < 0)
                {
                    return("(none)");
                }
                else
                {
                    return(parameter
                           .Element
                           .Document
                           .GetElement(parameter.AsElementId()).Name);
                }

            case StorageType.None:
                return("N/A");

            default:
                return("N/A");
            }
        }
Пример #3
0
        public static ElementId GetBaseLevelIdForElement(Element elem)
        {
            if (elem.ViewSpecific)
            {
                ElementId viewId = elem.OwnerViewId;
                ElementId viewSpecificlevelId;
                if (ExporterCacheManager.DBViewsToExport.TryGetValue(viewId, out viewSpecificlevelId))
                {
                    return(viewSpecificlevelId);
                }
            }

            Parameter levelParameter = null;

            if (elem is FamilyInstance)
            {
                // If this is a nested family, check the top-level instance for the level parameter information.
                Element elemToCheck = (elem as FamilyInstance).SuperComponent;
                if (elemToCheck == null)
                {
                    elemToCheck = elem;
                }

                // There are two Family-related parameters: INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM and INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM.
                // We prioritize INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM over INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM.
                levelParameter = elemToCheck.get_Parameter(BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM);
                if (levelParameter != null && levelParameter.StorageType == StorageType.ElementId)
                {
                    ElementId levelId = levelParameter.AsElementId();
                    if (levelId != ElementId.InvalidElementId)
                    {
                        return(levelId);
                    }
                }

                levelParameter = elemToCheck.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM);
            }
            else if (elem is Truss)
            {
                levelParameter = elem.get_Parameter(BuiltInParameter.TRUSS_ELEMENT_REFERENCE_LEVEL_PARAM);
            }
            else if (elem is Stairs || StairsExporter.IsLegacyStairs(elem))
            {
                levelParameter = elem.get_Parameter(BuiltInParameter.STAIRS_BASE_LEVEL_PARAM);
            }
            else if (elem is ExtrusionRoof)
            {
                levelParameter = elem.get_Parameter(BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM);
            }

            if (levelParameter != null && levelParameter.StorageType == StorageType.ElementId)
            {
                return(levelParameter.AsElementId());
            }
            else
            {
                return(elem.LevelId);
            }
        }
Пример #4
0
        private static void updateView(View v, StyleEnum style)
        {
            if (testDocNeedsInitializing(v.Document))
            {
                createAllStyles(v.Document);
            }


            //does the current view have an analysis style?
            Parameter avf = v.get_Parameter(BuiltInParameter.VIEW_ANALYSIS_DISPLAY_STYLE);
            Document  doc = v.Document;

            if (avf != null)
            {
                ElementId eid = avf.AsElementId();

                string name = "";
                switch (style)
                {
                case StyleEnum.Faces:
                    name = "SolidView";
                    break;

                case StyleEnum.Vectors:
                    name = "VectorView";
                    break;

                default:
                    throw new ApplicationException("Unexpected Display Style: " + style);
                }

                ElementId pc = AnalysisDisplayStyle.FindByName(doc, name);



                if (pc.IntegerValue > 0)
                {
                    if (avf.AsElementId() != pc)
                    {
                        Transaction t = null;
                        if (v.Document.IsModifiable == false)
                        {
                            t = new Transaction(v.Document, "Set AVF view style");
                            t.Start();
                        }
                        bool success = avf.Set(pc);
                        if (t != null)
                        {
                            t.Commit();
                        }
                    }
                }
            }
        }
Пример #5
0
        //public static ParameterForm GetParameterForm(this Parameter param, Document doc)
        //{
        //    ParameterForm pf = ParameterForm.None;

        //    Debug.WriteLine("This parameter's type is: " + param.Definition.ParameterType.ToString());
        //    if (!param.Definition.ParameterType.ToString().Equals("Invalid"))
        //    {
        //        try
        //        {
        //            DefinitionBindingMap dbm = doc.ParameterBindings;
        //            Debug.WriteLine("The DefinitionBindingMap has " + dbm.Size.ToString() + "entries");

        //            Definition d = param.Definition;
        //            Binding b = dbm.get_Item(d);

        //            Debug.Assert(b is InstanceBinding, (d.Name + " is an instance"));
        //            Debug.Assert(b is TypeBinding, (d.Name + " is a type"));
        //        }

        //        catch (Autodesk.Revit.Exceptions.InvalidObjectException invOe)
        //        {
        //            // coode
        //            Debug.WriteLine("The object was invalid?" + "\n" + invOe.Message);
        //        }

        //        catch (Autodesk.Revit.Exceptions.InvalidOperationException auto_ioe)
        //        {
        //            // code
        //            Debug.WriteLine("The operation was invalid?" + "\n" + auto_ioe.Message);
        //        }
        //    }

        //    return pf;
        //}

        public static string GetParameterValue(this Parameter param)
        {
            try
            {
                switch (param.StorageType)
                {
                default:
                    // A NULL VALUE MEANS THE PARAMETER IS UNEXPOSED
                    return("PARAMETER HAS NOT BEEN EXPOSED");

                case StorageType.Double:
                    return(GetParameterDouble(param));

                case StorageType.Integer:
                    if (ParameterType.YesNo != param.Definition.ParameterType)
                    {
                        return("INTEGER: " + param.AsInteger().ToString());
                    }

                    if (param.AsInteger() == 0)
                    {
                        return("False");
                    }

                    return("True");

                case StorageType.String:
                    return(param.AsString());

                case StorageType.ElementId:
                    // this one is tricky
                    // a positive ElementID can point to a specific element
                    // however a negative one can mean a number of different things

                    if (param.AsElementId().IntegerValue <= 0)
                    {
                        return("ELEMENTID: " + param.AsElementId().IntegerValue.ToString());
                    }

                    using (Document paramdoc = param.Element.Document)
                    {
                        return(paramdoc.GetElement(param.AsElementId()).Name);
                    }
                }
            }


            catch (InvalidObjectException invalidoex)
            {
                ExceptionReport.DebugLog(invalidoex);
            }

            return(null);
        }
        public static IEnumerable <ElementId> ElementIdsByParameter(this Document document, string parameterName, int elementId, IEnumerable <ElementId> ids = null)
        {
            if (document == null)
            {
                return(null);
            }

            HashSet <ElementId> result = new HashSet <ElementId>();

            if (ids != null && ids.Count() == 0)
            {
                return(result);
            }

            FilteredElementCollector collector = ids == null ? new FilteredElementCollector(document) : new FilteredElementCollector(document, ids.ToList());

            foreach (Element element in collector.WherePasses(new LogicalOrFilter(new ElementIsElementTypeFilter(), new ElementIsElementTypeFilter(true))))
            {
                Parameter param = element.LookupParameter(parameterName);
                if (param != null && param.HasValue && param.StorageType == StorageType.ElementId)
                {
                    if (param.AsElementId().IntegerValue == elementId)
                    {
                        result.Add(element.Id);
                    }
                }
            }

            return(result);
        }
Пример #7
0
        /// <summary>
        /// The GetParameterValue
        /// </summary>
        /// <param name="Paramètre">The Paramètre<see cref="Parameter"/></param>
        /// <returns>The <see cref="string"/></returns>
        public static string GetParameterValue(Parameter Paramètre)
        {
            switch (Paramètre.StorageType)
            {
            case StorageType.Double:
                //// Obtenir la valeur du paramètre sans unité.
                //return paramètre.AsDouble(); // Changer la valeur de retour.

                // Obtenir la valeur du paramètre avec unité.
                return(Paramètre.AsValueString());

            case StorageType.ElementId:
                return(Paramètre.AsElementId().IntegerValue.ToString());

            case StorageType.Integer:
                return(Paramètre.AsValueString());

            case StorageType.None:
                return(Paramètre.AsValueString());

            case StorageType.String:
                return(Paramètre.AsString());

            default:
                return("");
            }
        }
Пример #8
0
        /// <summary>
        /// Gets element filter that match certain phases.
        /// </summary>
        /// <param name="document">The Revit document.</param>
        /// <returns>The element filter.</returns>
        private static ElementFilter GetPhaseStatusFilter(Document document, Element filterView)
        {
            List <ElementOnPhaseStatus> phaseStatuses = new List <ElementOnPhaseStatus>();

            phaseStatuses.Add(ElementOnPhaseStatus.None);  //include "none" because we might want to export phaseless elements.
            phaseStatuses.Add(ElementOnPhaseStatus.Existing);
            phaseStatuses.Add(ElementOnPhaseStatus.New);

            PhaseArray phaseArray = document.Phases;

            ElementId phaseId = ElementId.InvalidElementId;

            if (filterView != null)
            {
                Parameter currPhase = filterView.get_Parameter(BuiltInParameter.VIEW_PHASE);
                if (currPhase != null)
                {
                    phaseId = currPhase.AsElementId();
                }
            }
            if (phaseId == ElementId.InvalidElementId)
            {
                Phase lastPhase = phaseArray.get_Item(phaseArray.Size - 1);
                phaseId = lastPhase.Id;
            }

            return(new ElementPhaseStatusFilter(phaseId, phaseStatuses));
        }
Пример #9
0
        public object GetParameterValue(Parameter parameter)
        {
            object returnValue = null;

            if (parameter == null || !parameter.HasValue)
            {
                return(returnValue);
            }

            switch (parameter.StorageType)
            {
            case StorageType.Double:
                returnValue = parameter.AsDouble();
                break;

            case StorageType.Integer:
                returnValue = parameter.AsInteger();
                break;

            case StorageType.String:
                returnValue = parameter.AsString();
                break;

            case StorageType.ElementId:
                returnValue = parameter.AsElementId();
                break;
            }

            return(returnValue);
        }
Пример #10
0
        public static string GetParameterValueString(this Parameter param)
        {
            string empty = string.Empty;
            string str;

            switch ((int)param.StorageType)
            {
            case 0:
                str = param.AsValueString().ToString();
                break;

            case 1:
                str = param.AsInteger().ToString();
                break;

            case 2:
                str = param.AsDouble().ToString(CultureInfo.InvariantCulture);
                break;

            case 3:
                str = param.AsString();
                break;

            case 4:
                str = param.AsElementId().ToString();
                break;

            default:
                str = param.AsValueString();
                break;
            }
            return(str ?? string.Empty);
        }
Пример #11
0
        private Room getOtherRoom(Room r1, BoundarySegment seg, XYZ point)
        {
            // we already know what one of the rooms is attached to a boundary segment.
            // this attempts to find the other.
            Curve crv = seg.GetCurve();

            XYZ vector = crv.GetEndPoint(1).Subtract(crv.GetEndPoint(0)).Normalize();

            XYZ otherVector = XYZ.BasisZ;

            if (vector.IsAlmostEqualTo(XYZ.BasisZ))
            {
                otherVector = XYZ.BasisY;
            }
            XYZ perp = vector.CrossProduct(otherVector).Normalize();

            XYZ       testp1    = point.Add(perp.Multiply(0.25));
            XYZ       testp2    = point.Add(perp.Negate().Multiply(0.25));
            Parameter phaseParm = r1.get_Parameter(BuiltInParameter.ROOM_PHASE);
            Phase     p         = _doc.GetElement(phaseParm.AsElementId()) as Phase;

            Room roomP1 = _doc.GetRoomAtPoint(testp1, p);
            Room roomP2 = _doc.GetRoomAtPoint(testp2, p);

            if ((roomP1 != null) && (roomP1.Id != r1.Id))
            {
                return(roomP1);
            }
            if ((roomP2 != null) && (roomP2.Id != r1.Id))
            {
                return(roomP2);
            }

            return(null);
        }
        //Sets the value of the family parameter based on a parameter value
        private void SetDocumentParameter(FamilyParameter docParameter, Parameter famParameter)
        {
            switch (famParameter.StorageType)
            {
            case (StorageType.Double):
                var value = famParameter.AsDouble();
                familyManager.Set(docParameter, famParameter.AsDouble());
                break;

            case (StorageType.Integer):
                familyManager.Set(docParameter, famParameter.AsInteger());
                break;

            case (StorageType.String):
                familyManager.Set(docParameter, famParameter.AsString());
                break;

            case (StorageType.ElementId):
                familyManager.Set(docParameter, famParameter.AsElementId());
                break;

            case (StorageType.None):
                break;
            }
        }
        public void GetParameters()
        {
            Document     doc  = Column.Document;
            FamilySymbol type = Column.Symbol;

            Width  = type.LookupParameter("b").AsDouble();
            Height = type.LookupParameter("h").AsDouble();

            LocationPoint lp = Column.Location as LocationPoint;
            XYZ           p  = lp.Point;

            Parameter blP = Column.LookupParameter("Base Level");
            Parameter boP = Column.LookupParameter("Base Offset");

            Level  bl = doc.GetElement(blP.AsElementId()) as Level;
            double bo = boP.AsDouble();

            Parameter tlP = Column.LookupParameter("Top Level");
            Parameter toP = Column.LookupParameter("Top Offset");

            Level  tl = doc.GetElement(tlP.AsElementId()) as Level;
            double to = toP.AsDouble();

            DrivingCurve = Line.CreateBound(new XYZ(p.X, p.Y, bl.Elevation + bo), new XYZ(p.X, p.Y, tl.Elevation + to));
            Length       = DrivingCurve.Length;
        }
Пример #14
0
        public static bool ResetValue(this Parameter parameter)
        {
            if (!parameter.HasValue)
            {
                return(true);
            }

#if REVIT_2020
            if (parameter.IsShared && (parameter.Definition as ExternalDefinition).HideWhenNoValue)
            {
                return(parameter.ClearValue());
            }
#endif

            switch (parameter.StorageType)
            {
            case StorageType.Integer:   return(parameter.AsInteger() == 0 || parameter.Set(0));

            case StorageType.Double:    return(parameter.AsDouble() == 0.0 || parameter.Set(0.0));

            case StorageType.String:    return(parameter.AsString() == string.Empty || parameter.Set(string.Empty));

            case StorageType.ElementId: return(parameter.AsElementId() == ElementId.InvalidElementId || parameter.Set(ElementId.InvalidElementId));
            }

            return(false);
        }
Пример #15
0
        public static string GetParameterAsString(Element element, string v)
        {
            if (element == null)
            {
                return(string.Empty);
            }
            Parameter p = element.LookupParameter(v);

            if (p != null)
            {
                switch (p.StorageType)
                {
                case StorageType.Double:
                    //if (p.DisplayUnitType != DisplayUnitType.DUT_UNDEFINED)
                    //{
                    return(p.AsValueString());

                //}
                //else
                //{

                //}
                case StorageType.Integer:
                    return(p.AsInteger().ToString());

                case StorageType.ElementId:
                    Element e = element.Document.GetElement(p.AsElementId());
                    return(e != null ? e.Name : "None");

                case StorageType.String:
                    return(p.AsString() != null?p.AsString() : "-");
                }
            }
            return(string.Empty);
        }
Пример #16
0
        public static string GetParameterValueString(Element e, BuiltInParameter bip)
        {
            Parameter p = e.get_Parameter(bip);

            string s = string.Empty;

            if (null != p)
            {
                switch (p.StorageType)
                {
                case StorageType.Integer:
                    s = p.AsInteger().ToString();
                    break;

                case StorageType.ElementId:
                    s = p.AsElementId().IntegerValue.ToString();
                    break;

                case StorageType.Double:
                    s = p.AsDouble().ToString();
                    break;

                case StorageType.String:
                    s = p.AsDouble().ToString();
                    break;

                default:
                    s = "";
                    break;
                }
            }
            return(s);
        }
Пример #17
0
        public static int GetConcreteClass(Element elem)
        {
            Document  doc           = elem.Document;
            Element   elemType      = doc.GetElement(elem.GetTypeId());
            Parameter materialParam = elemType.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);

            if (materialParam == null || !materialParam.HasValue)
            {
                throw new Exception("No Structural Material in element " + elem.Id.IntegerValue.ToString());
            }
            Material mat = doc.GetElement(materialParam.AsElementId()) as Material;

            if (mat == null)
            {
                throw new Exception("Unable to get Material from element " + elem.Id.IntegerValue.ToString());
            }
            Parameter materialCodeParam = mat.LookupParameter("Мтрл.КодМатериала");

            if (materialCodeParam == null || !materialCodeParam.HasValue)
            {
                throw new Exception("Нет параметра Мтрл.КодМатериала в материале " + mat.Name);
            }
            int materialCode  = materialCodeParam.AsInteger() / 100000;
            int concreteClass = materialCode % 100;

            return(concreteClass);
        }
        public string GetParameterValue(Parameter parameter)
        {
            string s;

            switch (parameter.StorageType)
            {
            case StorageType.Double:

                s = RealString(parameter.AsDouble());
                break;

            case StorageType.Integer:
                s = parameter.AsInteger().ToString();
                break;

            case StorageType.String:
                s = parameter.AsString();
                break;

            case StorageType.ElementId:
                s = parameter.AsElementId().IntegerValue.ToString();
                break;

            case StorageType.None:
                s = "";
                break;

            default:
                s = "0.0";
                break;
            }
            return(s);
        }
Пример #19
0
        private static string GetParameterValue(Parameter param)
        {
            if (param == null)
            {
                return(string.Empty);
            }
            string str;

            switch (param.StorageType)
            {
            case StorageType.Integer:
                str = param.AsInteger().ToString();
                break;

            case StorageType.Double:
                str = param.AsDouble().ToString(CultureInfo.InvariantCulture);
                break;

            case StorageType.String:
                str = param.AsString();
                break;

            case StorageType.ElementId:
                str = param.AsElementId().ToString();
                break;

            default:
                str = param.AsString();
                break;
            }
            return(str ?? string.Empty);
        }
Пример #20
0
        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();
                if (param.Definition.UnitType == UnitType.UT_Length)
                {
                    doubleval *= 304.8;
                }
                return(doubleval.ToString("F1"));

            case StorageType.String:
                return(param.AsString());

            case StorageType.ElementId:
                int intval = param.AsElementId().IntegerValue;
                return(intval.ToString());

            default:
                return("");
            }
        }
        /// <summary>
        /// Helper to return parameter value as string, with additional
        /// support for element id to display the element type referred to.
        /// </summary>
        public static string GetParameterValue2(Parameter param, Document doc)
        {
            string s;

            if (StorageType.ElementId == param.StorageType &&
                null != doc)
            {
                ElementId id = param.AsElementId();

                int i = id.IntegerValue;

                if (0 > i)
                {
                    s = i.ToString()
                        + BuiltInCategoryString(i);
                }
                else
                {
                    Element e = doc.GetElement(id);
                    s = ElementDescription(e, true);
                }
            }
            else
            {
                s = GetParameterValue(param);
            }
            return(s);
        }
Пример #22
0
        private static Value _getParam(Parameter p)
        {
            switch (p.StorageType)
            {
            case StorageType.ElementId:
                return(Value.NewContainer(p.AsElementId()));

            case StorageType.String:
                return(Value.NewString(p.AsString()));

            case StorageType.Integer:
            case StorageType.Double:
                switch (p.Definition.ParameterType)
                {
                case ParameterType.Length:
                    return(Value.NewContainer(Units.Length.FromFeet(p.AsDouble(), dynSettings.Controller.UnitsManager)));

                case ParameterType.Area:
                    return(Value.NewContainer(Units.Area.FromSquareFeet(p.AsDouble(), dynSettings.Controller.UnitsManager)));

                case ParameterType.Volume:
                    return(Value.NewContainer(Units.Volume.FromCubicFeet(p.AsDouble(), dynSettings.Controller.UnitsManager)));

                default:
                    return(Value.NewNumber(p.AsDouble()));
                }

            default:
                throw new Exception(string.Format("Parameter {0} has no storage type.", p));
            }
        }
        private void UpdatePhaseAttributes(IFCExportConfiguration configuration)
        {
            if (configuration.VisibleElementsOfCurrentView)
            {
                UIDocument uiDoc     = new UIDocument(IFCCommandOverrideApplication.TheDocument);
                Parameter  currPhase = uiDoc.ActiveView.get_Parameter(BuiltInParameter.VIEW_PHASE);
                if (currPhase != null)
                {
                    configuration.ActivePhaseId = currPhase.AsElementId();
                }
                else
                {
                    configuration.ActivePhaseId = ElementId.InvalidElementId;
                }
            }

            if (!IFCPhaseAttributes.Validate(configuration.ActivePhaseId))
            {
                configuration.ActivePhaseId = ElementId.InvalidElementId;
            }

            foreach (IFCPhaseAttributes attribute in comboboxActivePhase.Items.Cast <IFCPhaseAttributes>())
            {
                if (configuration.ActivePhaseId == attribute.PhaseId)
                {
                    comboboxActivePhase.SelectedItem = attribute;
                    break;
                }
            }

            comboboxActivePhase.IsEnabled = !configuration.VisibleElementsOfCurrentView;
        }
Пример #24
0
        private void checkBox_Unchecked(object sender, EventArgs e)
        {
            CheckBox     cb  = sender as CheckBox;
            TreeViewItem tvi = cb.Parent as TreeViewItem;

            if (tvi.HasItems)
            {
                foreach (TreeViewItem tvitest in tvi.Items)
                {
                    (tvitest.Header as CheckBox).IsChecked = false;
                }
            }
            else
            {
                Parameter p = cb.Tag as Parameter;
                foreach (ElementId ei in elementsId)
                {
                    Parameter par = doc.GetElement(ei).get_Parameter(p.Definition);
                    if (Math.Round(par.AsDouble()) == Math.Round(p.AsDouble()) && par.AsElementId() == p.AsElementId() && par.AsInteger() == p.AsInteger() && par.AsString() == p.AsString() && par.AsValueString() == p.AsValueString())
                    {
                        filteredElementId.Remove(ei);
                    }
                }
                filteredElementId = filteredElementId
                                    .Distinct()
                                    .ToList();
                label1.Content = "Выбрано элементов: " + filteredElementId.Count;
            }
        }
Пример #25
0
        /// <summary>
        /// When the roof was edited, then the data of the RoofItem should be updated synchronously.
        /// </summary>
        /// <returns>Update successfully return true, otherwise return false.</returns>
        public bool  Update()
        {
            try
            {
                this.SubItems[1].Text = m_roof.Name;

                if (m_roof is Autodesk.Revit.DB.FootPrintRoof)
                {
                    Parameter para = m_roof.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOF_BASE_LEVEL_PARAM);
                    this.SubItems[2].Text = LevelConverter.GetLevelByID(para.AsElementId().IntegerValue).Name;
                }
                else if (m_roof is Autodesk.Revit.DB.ExtrusionRoof)
                {
                    Parameter para = m_roof.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM);
                    this.SubItems[2].Text = LevelConverter.GetLevelByID(para.AsElementId().IntegerValue).Name;
                }

                this.SubItems[3].Text = m_roof.RoofType.Name;
            }
            catch
            {
                return(false);
            }
            return(true);
        }
        //***********************************GetParameterValue***********************************
        public string GetParameterValue(Parameter parameter)
        {
            switch (parameter.StorageType)
            {
            case StorageType.Double:
                //get value with unit, AsDouble() can get value without unit
                return(parameter.AsValueString());

            case StorageType.ElementId:
                return(parameter.AsElementId().IntegerValue.ToString());

            case StorageType.Integer:
                //get value with unit, AsInteger() can get value without unit
                return(parameter.AsValueString());

            case StorageType.None:
                return(parameter.AsValueString());

            case StorageType.String:
                return(parameter.AsString());

            default:
                return("");
            }
        }
Пример #27
0
        object GetParameterValue(Parameter par)
        {
            object parValue = null;

            if (!par.HasValue)
            {
                return(parValue);
            }

            switch (par.StorageType)
            {
            case StorageType.Double:
                parValue = par.AsDouble();
                break;

            case StorageType.Integer:
                parValue = par.AsInteger();
                break;

            case StorageType.String:
                parValue = par.AsString();
                break;

            case StorageType.ElementId:
                parValue = par.AsElementId();
                break;

            default:
                break;
            }
            return(parValue);
        }
Пример #28
0
        /// <summary>
        /// Return parameter value formatted as string
        /// </summary>
        static string ParameterToString(Parameter p)
        {
            string s = "null";

            if (p != null)
            {
                switch (p.StorageType)
                {
                case StorageType.Double:
                    s = p.AsDouble().ToString("0.##");
                    break;

                case StorageType.Integer:
                    s = p.AsInteger().ToString();
                    break;

                case StorageType.String:
                    s = p.AsString();
                    break;

                case StorageType.ElementId:
                    s = p.AsElementId().IntegerValue.ToString();
                    break;

                case StorageType.None:
                    s = "none";
                    break;
                }
            }
            return(s);
        }
Пример #29
0
 private Level GetlevelFromOpening()
 {
     if (Common.IsValidGuid(_comparisonCoupleElement.IdRevitElement))
     {
         Element element = _doc.GetElement(_comparisonCoupleElement.IdRevitElement);
         if (element == null)
         {
             return(null);
         }
         if (element is Opening)
         {
             Opening   opening   = element as Opening;
             Parameter parameter = opening.LookupParameter("Base Constraint");
             Level     level     = _doc.GetElement(parameter.AsElementId()) as Level;
             return(level);
         }
         else
         {
             Level level = _doc.GetElement(element.LevelId) as Level;
             if (level == null)
             {
                 XYZ locationPoint = (element.Location as LocationPoint).Point;
                 level = GetLevelFromLocation(_comparisonCoupleElement.LocalGeometry);
             }
             return(level);
         }
     }
     else
     {
         return(GetLevelFromLocation(_comparisonCoupleElement.ServerGeometry));
     }
 }
Пример #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static object GetParameterValue(Parameter p)
        {
            switch (p.StorageType)
            {
            case StorageType.None:
                throw new System.ArgumentOutOfRangeException();

            case StorageType.Integer:
                // (Konrad) It appears that by default yes/no parameters
                // have a greyed out box checked to 1 even though stored
                // integer value would return 0
                return(p.HasValue ? p.AsInteger() : 1);

            case StorageType.Double:
                return(p.AsDouble());

            case StorageType.String:
                return(p.AsString());

            case StorageType.ElementId:
                return(p.AsElementId().IntegerValue);

            default:
                throw new System.ArgumentOutOfRangeException();
            }
        }
Пример #31
0
        /// <summary>
        /// Returns a string value corresponding to an ElementId Parameter.
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        /// <returns>The string.</returns>
        public static string ElementIdParameterAsString(Parameter parameter)
        {
            ElementId value = parameter.AsElementId();
            if (value == ElementId.InvalidElementId)
                return null;

            string valueString = null;
            // All real elements in Revit have non-negative ids.
            if (value.IntegerValue >= 0)
            {
                // Get the family and element name.
                Element paramElement = ExporterCacheManager.Document.GetElement(value);
                valueString = (paramElement != null) ? paramElement.Name : null;
                if (!string.IsNullOrEmpty(valueString))
                {
                    ElementType paramElementType = paramElement is ElementType ? paramElement as ElementType :
                        ExporterCacheManager.Document.GetElement(paramElement.GetTypeId()) as ElementType;
                    string paramElementTypeName = (paramElementType != null) ? ExporterIFCUtils.GetFamilyName(paramElementType) : null;
                    if (!string.IsNullOrEmpty(paramElementTypeName))
                        valueString = paramElementTypeName + ": " + valueString;
                }
            }
            else 
            {
                valueString = parameter.AsValueString();
            }

            if (string.IsNullOrEmpty(valueString))
                valueString = value.ToString();

            return valueString;
        }
Пример #32
0
 private static Value _getParam(FamilyInstance fi, Parameter p)
 {
     if (p.StorageType == StorageType.Double)
     {
         switch (p.Definition.ParameterType)
         {
             case ParameterType.Length:
                 return Value.NewContainer(Units.Length.FromFeet(p.AsDouble()));
                 break;
             case ParameterType.Area:
                 return Value.NewContainer(Units.Area.FromSquareFeet(p.AsDouble()));
                 break;
             case ParameterType.Volume:
                 return Value.NewContainer(Units.Volume.FromCubicFeet(p.AsDouble()));
                 break;
             default:
                 return Value.NewNumber(p.AsDouble());
                 break;
         }
     }
     else if (p.StorageType == StorageType.Integer)
     {
         return Value.NewNumber(p.AsInteger());
     }
     else if (p.StorageType == StorageType.String)
     {
         return Value.NewString(p.AsString());
     }
     else
     {
         return Value.NewContainer(p.AsElementId());
     }
 }
Пример #33
0
 private static Expression _getParam(FamilyInstance fi, Parameter p)
 {
     if (p.StorageType == StorageType.Double)
     {
         return Expression.NewNumber(p.AsDouble());
     }
     else if (p.StorageType == StorageType.Integer)
     {
         return Expression.NewNumber(p.AsInteger());
     }
     else if (p.StorageType == StorageType.String)
     {
         return Expression.NewString(p.AsString());
     }
     else
     {
         return Expression.NewContainer(p.AsElementId());
     }
 }
Пример #34
0
Файл: Para.cs Проект: AMEE/revit
 // jeremy
 //public static Object GetParameterValue(Parameter parameter) // jeremy
 /// <summary>
 /// get parameter's value
 /// </summary>
 /// <param name="parameter">parameter of Element</param>
 /// <returns>parameter's value include unit if have</returns>
 public static string GetParameterValue(Parameter parameter)
 {
     switch (parameter.StorageType)
     {
         case StorageType.Double:
             //get value with unit, AsDouble() can get value without unit
             return parameter.AsValueString();
         case StorageType.ElementId:
             return parameter.AsElementId().IntegerValue.ToString();
         case StorageType.Integer:
             //get value with unit, AsInteger() can get value without unit
             return parameter.AsValueString();
         case StorageType.None:
             return parameter.AsValueString();
         case StorageType.String:
             return parameter.AsString();
         default:
             return "";
     }
 }
    /// <summary>
    /// Helper function: return a string form of a given parameter.
    /// </summary>
    public static string ParameterToString(Parameter param)
    {
      string val = "none";

      if (param == null)
      {
        return val;
      }

      // To get to the parameter value, we need to pause it depending on its storage type 

      switch (param.StorageType)
      {
        case StorageType.Double:
          double dVal = param.AsDouble();
          val = dVal.ToString();
          break;
        case StorageType.Integer:
          int iVal = param.AsInteger();
          val = iVal.ToString();
          break;
        case StorageType.String:
          string sVal = param.AsString();
          val = sVal;
          break;
        case StorageType.ElementId:
          ElementId idVal = param.AsElementId();
          val = idVal.IntegerValue.ToString();
          break;
        case StorageType.None:
          break;
      }
      return val;
    }
Пример #36
0
        private void Stream(ArrayList data, Parameter param)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(Parameter)));

            data.Add(new Snoop.Data.Object("Definition", param.Definition));

            try {   // this only works for certain types of Parameters
                data.Add(new Snoop.Data.String("Display unit type", param.DisplayUnitType.ToString()));
            }
            catch (System.Exception) {
                data.Add(new Snoop.Data.String("Display unit type", "N/A"));
            }
            try
            {   // this only works for certain types of Parameters
              data.Add(new Snoop.Data.Object("Element", param.Element));
            }
            catch (System.Exception ex)
            {
              data.Add(new Snoop.Data.Exception("Element", ex));
            }
            try
            {   // this only works for certain types of Parameters
              data.Add(new Snoop.Data.String("GUID", param.GUID.ToString()));
            }
            catch (System.Exception ex)
            {
              data.Add(new Snoop.Data.Exception("GUID", ex));
            }
            try
            {   // this only works for certain types of Parameters
              data.Add(new Snoop.Data.Bool("HasValue", param.HasValue));
            }
            catch (System.Exception ex)
            {
              data.Add(new Snoop.Data.Exception("HasValue", ex));
            }
            try
            {   // this only works for certain types of Parameters
              data.Add(new Snoop.Data.ElementId("ID", param.Id,m_activeDoc));
            }
            catch (System.Exception ex)
            {
              data.Add(new Snoop.Data.Exception("ID", ex));
            }
            try
            {   // this only works for certain types of Parameters
              data.Add(new Snoop.Data.Bool("IsShared", param.IsShared));
            }
            catch (System.Exception ex)
            {
              data.Add(new Snoop.Data.Exception("IsShared", ex));
            }

            data.Add(new Snoop.Data.String("Storage type", param.StorageType.ToString()));

            if (param.StorageType == StorageType.Double)
                data.Add(new Snoop.Data.Double("Value", param.AsDouble()));
            else if (param.StorageType == StorageType.ElementId)
                data.Add(new Snoop.Data.ElementId("Value", param.AsElementId(), m_app.ActiveUIDocument.Document));
            else if (param.StorageType == StorageType.Integer)
                data.Add(new Snoop.Data.Int("Value", param.AsInteger()));
            else if (param.StorageType == StorageType.String)
                data.Add(new Snoop.Data.String("Value", param.AsString()));

            data.Add(new Snoop.Data.String("As value string", param.AsValueString()));
        }
Пример #37
0
        /// <summary>
        /// Helper to return parameter value as string, with additional
        /// support for element id to display the element type referred to.
        /// </summary>
        public static string GetParameterValue2( Parameter param, Document doc )
        {
            string s;
              if( StorageType.ElementId == param.StorageType
            && null != doc )
              {
            ElementId id = param.AsElementId();

            int i = id.IntegerValue;

            if( 0 > i )
            {
              s = i.ToString()
            + BuiltInCategoryString( i );
            }
            else
            {
              Element e = doc.GetElement( id );
              s = ElementDescription( e, true );
            }
              }
              else
              {
            s = GetParameterValue( param );
              }
              return s;
        }
Пример #38
0
        /// <summary>
        /// Helper to return parameter value as string.
        /// One can also use param.AsValueString() to
        /// get the user interface representation.
        /// </summary>
        public static string GetParameterValue( Parameter param )
        {
            string s;
              switch( param.StorageType )
              {
            case StorageType.Double:
              //
              // the internal database unit for all lengths is feet.
              // for instance, if a given room perimeter is returned as
              // 102.36 as a double and the display unit is millimeters,
              // then the length will be displayed as
              // peri = 102.36220472440
              // peri * 12 * 25.4
              // 31200 mm
              //
              //s = param.AsValueString(); // value seen by user, in display units
              //s = param.AsDouble().ToString(); // if not using not using LabUtils.RealString()
              s = RealString( param.AsDouble() ); // raw database value in internal units, e.g. feet
              break;

            case StorageType.Integer:
              s = param.AsInteger().ToString();
              break;

            case StorageType.String:
              s = param.AsString();
              break;

            case StorageType.ElementId:
              s = param.AsElementId().IntegerValue.ToString();
              break;

            case StorageType.None:
              s = "?NONE?";
              break;

            default:
              s = "?ELSE?";
              break;
              }
              return s;
        }
Пример #39
0
 private static FScheme.Value _getParam(FamilySymbol fi, Parameter p)
 {
     if (p.StorageType == StorageType.Double)
     {
         return FScheme.Value.NewNumber(p.AsDouble());
     }
     else if (p.StorageType == StorageType.Integer)
     {
         return FScheme.Value.NewNumber(p.AsInteger());
     }
     else if (p.StorageType == StorageType.String)
     {
         return FScheme.Value.NewString(p.AsString());
     }
     else
     {
         return FScheme.Value.NewContainer(p.AsElementId());
     }
 }
Пример #40
0
 private static Value _getParam(Parameter p)
 {
     switch (p.StorageType)
     {
         case StorageType.ElementId:
             return Value.NewContainer(p.AsElementId());
         case StorageType.String:
             return Value.NewString(p.AsString());
         case StorageType.Integer:
         case StorageType.Double:
             switch (p.Definition.ParameterType)
         {
             case ParameterType.Length:
                 return Value.NewContainer(Units.Length.FromFeet(p.AsDouble(), dynSettings.Controller.UnitsManager));
             case ParameterType.Area:
                 return Value.NewContainer(Units.Area.FromSquareFeet(p.AsDouble(), dynSettings.Controller.UnitsManager));
             case ParameterType.Volume:
                 return Value.NewContainer(Units.Volume.FromCubicFeet(p.AsDouble(), dynSettings.Controller.UnitsManager));
             default:
                 return Value.NewNumber(p.AsDouble());
         }
         default:
             throw new Exception(string.Format("Parameter {0} has no storage type.", p));
     }
 }
Пример #41
0
 private void writeValueByStorageType(Parameter p, TextWriter writer, Document doc)
 {
     if (null != p)
     {
         switch (p.StorageType)
         {
             case StorageType.Double:
                 {
                     writer.Write(p.AsDouble());
                     break;
                 }
             case StorageType.Integer:
                 {
                     writer.Write(p.AsInteger());
                     break;
                 }
             case StorageType.String:
                 {
                     writer.Write(p.AsString());
                     break;
                 }
             case StorageType.ElementId:
                 {
                     Element elem = doc.get_Element(p.AsElementId());
                     if (null == elem)
                         writer.Write("NULL ELEMENT FOUND");
                     else
                         writer.Write(elem.Name);
                     break;
                 }
             default:
                 writer.Write("N/A");
                 break;
         }
     }
 }
Пример #42
0
        /// <summary>
        /// Extract the parameter information.
        /// By Dan Tartaglia.
        /// </summary>
        public string GetParameterInformation(
            Parameter para,
            Document doc)
        {
            string defName = "";

              // Use different method to get parameter
              // data according to the storage type

              switch( para.StorageType )
              {
            // Determine the parameter type

            case StorageType.Double:

              // Convert the number into Metric

              defName = para.AsValueString();
              break;

            case StorageType.ElementId:

              // Find out the name of the element

              Autodesk.Revit.DB.ElementId id
            = para.AsElementId();

              defName = ( id.IntegerValue >= 0 )
            ? doc.GetElement( id ).Name
            : id.IntegerValue.ToString();

              break;

            case StorageType.Integer:
              if( ParameterType.YesNo
            == para.Definition.ParameterType )
              {
            if( para.AsInteger() == 0 )
            {
              defName = "False";
            }
            else
            {
              defName = "True";
            }
              }
              else
              {
            defName = para.AsInteger().ToString();
              }
              break;

            case StorageType.String:
              defName = para.AsString();
              break;

            default:
              defName = "Unexposed parameter";
              break;
              }
              return defName;
        }