//Get the parameter value as Double
        private static double GetParameterValue(FamilyType ft, FamilyParameter fp)
        {
            double value = 0.0;

            switch (fp.StorageType)
            {
            case (StorageType.Double):
                value = Convert.ToDouble(ft.AsDouble(fp));
                break;

            case (StorageType.Integer):
                value = Convert.ToDouble(ft.AsInteger(fp));
                break;

            case (StorageType.String):
                value = 0.0;
                break;

            case (StorageType.ElementId):
                value = 0.0;
                break;

            default:
                break;
            }

            return(value);
        }
        static string FamilyParamValueString(
            FamilyType t,
            FamilyParameter fp,
            Document doc)
        {
            string value = t.AsValueString(fp);

            switch (fp.StorageType)
            {
            case StorageType.Double:
                value = Util.RealString(
                    (double)t.AsDouble(fp))
                        + " (double)";
                break;

            case StorageType.ElementId:
                ElementId id = t.AsElementId(fp);
                Element   e  = doc.GetElement(id);
                value = id.IntegerValue.ToString() + " ("
                        + Util.ElementDescription(e) + ")";
                break;

            case StorageType.Integer:
                value = t.AsInteger(fp).ToString()
                        + " (int)";
                break;

            case StorageType.String:
                value = "'" + t.AsString(fp)
                        + "' (string)";
                break;
            }
            return(value);
        }
Ejemplo n.º 3
0
        public static string FamilyParamValueString(FamilyType t, FamilyParameter fp, Document doc)
        {
            string value = t.AsValueString(fp);

            switch (fp.StorageType)
            {
            case StorageType.Double:
                value = t.AsValueString(fp);
                break;

            /* case StorageType.ElementId:
             *   ElementId id = t.AsElementId(fp);
             *   Element e = doc.GetElement(id);
             *   value = id.IntegerValue.ToString() + " (" + e.Name + ")";
             *   break;*/

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

            case StorageType.String:
                value = t.AsString(fp);
                break;
            }
            return(value);
        }
Ejemplo n.º 4
0
        public static string ParameterToString(Document doc, FamilyParameter param, FamilyType type)
        {
            if (!type.HasValue(param))
            {
                return("无");
            }
            if (param.Definition.ParameterType == ParameterType.Invalid)
            {
                return("不可用");
            }
            switch (param.StorageType)
            {
            case StorageType.Double:
#if R2014
                var uStr = FormatUtils.Format(doc, param.Definition.UnitType, type.AsDouble(param).Value);
#else
                var uStr = UnitFormatUtils.Format(doc.GetUnits(), param.Definition.UnitType, type.AsDouble(param).Value, false, false);
#endif
                return(uStr);

            //var uStr = string.Empty;
            //if (param.Definition.ParameterType == ParameterType.Length)
            //{
            //    uStr = GetParamaterUnit(param.DisplayUnitType);
            //}
            //var dStr = param.AsValueString();
            //if (!String.IsNullOrEmpty(uStr) && !dStr.EndsWith(uStr)) dStr += uStr;
            //return dStr;
            case StorageType.Integer:
                var v = type.AsInteger(param).Value;
                if (param.Definition.ParameterType == ParameterType.YesNo)
                {
                    if (v == 0)
                    {
                        return("否");
                    }
                    return("是");
                }
#if R2014
                return(FormatUtils.Format(doc, param.Definition.UnitType, v));
#else
                return(UnitFormatUtils.Format(doc.GetUnits(), param.Definition.UnitType, v, false, false));
#endif
            case StorageType.String:
                return(type.AsString(param));

            case StorageType.ElementId:
                ElementId idVal = type.AsElementId(param);
                return(AsElementName(doc, idVal));

            case StorageType.None:
            default:
                return("无");
            }
        }
Ejemplo n.º 5
0
        public static bool FamilyParamYesNoType(FamilyType t, FamilyParameter fp)
        {
            bool value;

            if (t.AsInteger(fp) == 0)
            {
                value = false;
            }
            else
            {
                value = true;
            }
            return(value);
        }
