Exemple #1
0
        /// <summary>
        /// Return value Of parameter all case unit
        /// </summary>
        /// <param name="_parameter"></param>
        /// <returns></returns>
        public static string GetValue(this Autodesk.Revit.DB.Parameter _parameter)
        {
            string value;

            switch (_parameter.StorageType)
            {
            // database value, internal units, e.g. feet:
            case StorageType.Double:
                value = RealString(_parameter.AsDouble());
                break;

            case StorageType.Integer:
                value = _parameter.AsInteger().ToString();
                break;

            case StorageType.String:
                value = _parameter.AsString();
                break;

            case StorageType.ElementId:
                value = _parameter.AsElementId().IntegerValue.ToString();
                break;

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

            default:
                Debug.Assert(false, "unexpected storage type"); value = string.Empty;
                break;
            }

            return(value);
        }
Exemple #2
0
        public static Model.ParameterValue AsValue(this Autodesk.Revit.DB.Parameter p)
        {
            string text   = null;
            double number = 0;

            switch (p.StorageType)
            {
            case Autodesk.Revit.DB.StorageType.String:
                text = p.AsString();
                return(new Model.ParameterValue {
                    ParameterValueType = ParameterValueType.Text, ValueText = text
                });

            case Autodesk.Revit.DB.StorageType.ElementId:
                text = revitData.Document.GetElement(p.AsElementId()).Name;
                return(new Model.ParameterValue {
                    ParameterValueType = ParameterValueType.Text, ValueText = text
                });

            case Autodesk.Revit.DB.StorageType.Integer:
                number = p.AsInteger();
                return(new Model.ParameterValue {
                    ParameterValueType = ParameterValueType.Number, ValueNumber = number
                });

            case Autodesk.Revit.DB.StorageType.Double:
                number = p.AsDouble().GetConvertValue(p.DisplayUnitType);
                return(new Model.ParameterValue {
                    ParameterValueType = ParameterValueType.Number, ValueNumber = number
                });
            }
            throw new Exception("Đoạn code này không được đọc tới.");
        }
Exemple #3
0
        /// <summary>
        /// Initialize a Wall element
        /// </summary>
        /// <param name="curve"></param>
        /// <param name="wallType"></param>
        /// <param name="baseLevel"></param>
        /// <param name="height"></param>
        /// <param name="offset"></param>
        /// <param name="flip"></param>
        /// <param name="isStructural"></param>
        private void InitWall(Curve curve, Autodesk.Revit.DB.WallType wallType, Autodesk.Revit.DB.Level baseLevel, double height, double offset, bool flip, bool isStructural)
        {
            // This creates a new wall and deletes the old one
            TransactionManager.Instance.EnsureInTransaction(Document);

            //Phase 1 - Check to see if the object exists and should be rebound
            var wallElem =
                ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.Wall>(Document);

            bool successfullyUsedExistingWall = false;

            //There was a modelcurve, try and set sketch plane
            // if you can't, rebuild
            if (wallElem != null && wallElem.Location is Autodesk.Revit.DB.LocationCurve)
            {
                var wallLocation = wallElem.Location as Autodesk.Revit.DB.LocationCurve;
                if ((wallLocation.Curve is Autodesk.Revit.DB.Line == curve is Autodesk.Revit.DB.Line) ||
                    (wallLocation.Curve is Autodesk.Revit.DB.Arc == curve is Autodesk.Revit.DB.Arc) ||
                    (wallLocation.Curve is Autodesk.Revit.DB.Ellipse == curve is Autodesk.Revit.DB.Ellipse))
                {
                    if (!CurveUtils.CurvesAreSimilar(wallLocation.Curve, curve))
                    {
                        wallLocation.Curve = curve;
                    }

                    Autodesk.Revit.DB.Parameter baseLevelParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_BASE_CONSTRAINT);
                    Autodesk.Revit.DB.Parameter topOffsetParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.WALL_USER_HEIGHT_PARAM);
                    Autodesk.Revit.DB.Parameter wallTypeParameter =
                        wallElem.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ELEM_TYPE_PARAM);
                    if (baseLevelParameter.AsElementId() != baseLevel.Id)
                    {
                        baseLevelParameter.Set(baseLevel.Id);
                    }
                    if (Math.Abs(topOffsetParameter.AsDouble() - height) > 1.0e-10)
                    {
                        topOffsetParameter.Set(height);
                    }
                    if (wallTypeParameter.AsElementId() != wallType.Id)
                    {
                        wallTypeParameter.Set(wallType.Id);
                    }
                    successfullyUsedExistingWall = true;
                }
            }

            var wall = successfullyUsedExistingWall ? wallElem :
                       Autodesk.Revit.DB.Wall.Create(Document, curve, wallType.Id, baseLevel.Id, height, offset, flip, isStructural);

            InternalSetWall(wall);

            TransactionManager.Instance.TransactionTaskDone();

            // delete the element stored in trace and add this new one
            ElementBinder.CleanupAndSetElementForTrace(Document, InternalWall);
        }
        public static double?GetParameter_double(this Element element, string parameterName)
        {
            Parameter parameter = element.get_Parameter(parameterName);

            if (parameter != null)
            {
                return(parameter.AsDouble());
            }
            return(null);
        }