Ejemplo n.º 6
0
        public FamilyParameterValueWrapper(FamilyParameter parameter, FamilyType familyType, Document doc)
        {
            _parameter  = parameter;
            _familyType = familyType;
            _doc        = doc;

            // Значение параметра \"{parameter.Definition.Name}\"
            Title          = string.Format(Language.GetItem(ModPlusConnector.Instance.Name, "p4"), parameter.Definition.Name);
            ParameterName  = parameter.Definition.Name;
            FamilyTypeName = familyType.Name;
            switch (parameter.StorageType)
            {
            case StorageType.String:
                Source = familyType.AsString(parameter);
                break;

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

            case StorageType.Double:
                var d = familyType.AsDouble(parameter);
                if (d.HasValue)
                {
                    Source = UnitUtils.ConvertFromInternalUnits(
                        d.Value,
#if R2017 || R2018 || R2019 || R2020
                        parameter.DisplayUnitType)
#else
                        parameter.GetUnitTypeId())
#endif
                             .ToString(CultureInfo.InvariantCulture);
                }

                break;
            }

            Destination = string.Empty;
        }
Ejemplo n.º 7
0
        private static string GetParameterValue(this FamilyType t, FamilyParameter p)
        {
            string paramValue = null;

            switch (p.StorageType)
            {
            case StorageType.Integer:
                if (ParameterType.YesNo == p.Definition.ParameterType)
                {
                    if (t.AsInteger(p) == 1)
                    {
                        paramValue = "YES";
                    }
                    else
                    {
                        paramValue = "NO";
                    }
                }
                else
                {
                    paramValue = t.AsValueString(p);
                }
                break;

            case StorageType.Double:
                paramValue = t.AsValueString(p);
                break;

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

            default:
                paramValue = null;
                break;
            }
            return(paramValue);
        }
        static string FamilyParamValueString(
            FamilyType t,
            FamilyParameter fp,
            Document doc)
        {
            string value = t.AsValueString( fp );
              switch( fp.StorageType )
              {
            case StorageType.Double:
              value = Util.RealString(
            ( double ) t.AsDouble( fp ) )
            + " (double)";
              break;

            case StorageType.ElementId:
              ElementId id = t.AsElementId( fp );
              Element e = doc.GetElement( id );
              value = id.IntegerValue.ToString() + " ("
            + Util.ElementDescription( e ) + ")";
              break;

            case StorageType.Integer:
              value = t.AsInteger( fp ).ToString()
            + " (int)";
              break;

            case StorageType.String:
              value = "'" + t.AsString( fp )
            + "' (string)";
              break;
              }
              return value;
        }
        /// <summary>
        /// The method is used to collect template information, specifying the New Window Parameters
        /// </summary>
        private void CollectTemplateInfo()
        {
            List <Wall> walls = Utility.GetElements <Wall>(m_application, m_document);

            m_wallThickness = walls[0].Width;
            ParameterMap paraMap        = walls[0].ParametersMap;
            Parameter    wallheightPara = walls[0].get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);//paraMap.get_Item("Unconnected Height");

            if (wallheightPara != null)
            {
                m_wallHeight = wallheightPara.AsDouble();
            }

            LocationCurve location = walls[0].Location as LocationCurve;

            m_wallWidth = location.Curve.Length;

            m_windowInset = m_wallThickness / 10;
            FamilyType      type           = m_familyManager.CurrentType;
            FamilyParameter heightPara     = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT);
            FamilyParameter widthPara      = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH);
            FamilyParameter sillHeightPara = m_familyManager.get_Parameter("Default Sill Height");

            if (type.HasValue(heightPara))
            {
                switch (heightPara.StorageType)
                {
                case StorageType.Double:
                    m_height = type.AsDouble(heightPara).Value;
                    break;

                case StorageType.Integer:
                    m_height = type.AsInteger(heightPara).Value;
                    break;
                }
            }
            if (type.HasValue(widthPara))
            {
                switch (widthPara.StorageType)
                {
                case StorageType.Double:
                    m_width = type.AsDouble(widthPara).Value;
                    break;

                case StorageType.Integer:
                    m_width = type.AsDouble(widthPara).Value;
                    break;
                }
            }
            if (type.HasValue(sillHeightPara))
            {
                switch (sillHeightPara.StorageType)
                {
                case StorageType.Double:
                    m_sillHeight = type.AsDouble(sillHeightPara).Value;
                    break;

                case StorageType.Integer:
                    m_sillHeight = type.AsDouble(sillHeightPara).Value;
                    break;
                }
            }

            //set the height,width and sillheight parameter of the opening
            m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT),
                                m_height);
            m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH),
                                m_width);
            m_familyManager.Set(m_familyManager.get_Parameter("Default Sill Height"), m_sillHeight);

            //get materials

            FilteredElementCollector elementCollector = new FilteredElementCollector(m_document);

            elementCollector.WherePasses(new ElementClassFilter(typeof(Material)));
            IList <Element> materials = elementCollector.ToElements();

            foreach (Element materialElement in materials)
            {
                Material material = materialElement as Material;
                m_para.GlassMaterials.Add(material.Name);
                m_para.FrameMaterials.Add(material.Name);
            }

            //get categories
            Categories      categories = m_document.Settings.Categories;
            Category        category   = categories.get_Item(BuiltInCategory.OST_Windows);
            CategoryNameMap cnm        = category.SubCategories;

            m_frameCat = categories.get_Item(BuiltInCategory.OST_WindowsFrameMullionProjection);
            m_glassCat = categories.get_Item(BuiltInCategory.OST_WindowsGlassProjection);

            //get referenceplanes
            List <ReferencePlane> planes = Utility.GetElements <ReferencePlane>(m_application, m_document);

            foreach (ReferencePlane p in planes)
            {
                if (p.Name.Equals("Sash"))
                {
                    m_sashPlane = p;
                }
                if (p.Name.Equals("Exterior"))
                {
                    m_exteriorPlane = p;
                }
                if (p.Name.Equals("Center (Front/Back)"))
                {
                    m_centerPlane = p;
                }
                if (p.Name.Equals("Top") || p.Name.Equals("Head"))
                {
                    m_topPlane = p;
                }
                if (p.Name.Equals("Sill") || p.Name.Equals("Bottom"))
                {
                    m_sillPlane = p;
                }
            }
        }
        private void PopulateModel()
        {
            ValueParameters = new ObservableCollection <FamilyParameterModel>();
            ValueParameters.CollectionChanged += ValueParameters_CollectionChanged;
            BuiltInParameters = new ObservableCollection <FamilyParameterModel>();
            CheckParameters   = new ObservableCollection <FamilyParameterModel>();
            famParam          = new SortedList <string, FamilyParameter>();

            FamilyManager familyManager = doc.FamilyManager;
            FamilyType    familyType    = familyManager.CurrentType;


            if (familyType == null)
            {
                familyType = CreateDefaultFamilyType(familyManager);
            }

            Utils.Init(this.doc);
            double value = 0.0;

            foreach (FamilyParameter fp in familyManager.Parameters)
            {
                if (!famEdit(fp, familyType))
                {
                    continue;
                }
                else
                {
                    if (!famParam.ContainsKey(fp.Definition.Name))
                    {
                        famParam.Add(fp.Definition.Name, fp);
                    }
                }
            }

            List <ElementId> eId = new List <ElementId>();

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            List <Dimension>         dimList   = collector
                                                 .OfCategory(BuiltInCategory.OST_Dimensions)
                                                 .WhereElementIsNotElementType()
                                                 .Cast <Dimension>()
                                                 .ToList();

            List <FamilyParameter> paramUsed = new List <FamilyParameter>();

            foreach (Dimension dim in dimList)
            {
                try
                {
                    if (dim.FamilyLabel != null)
                    {
                        paramUsed.Add(dim.FamilyLabel);
                    }
                }
                catch (Exception)
                {
                }
            }

            foreach (FamilyParameter fp in famParam.Values)
            {
                bool associated = !fp.AssociatedParameters.IsEmpty || paramUsed.Any(x => x.Definition.Name.Equals(fp.Definition.Name));
                bool builtIn    = fp.Id.IntegerValue < 0;
                ///yes-no parameters
                if (fp.Definition.ParameterType.Equals(ParameterType.YesNo))
                {
                    if (fp.StorageType == StorageType.Integer)
                    {
                        value = Convert.ToDouble(familyType.AsInteger(fp));
                    }

                    //eId.Add(fp.Id);

                    FamilyParameterModel newItem = new FamilyParameterModel(); // collect data yes-no
                    newItem.Precision      = Properties.Settings.Default.Precision;
                    newItem.Name           = fp.Definition.Name;
                    newItem.Value          = value;
                    newItem.Type           = fp.Definition.ParameterType.ToString();
                    newItem.Associated     = associated;
                    newItem.BuiltIn        = fp.Id.IntegerValue < 0;
                    newItem.Shared         = fp.IsShared;
                    newItem.Visible        = associated ? true : Properties.Settings.Default.AssociatedVisibility;
                    newItem.TypeOrInstance = fp.IsInstance ? "Instance" : "Type";

                    CheckParameters.Add(newItem);

                    continue;
                }
                ///slider parameters
                if (fp.StorageType == StorageType.Double)
                {
                    value = Convert.ToDouble(familyType.AsDouble(fp));
                }
                else if (fp.StorageType == StorageType.Integer)
                {
                    value = Convert.ToDouble(familyType.AsInteger(fp));
                }
                eId.Add(fp.Id);

                if (!builtIn)
                {
                    FamilyParameterModel newItem = new FamilyParameterModel();  // collect data slider, value != 0
                    newItem.Precision      = Properties.Settings.Default.Precision;
                    newItem.Name           = fp.Definition.Name;
                    newItem.Value          = value;
                    newItem.Type           = fp.Definition.ParameterType.ToString();
                    newItem.Associated     = associated;
                    newItem.BuiltIn        = fp.Id.IntegerValue < 0;
                    newItem.Shared         = fp.IsShared;
                    newItem.Visible        = associated ? true : Properties.Settings.Default.AssociatedVisibility;
                    newItem.TypeOrInstance = fp.IsInstance ? "Instance" : "Type";

                    ValueParameters.Add(newItem);
                }
                else
                {
                    FamilyParameterModel newItem = new FamilyParameterModel(); // collect data slider, value == 0
                    newItem.Precision      = Properties.Settings.Default.Precision;
                    newItem.Name           = fp.Definition.Name;
                    newItem.Value          = value;
                    newItem.Type           = fp.Definition.ParameterType.ToString();
                    newItem.Associated     = associated;
                    newItem.BuiltIn        = fp.Id.IntegerValue < 0;
                    newItem.Shared         = fp.IsShared;
                    newItem.Visible        = associated ? true : Properties.Settings.Default.AssociatedVisibility;
                    newItem.TypeOrInstance = fp.IsInstance ? "Instance" : "Type";

                    BuiltInParameters.Add(newItem);
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Check parameter conditions
 /// </summary>
 /// <param name="fp"></param>
 /// <param name="ft"></param>
 /// <returns></returns>
 private Boolean famEdit(FamilyParameter fp, FamilyType ft)
 {
     //double valueDouble;
     //int valueInt;
     if (!fp.StorageType.ToString().Equals("Double") && !fp.StorageType.ToString().Equals("Integer"))
     {
         return false;
     }
     else if (fp.UserModifiable)
     {
         return false;
     }
     else if (fp.IsDeterminedByFormula || fp.Formula != null)
     {
         return false;
     }
     else if (!ft.HasValue(fp))
     {
         return false;
     }
     else if (ft.AsDouble(fp) == null && ft.AsInteger(fp) == null)
     {
         return false;
     }
     //else if (!double.TryParse(ft.AsDouble(fp).ToString(), out valueDouble) && !int.TryParse(ft.AsInteger(fp).ToString(), out valueInt))
     //{
     //    return false;
     //}
     else if (fp.IsReporting)
     {
         return false;
     }
     else if (fp.IsDeterminedByFormula)
     {
         return false;
     }
     return true;
 }
Ejemplo n.º 12
0
 public CFamilyParameter(FamilyParameter oParam, FamilyType oFamType)
 {
     //IL_0028: Unknown result type (might be due to invalid IL or missing references)
     //IL_0029: Unknown result type (might be due to invalid IL or missing references)
     //IL_0039: Unknown result type (might be due to invalid IL or missing references)
     //IL_003a: Unknown result type (might be due to invalid IL or missing references)
     //IL_003f: Unknown result type (might be due to invalid IL or missing references)
     //IL_0045: Unknown result type (might be due to invalid IL or missing references)
     //IL_0051: Unknown result type (might be due to invalid IL or missing references)
     //IL_0052: Unknown result type (might be due to invalid IL or missing references)
     //IL_0061: Unknown result type (might be due to invalid IL or missing references)
     //IL_0062: Unknown result type (might be due to invalid IL or missing references)
     //IL_006e: Unknown result type (might be due to invalid IL or missing references)
     //IL_0074: Invalid comparison between Unknown and I4
     //IL_0076: Unknown result type (might be due to invalid IL or missing references)
     //IL_0077: Unknown result type (might be due to invalid IL or missing references)
     //IL_007c: Unknown result type (might be due to invalid IL or missing references)
     //IL_0083: Invalid comparison between Unknown and I4
     //IL_0085: Unknown result type (might be due to invalid IL or missing references)
     //IL_0086: Unknown result type (might be due to invalid IL or missing references)
     //IL_00bc: Unknown result type (might be due to invalid IL or missing references)
     //IL_00c2: Invalid comparison between Unknown and I4
     //IL_00c5: Unknown result type (might be due to invalid IL or missing references)
     //IL_00c6: Unknown result type (might be due to invalid IL or missing references)
     //IL_00e1: Unknown result type (might be due to invalid IL or missing references)
     //IL_00e7: Invalid comparison between Unknown and I4
     //IL_00ea: Unknown result type (might be due to invalid IL or missing references)
     //IL_00eb: Unknown result type (might be due to invalid IL or missing references)
     //IL_010f: Unknown result type (might be due to invalid IL or missing references)
     //IL_0115: Invalid comparison between Unknown and I4
     //IL_0118: Unknown result type (might be due to invalid IL or missing references)
     //IL_0119: Unknown result type (might be due to invalid IL or missing references)
     this.Name             = oParam.get_Definition().get_Name();
     this.ParamStorageType = oParam.get_StorageType();
     this.TypeName         = oFamType.get_Name();
     this.ID = oParam.get_Id().get_IntegerValue();
     if (oFamType.HasValue(oParam))
     {
         if ((int)this.ParamStorageType == 1 && (int)oParam.get_Definition().get_ParameterType() == 10)
         {
             if (oFamType.AsInteger(oParam) == 1)
             {
                 this.Value = "Yes";
             }
             else
             {
                 this.Value = "No";
             }
         }
         else if ((int)this.ParamStorageType == 1)
         {
             this.Value = oFamType.AsInteger(oParam).ToString();
         }
         else if ((int)this.ParamStorageType == 2)
         {
             this.Value = Math.Round(oFamType.AsDouble(oParam).Value, 2).ToString();
         }
         else if ((int)this.ParamStorageType == 3)
         {
             this.Value = oFamType.AsString(oParam);
         }
     }
 }