Exemple #5
0
        public static object GetParameterValue(Autodesk.Revit.DB.Parameter param)
        {
            object result;

            switch (param.StorageType)
            {
            case StorageType.ElementId:
                int valueId = param.AsElementId().IntegerValue;
                if (valueId > 0)
                {
                    // When the element is obtained here, to convert it to our element wrapper, it
                    // need to be figured out whether this element is created by us. Here the existing
                    // element wrappers will be checked. If there is one, its property to specify
                    // whether it is created by us will be followed. If there is none, it means the
                    // element is not created by us.
                    var elem = ElementIDLifecycleManager <int> .GetInstance().GetFirstWrapper(valueId) as Element;

                    result = ElementSelector.ByElementId(valueId, elem == null ? true : elem.IsRevitOwned);
                }
                else
                {
                    int paramId = param.Id.IntegerValue;
                    if (paramId == (int)BuiltInParameter.ELEM_CATEGORY_PARAM || paramId == (int)BuiltInParameter.ELEM_CATEGORY_PARAM_MT)
                    {
                        var categories = DocumentManager.Instance.CurrentDBDocument.Settings.Categories;
                        result = new Category(categories.get_Item((BuiltInCategory)valueId));
                    }
                    else
                    {
                        // For other cases, return a localized string
                        result = param.AsValueString();
                    }
                }
                break;

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

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

            case StorageType.Double:
                result = param.AsDouble() * Revit.GeometryConversion.UnitConverter.HostToDynamoFactor(param.Definition.UnitType);
                break;

            default:
                throw new Exception(string.Format(Properties.Resources.ParameterWithoutStorageType, param));
            }

            return(result);
        }
Exemple #6
0
        public Autodesk.Revit.DB.Line drivingLine(Element wall)
        {
            LocationCurve lc = wall.Location as LocationCurve; Curve c = lc.Curve;

            Autodesk.Revit.DB.Parameter boP = wall.LookupParameter("Base Offset");
            c = GeomUtil.OffsetCurve(c, XYZ.BasisZ, boP.AsDouble());
            List <XYZ> ps = new List <XYZ> {
                c.GetEndPoint(0), c.GetEndPoint(1)
            };

            ps.Sort(new ZYXComparer());
            return(Autodesk.Revit.DB.Line.CreateBound(ps[0], ps[1]));
        }
Exemple #7
0
 public bool IsDouble(out double?value, bool converted = true)
 {
     value = null;
     if (parameter.StorageType == Rvt.StorageType.Double)
     {
         var doubleValue = parameter.AsDouble();
         if (converted)
         {
             var dut = parameter.DisplayUnitType;
             doubleValue = ConvertHelper.ConvertFrom(doubleValue, dut);
         }
         value = doubleValue;
     }
     return(value != null);
 }
Exemple #8
0
        /// <summary>
        /// Get Project Rotation
        /// </summary>
        /// <returns>Rotation in degrees</returns>
        public static double ProjectRotation()
        {
            // Get project base point
            RVT.Document doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.FilteredElementCollector collector = new RVT.FilteredElementCollector(doc).OfCategory(RVT.BuiltInCategory.OST_ProjectBasePoint);
            RVT.BasePoint element = (RVT.BasePoint)collector.ToElements().FirstOrDefault();

            if (element == null)
            {
                throw new Exception(Properties.Resources.CannotGetBaseOrSurveyPoint);
            }

            // Return the rotation parameter as double
            RVT.Parameter param = element.get_Parameter(RVT.BuiltInParameter.BASEPOINT_ANGLETON_PARAM);
            return(param.AsDouble().ToDegrees());
        }
Exemple #9
0
        //----------------------------------------------------------
        public static void GetParameterValue(Parameter para, Parameter para_change)
        {
            try
            {
                if (para != null)
                {
                    if (para.Definition.Name == para_change.Definition.Name && para.IsReadOnly == false)
                    {
                        // Use different method to get parameter data according to the storage type
                        switch (para.StorageType)
                        {
                        case StorageType.Double:
                            //covert the number into Metric
                            para.Set(para_change.AsDouble());
                            break;

                        case StorageType.ElementId:
                            //find out the name of the element
                            para.Set(para_change.AsElementId());
                            break;

                        case StorageType.Integer:
                            para.Set(para_change.AsInteger());
                            break;

                        case StorageType.String:
                            para.Set(para_change.AsString());
                            break;

                        default:
                            //defValue = "Unexposed parameter.";
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #10
0
        public ParameterJSON(RevitParam param,
                             [DefaultArgument("Synthetic.Revit.Document.Current()")] revitDoc Document)
        {
            this.Name        = param.Definition.Name;
            this.StorageType = param.StorageType.ToString();
            switch (this.StorageType)
            {
            case "Double":
                this.Value = param.AsDouble().ToString();
                break;

            case "ElementId":
                ElementIdJSON id = new ElementIdJSON(param.AsElementId(), Document);
                this.Value = ElementIdJSON.ToJSON(id);
                break;

            case "Integer":
                this.Value = param.AsInteger().ToString();
                break;

            case "String":
            default:
                this.Value = param.AsString();
                break;
            }

            this.Id = param.Id.IntegerValue;

            if (IsShared)
            {
                this.GUID = param.GUID.ToString();
            }
            else
            {
                this.GUID = "";
            }

            this.IsShared   = param.IsShared;
            this.IsReadOnly = param.IsReadOnly;
        }
Exemple #11
0
 ParamValueToStr(Revit.Parameter param)
 {
     if (param.StorageType == Revit.StorageType.Double)
     {
         return(param.AsDouble().ToString());
     }
     else if (param.StorageType == Revit.StorageType.ElementId)
     {
         return(param.AsElementId().ToString());
     }
     else if (param.StorageType == Revit.StorageType.Integer)
     {
         return(param.AsInteger().ToString());
     }
     else if (param.StorageType == Revit.StorageType.String)
     {
         return(param.AsString());
     }
     else
     {
         Debug.Assert(false);
         return(string.Empty);
     }
 }
        public SerialParameter(RevitParam parameter,
                               [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc Document)
        {
            this.Name        = parameter.Definition.Name;
            this.StorageType = parameter.StorageType.ToString();
            switch (this.StorageType)
            {
            case "Double":
                this.Value = parameter.AsDouble().ToString();
                break;

            case "ElementId":
                this.ValueElemId = new SerialElementId(parameter.AsElementId(), Document);
                //this.Value = param.AsElementId().ToString();
                break;

            case "Integer":
                this.Value = parameter.AsInteger().ToString();
                break;

            case "String":
            default:
                this.Value = parameter.AsString();
                break;
            }

            this.Id = parameter.Id.IntegerValue;

            if (IsShared)
            {
                this.GUID = parameter.GUID.ToString();
            }

            this.IsShared   = parameter.IsShared;
            this.IsReadOnly = parameter.IsReadOnly;
        }
 internal static double AsDoubleInRhinoUnits(this DB.Parameter parameter)
 {
     return(UnitConverter.InRhinoUnits(parameter.AsDouble(), parameter.Definition.ParameterType));
 }
        public void GetBarNumber(FamilyInstance rebarInstance, out string imperial, out string metric)
        {
            imperial = "";
            metric   = "";
            Autodesk.Revit.DB.Parameter parameter = rebarInstance.Symbol.LookupParameter("BAR_DIAMETER");
            bool flag = parameter == null || parameter.StorageType != StorageType.Double;

            if (!flag)
            {
                double num = parameter.AsDouble();
                this.GetBarNumber(num, out imperial, out metric);
                bool flag2 = MathLib.IsEqual(num, 0.03125, 0.0001);
                if (flag2)
                {
                    imperial = "3";
                    metric   = "10";
                }
                else
                {
                    bool flag3 = MathLib.IsEqual(num, 0.04167, 0.001);
                    if (flag3)
                    {
                        imperial = "4";
                        metric   = "13";
                    }
                    else
                    {
                        bool flag4 = MathLib.IsEqual(num, 0.05208, 0.001);
                        if (flag4)
                        {
                            imperial = "5";
                            metric   = "16";
                        }
                        else
                        {
                            bool flag5 = MathLib.IsEqual(num, 0.0625, 0.001);
                            if (flag5)
                            {
                                imperial = "6";
                                metric   = "19";
                            }
                            else
                            {
                                bool flag6 = MathLib.IsEqual(num, 0.07292, 0.001);
                                if (flag6)
                                {
                                    imperial = "7";
                                    metric   = "22";
                                }
                                else
                                {
                                    bool flag7 = MathLib.IsEqual(num, 0.08333, 0.001);
                                    if (flag7)
                                    {
                                        imperial = "8";
                                        metric   = "25";
                                    }
                                    else
                                    {
                                        bool flag8 = MathLib.IsEqual(num, 0.09408, 0.001);
                                        if (flag8)
                                        {
                                            imperial = "9";
                                            metric   = "29";
                                        }
                                        else
                                        {
                                            bool flag9 = MathLib.IsEqual(num, 0.10579, 0.001);
                                            if (flag9)
                                            {
                                                imperial = "10";
                                                metric   = "32";
                                            }
                                            else
                                            {
                                                bool flag10 = MathLib.IsEqual(num, 0.11751, 0.001);
                                                if (flag10)
                                                {
                                                    imperial = "11";
                                                    metric   = "36";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public CEGRebarInfo(FamilyInstance familyInstance)
        {
            string imperialSize;
            string metricSize;

            GetBarNumber(familyInstance, out imperialSize, out metricSize);
            this.UnistImperial = imperialSize;
            this.UnistMetric   = UnistMetric;
            Autodesk.Revit.DB.Parameter parameter = familyInstance.LookupParameter("BAR_PREFIX");
            bool flag = parameter != null && parameter.StorageType == StorageType.String;

            if (flag)
            {
                this.BarPrefix = parameter.AsString();
            }
            Autodesk.Revit.DB.Parameter parameter2 = familyInstance.LookupParameter("CONTROL_MARK");
            bool flag2 = parameter2 != null && parameter2.StorageType == StorageType.String;

            if (flag2)
            {
                this.ControlMark = parameter2.AsString();
            }
            Autodesk.Revit.DB.Parameter parameter3 = familyInstance.Symbol.LookupParameter("BAR_SHAPE");
            bool flag3 = parameter3 != null && parameter3.StorageType == StorageType.String;

            if (flag3)
            {
                this.BarShape = parameter3.AsString();
            }
            Autodesk.Revit.DB.Parameter parameter4 = familyInstance.LookupParameter("DIM_LENGTH");
            bool flag4 = parameter4 != null && parameter4.StorageType == StorageType.Double;

            if (flag4)
            {
                this.DimLength = ConVertDoubleToImperial(parameter4.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter5 = familyInstance.LookupParameter("BAR_LENGTH_A");
            bool flag5 = parameter5 != null && parameter5.StorageType == StorageType.Double;

            if (flag5)
            {
                this.BarLengthA = ConVertDoubleToImperial(parameter5.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter6 = familyInstance.LookupParameter("BAR_LENGTH_B");
            bool flag6 = parameter6 != null && parameter6.StorageType == StorageType.Double;

            if (flag6)
            {
                this.BarLengthB = ConVertDoubleToImperial(parameter6.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter7 = familyInstance.LookupParameter("BAR_LENGTH_C");
            bool flag7 = parameter7 != null && parameter7.StorageType == StorageType.Double;

            if (flag7)
            {
                this.BarLengthC = ConVertDoubleToImperial(parameter7.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter8 = familyInstance.LookupParameter("BAR_LENGTH_D");
            bool flag8 = parameter8 != null && parameter8.StorageType == StorageType.Double;

            if (flag8)
            {
                this.BarLengthD = ConVertDoubleToImperial(parameter8.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter9 = familyInstance.LookupParameter("BAR_LENGTH_E");
            bool flag9 = parameter9 != null && parameter9.StorageType == StorageType.Double;

            if (flag9)
            {
                this.BarLengthE = ConVertDoubleToImperial(parameter9.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter10 = familyInstance.LookupParameter("BAR_LENGTH_F");
            bool flag10 = parameter10 != null && parameter10.StorageType == StorageType.Double;

            if (flag10)
            {
                this.BarLengthF = ConVertDoubleToImperial(parameter10.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter11 = familyInstance.LookupParameter("BAR_LENGTH_G");
            bool flag11 = parameter11 != null && parameter11.StorageType == StorageType.Double;

            if (flag11)
            {
                this.BarLengthG = ConVertDoubleToImperial(parameter11.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter12 = familyInstance.LookupParameter("BAR_LENGTH_H");
            bool flag12 = parameter12 != null && parameter12.StorageType == StorageType.Double;

            if (flag12)
            {
                this.BarLengthH = ConVertDoubleToImperial(parameter12.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter13 = familyInstance.LookupParameter("BAR_LENGTH_K");
            bool flag13 = parameter13 != null && parameter13.StorageType == StorageType.Double;

            if (flag13)
            {
                this.BarLengthK = ConVertDoubleToImperial(parameter13.AsDouble());
            }
            Autodesk.Revit.DB.Parameter parameter14 = familyInstance.LookupParameter("TypeNote");
            bool flag14 = parameter14 != null && parameter14.StorageType == StorageType.String;

            if (flag14)
            {
                this.TypeNote = parameter14.AsString();
            }
            Autodesk.Revit.DB.Parameter parameter15 = familyInstance.LookupParameter("BenDia");
            bool flag15 = parameter15 != null && parameter15.StorageType == StorageType.Double;

            if (flag15)
            {
                this.BenDia = ConVertDouble(parameter15.AsDouble());
            }
        }